pub const STORE_TABLE_NAME: &str = "yugendb_store";
pub const SCHEMA_VERSION: u32 = 1;
pub const MIGRATION_METADATA_TABLE_NAME: &str = "yugendb_migrations";
pub const VALUE_COLUMN_TYPE: &str = "BYTEA";
pub const CREATE_STORE_TABLE_SQL: &str = "CREATE TABLE IF NOT EXISTS yugendb_store (
namespace TEXT NOT NULL,
collection TEXT NOT NULL,
key TEXT NOT NULL,
value BYTEA NOT NULL,
codec TEXT NOT NULL,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
expires_at TEXT,
PRIMARY KEY (namespace, collection, key)
);";
pub const CREATE_PREFIX_INDEX_SQL: &str = "CREATE INDEX IF NOT EXISTS idx_yugendb_store_prefix ON yugendb_store(namespace, collection, key);";
pub const CREATE_EXPIRES_AT_INDEX_SQL: &str =
"CREATE INDEX IF NOT EXISTS idx_yugendb_store_expires_at ON yugendb_store(expires_at);";
pub const ALL_SCHEMA_STATEMENTS: [&str; 3] = [
CREATE_STORE_TABLE_SQL,
CREATE_PREFIX_INDEX_SQL,
CREATE_EXPIRES_AT_INDEX_SQL,
];
#[must_use]
pub const fn schema_statements() -> [&'static str; 3] {
ALL_SCHEMA_STATEMENTS
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PostgresDriverStorageSchema {
pub version: u32,
pub store_table_name: &'static str,
pub migration_metadata_table_name: &'static str,
pub value_column_type: &'static str,
}
impl PostgresDriverStorageSchema {
#[must_use]
pub const fn current() -> Self {
Self {
version: SCHEMA_VERSION,
store_table_name: STORE_TABLE_NAME,
migration_metadata_table_name: MIGRATION_METADATA_TABLE_NAME,
value_column_type: VALUE_COLUMN_TYPE,
}
}
}