agentmux_srv_core/migrations/
m0049_drone_versions.rs1use rusqlite::Connection;
17
18use super::{Migration, MigrationContext, MigrationError, MigrationScope};
19
20pub struct M0049DroneVersions;
21
22const CREATE: &str = "\
24CREATE TABLE IF NOT EXISTS db_drone_versions (
25 drone_id TEXT NOT NULL,
26 version INTEGER NOT NULL,
27 graph TEXT NOT NULL,
28 hash TEXT NOT NULL,
29 saved_at INTEGER NOT NULL,
30 saved_by TEXT NOT NULL,
31 PRIMARY KEY (drone_id, version)
32);";
33
34fn create(conn: &Connection) -> Result<(), String> {
35 conn.execute_batch(CREATE).map_err(|e| format!("db_drone_versions: {e}"))
36}
37
38impl Migration for M0049DroneVersions {
39 fn id(&self) -> &'static str {
40 "0049_drone_versions"
41 }
42
43 fn scope(&self) -> MigrationScope {
44 MigrationScope::Channel
45 }
46
47 fn description(&self) -> &'static str {
48 "Create db_drone_versions (a numbered graph per drone, no definition FK)"
49 }
50
51 fn up(&self, ctx: &MigrationContext) -> Result<(), MigrationError> {
52 if ctx.shared_store_path.exists() {
53 let conn = Connection::open(&ctx.shared_store_path)
54 .map_err(|e| MigrationError(format!("drone_versions: open shared store: {e}")))?;
55 create(&conn).map_err(MigrationError)?;
56 }
57 if ctx.channel_store_path.exists() {
58 let conn = Connection::open(&ctx.channel_store_path)
59 .map_err(|e| MigrationError(format!("drone_versions: open channel store: {e}")))?;
60 create(&conn).map_err(MigrationError)?;
61 }
62 Ok(())
63 }
64}
65
66#[cfg(test)]
67#[path = "m0049_drone_versions_tests.rs"]
68mod tests;