Skip to main content

systemprompt_analytics/
extension.rs

1//! Registers analytics-owned engagement and reputation schemas, the report
2//! views over source tables, and migrations.
3//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7use systemprompt_extension::prelude::*;
8
9#[derive(Debug, Clone, Copy, Default)]
10pub struct AnalyticsExtension;
11
12impl Extension for AnalyticsExtension {
13    fn metadata(&self) -> ExtensionMetadata {
14        ExtensionMetadata {
15            id: "analytics",
16            name: "Analytics",
17            version: env!("CARGO_PKG_VERSION"),
18        }
19    }
20
21    fn schemas(&self) -> Vec<SchemaDefinition> {
22        vec![
23            SchemaDefinition::new(
24                "engagement_events",
25                include_str!("../schema/engagement_events.sql"),
26            )
27            .with_required_columns(vec![
28                "id".into(),
29                "session_id".into(),
30                "created_at".into(),
31            ]),
32            SchemaDefinition::new(
33                "fingerprint_reputation",
34                include_str!("../schema/fingerprint_reputation.sql"),
35            )
36            .with_required_columns(vec!["fingerprint_hash".into()]),
37            SchemaDefinition::sql_only(include_str!("../schema/report_views.sql")),
38        ]
39    }
40
41    fn dependencies(&self) -> Vec<&'static str> {
42        vec!["users"]
43    }
44
45    fn migrations(&self) -> Vec<Migration> {
46        extension_migrations!()
47    }
48}
49
50register_extension!(AnalyticsExtension);