7Runtime migration for the roadmap v0.3 registry extension.
11Apply and roll back the activated roadmap v0.3 SQL extension.
15- Load the canonical REGISTRY_SCHEMA_V0_3.sql file.
16- Create roadmap tables idempotently and set PRAGMA user_version to 3.
17- Drop roadmap tables during rollback for migration tests and recovery.
23 L2 - migration lifecycle
24 L3 - schema version decisions
25 L4 - table existence checks
29- The SQL file is the single source of truth for created objects.
30- The module does not import wall-clock APIs; callers provide timestamps.
34- sqlite3 (migration connection)
35- oc_diagnostics (_dbg structured logger)
37from __future__
import annotations
39from pathlib
import Path
42from oc_diagnostics
import _dbg
44_dbg(
"OC_CHAT.MAIN",
"module",
"loaded", 4)
46ROADMAP_SCHEMA_VERSION = 3
47ROADMAP_SCHEMA_DESCRIPTION =
"roadmap REGISTRY_SCHEMA_V0_3"
55 "roadmap_item_tracks",
56 "roadmap_item_dependencies",
57 "roadmap_item_events",
59 "roadmap_render_sections",
64 """Return the canonical v0.3 roadmap SQL extension path."""
67 Path(__file__).resolve().parents[2]
71 /
"REGISTRY_SCHEMA_V0_3.sql"
76 """Load the canonical v0.3 roadmap SQL extension."""
82 """Return SQLite's integer schema user version."""
84 return int(conn.execute(
"PRAGMA user_version").fetchone()[0])
87def apply(conn: sqlite3.Connection) ->
None:
88 """Apply the roadmap v0.3 schema extension idempotently."""
96 """Drop roadmap v0.3 tables and reset SQLite user_version to 2."""
98 for name
in reversed(ROADMAP_TABLES):
99 conn.execute(f
"DROP TABLE IF EXISTS {name}")
101 conn.execute(
"DROP TRIGGER IF EXISTS roadmap_item_events_no_update")
102 conn.execute(
"DROP TRIGGER IF EXISTS roadmap_item_events_no_delete")
103 conn.execute(
"PRAGMA user_version = 2")
105 "DELETE FROM schema_migrations WHERE version = ?",
106 (ROADMAP_SCHEMA_VERSION,),
111 """Return True when all roadmap v0.3 tables exist."""
114 "SELECT name FROM sqlite_master WHERE type = 'table'"
116 existing = {str(row[0])
for row
in rows}
117 return set(ROADMAP_TABLES) <= existing
121 """Return roadmap v0.3 table names in dependency order."""
123 return ROADMAP_TABLES
None apply(sqlite3.Connection conn)
None rollback(sqlite3.Connection conn)
int current_user_version(sqlite3.Connection conn)
bool tables_exist(sqlite3.Connection conn)
tuple[str,...] table_names()