Skip to main content

systemprompt_database/
extension.rs

1//! Extension registration for the database crate's own schema.
2//!
3//! Every systemprompt extension that owns DDL registers itself through the
4//! `inventory` framework. The database crate registers its own bookkeeping
5//! tables (`extension_migrations`) and shared SQL helper functions so that
6//! they install before any downstream extension runs.
7//!
8//! Copyright (c) systemprompt.io — Business Source License 1.1.
9//! See <https://systemprompt.io> for licensing details.
10
11use systemprompt_extension::prelude::*;
12
13#[derive(Debug, Clone, Copy, Default)]
14pub struct DatabaseExtension;
15
16impl Extension for DatabaseExtension {
17    fn metadata(&self) -> ExtensionMetadata {
18        ExtensionMetadata {
19            id: "database",
20            name: "Database",
21            version: env!("CARGO_PKG_VERSION"),
22        }
23    }
24
25    fn schemas(&self) -> Vec<SchemaDefinition> {
26        vec![
27            SchemaDefinition::new(
28                "extension_migrations",
29                include_str!("../schema/extension_migrations.sql"),
30            ),
31            SchemaDefinition::new("services", include_str!("../schema/services.sql"))
32                .with_required_columns(vec!["name".into(), "module_name".into(), "status".into()]),
33            SchemaDefinition::new(
34                "projection_backlog",
35                include_str!("../schema/projection_backlog.sql"),
36            )
37            .with_required_columns(vec![
38                "projection".into(),
39                "key".into(),
40                "attempts".into(),
41            ]),
42            SchemaDefinition::new("trace_facts", include_str!("../schema/trace_facts.sql"))
43                .with_required_columns(vec!["trace_id".into(), "first_at".into(), "status".into()]),
44            SchemaDefinition::sql_only(include_str!("../schema/functions.sql")),
45        ]
46    }
47
48    fn migrations(&self) -> Vec<Migration> {
49        extension_migrations!()
50    }
51
52    fn dependencies(&self) -> Vec<&'static str> {
53        vec![]
54    }
55
56    fn priority(&self) -> u32 {
57        0
58    }
59}
60
61register_extension!(DatabaseExtension);