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                "schema_install_fingerprint",
33                include_str!("../schema/schema_install_fingerprint.sql"),
34            )
35            .with_required_columns(vec!["singleton".into(), "fingerprint".into()]),
36            SchemaDefinition::new(
37                "extension_migration_compat",
38                include_str!("../schema/extension_migration_compat.sql"),
39            ),
40            SchemaDefinition::new("services", include_str!("../schema/services.sql"))
41                .with_required_columns(vec!["name".into(), "module_name".into(), "status".into()]),
42            SchemaDefinition::new(
43                "projection_backlog",
44                include_str!("../schema/projection_backlog.sql"),
45            )
46            .with_required_columns(vec![
47                "projection".into(),
48                "key".into(),
49                "attempts".into(),
50            ]),
51            SchemaDefinition::new("trace_facts", include_str!("../schema/trace_facts.sql"))
52                .with_required_columns(vec!["trace_id".into(), "first_at".into(), "status".into()]),
53            SchemaDefinition::new(
54                "instance_leases",
55                include_str!("../schema/instance_leases.sql"),
56            )
57            .with_required_columns(vec![
58                "lease_key".into(),
59                "owner_instance_id".into(),
60                "expires_at".into(),
61            ]),
62            SchemaDefinition::new(
63                "instance_endpoints",
64                include_str!("../schema/instance_endpoints.sql"),
65            )
66            .with_required_columns(vec![
67                "instance_id".into(),
68                "advertise_url".into(),
69                "heartbeat_at".into(),
70            ]),
71            SchemaDefinition::new(
72                "instance_presence",
73                include_str!("../schema/instance_presence.sql"),
74            )
75            .with_required_columns(vec![
76                "instance_id".into(),
77                "role".into(),
78                "heartbeat_at".into(),
79            ]),
80            SchemaDefinition::new(
81                "release_stamps",
82                include_str!("../schema/release_stamps.sql"),
83            )
84            .with_required_columns(vec!["name".into(), "version".into()]),
85            SchemaDefinition::new(
86                "config_version",
87                include_str!("../schema/config_version.sql"),
88            )
89            .with_required_columns(vec!["id".into(), "version".into(), "plane".into()]),
90            SchemaDefinition::new(
91                "config_plane_applied",
92                include_str!("../schema/config_plane_applied.sql"),
93            )
94            .with_required_columns(vec!["plane".into(), "applied_at".into()]),
95            SchemaDefinition::sql_only(include_str!("../schema/functions.sql")),
96            SchemaDefinition::sql_only(include_str!("../schema/config_change_triggers.sql")),
97        ]
98    }
99
100    fn migrations(&self) -> Vec<Migration> {
101        extension_migrations!()
102    }
103
104    fn dependencies(&self) -> Vec<&'static str> {
105        vec![]
106    }
107
108    fn priority(&self) -> u32 {
109        0
110    }
111}
112
113register_extension!(DatabaseExtension);