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(
32                "extension_migration_compat",
33                include_str!("../schema/extension_migration_compat.sql"),
34            ),
35            SchemaDefinition::new("services", include_str!("../schema/services.sql"))
36                .with_required_columns(vec!["name".into(), "module_name".into(), "status".into()]),
37            SchemaDefinition::new(
38                "projection_backlog",
39                include_str!("../schema/projection_backlog.sql"),
40            )
41            .with_required_columns(vec![
42                "projection".into(),
43                "key".into(),
44                "attempts".into(),
45            ]),
46            SchemaDefinition::new("trace_facts", include_str!("../schema/trace_facts.sql"))
47                .with_required_columns(vec!["trace_id".into(), "first_at".into(), "status".into()]),
48            SchemaDefinition::sql_only(include_str!("../schema/functions.sql")),
49        ]
50    }
51
52    fn migrations(&self) -> Vec<Migration> {
53        extension_migrations!()
54    }
55
56    fn dependencies(&self) -> Vec<&'static str> {
57        vec![]
58    }
59
60    fn priority(&self) -> u32 {
61        0
62    }
63}
64
65register_extension!(DatabaseExtension);