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("functions", include_str!("../schema/functions.sql")),
32        ]
33    }
34
35    fn dependencies(&self) -> Vec<&'static str> {
36        vec![]
37    }
38
39    fn priority(&self) -> u32 {
40        // No extension declares `database` as a dependency, so install order is
41        // decided purely by priority among roots; 0 keeps the shared helper
42        // functions and `extension_migrations` ahead of every other extension.
43        0
44    }
45}
46
47register_extension!(DatabaseExtension);