1pub const SCHEMA_VERSION: u32 = 1;
14
15pub const STORE_TABLE_NAME: &str = "yugendb_store";
17
18pub const MIGRATION_METADATA_TABLE_NAME: &str = "yugendb_schema_migrations";
20
21pub const CREATE_STORE_TABLE_SQL: &str = r#"CREATE TABLE IF NOT EXISTS yugendb_store (
23 namespace TEXT NOT NULL,
24 collection TEXT NOT NULL,
25 key TEXT NOT NULL,
26 value BLOB NOT NULL,
27 codec TEXT NOT NULL,
28 created_at TEXT NOT NULL,
29 updated_at TEXT NOT NULL,
30 expires_at TEXT,
31 PRIMARY KEY (namespace, collection, key)
32);"#;
33
34pub const CREATE_PREFIX_INDEX_SQL: &str = r#"CREATE INDEX IF NOT EXISTS idx_yugendb_store_prefix
36ON yugendb_store(namespace, collection, key);"#;
37
38pub const CREATE_EXPIRES_AT_INDEX_SQL: &str = r#"CREATE INDEX IF NOT EXISTS idx_yugendb_store_expires_at
40ON yugendb_store(expires_at);"#;
41
42pub const CREATE_MIGRATION_METADATA_TABLE_SQL: &str = r#"CREATE TABLE IF NOT EXISTS yugendb_schema_migrations (
44 version INTEGER PRIMARY KEY,
45 applied_at TEXT NOT NULL
46);"#;
47
48pub const ALL_SCHEMA_STATEMENTS: [&str; 4] = [
50 CREATE_STORE_TABLE_SQL,
51 CREATE_PREFIX_INDEX_SQL,
52 CREATE_EXPIRES_AT_INDEX_SQL,
53 CREATE_MIGRATION_METADATA_TABLE_SQL,
54];
55
56#[must_use]
58pub const fn schema_statements() -> &'static [&'static str] {
59 &ALL_SCHEMA_STATEMENTS
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub struct SqliteStorageSchema {
65 pub version: u32,
67 pub store_table_name: &'static str,
69 pub migration_metadata_table_name: &'static str,
71 pub statements: &'static [&'static str],
73}
74
75impl SqliteStorageSchema {
76 #[must_use]
78 pub const fn current() -> Self {
79 Self {
80 version: SCHEMA_VERSION,
81 store_table_name: STORE_TABLE_NAME,
82 migration_metadata_table_name: MIGRATION_METADATA_TABLE_NAME,
83 statements: schema_statements(),
84 }
85 }
86}