use super::sql::{REGISTRY_TABLE, sql_control_store};
use crate::error::{KernelError, Result};
const MIGRATIONS: &[(i64, &str, &str)] = &[(
1,
"create kernel area settings and away cursor tables",
"\
CREATE TABLE IF NOT EXISTS adk_kernel_area_settings (\
partition_id TEXT PRIMARY KEY, \
record TEXT NOT NULL\
);\
CREATE TABLE IF NOT EXISTS adk_kernel_away_cursors (\
user_id TEXT NOT NULL, \
viewer TEXT NOT NULL, \
seq INTEGER NOT NULL, \
record TEXT NOT NULL, \
PRIMARY KEY (user_id, viewer)\
);",
)];
#[derive(Debug, Clone)]
pub struct SqliteControlStore {
pool: sqlx::SqlitePool,
}
impl SqliteControlStore {
pub fn new(pool: sqlx::SqlitePool) -> Self {
Self { pool }
}
pub fn pool(&self) -> &sqlx::SqlitePool {
&self.pool
}
pub async fn migrate(&self) -> Result<()> {
adk_session::migration::sqlite_runner::run_sql_migrations(
&self.pool,
REGISTRY_TABLE,
MIGRATIONS,
|| async { Ok(false) },
)
.await
.map_err(|error| KernelError::Store { backend: "sqlite", reason: error.message })
}
}
sql_control_store!(SqliteControlStore, "sqlite");