migration
This commit is contained in:
1 parent
ff40c2da16
commit
aee70ffbd2
1 file changed
+5
-4
+5
-4
@@ -64,15 +64,16 @@ async def init_db(db_path: Path = DB_PATH) -> aiosqlite.Connection:
|
||||
# schema_version doesn't exist yet (fresh database)
|
||||
current_version = 0
|
||||
|
||||
# Apply schema - filter out v2 migration if already applied
|
||||
# Apply schema - filter out v2 migration if already applied or on fresh DB
|
||||
schema = SCHEMA_PATH.read_text()
|
||||
if current_version >= 2:
|
||||
if current_version >= 2 or current_version == 0:
|
||||
# Remove v2 migration ALTER TABLE statements (lines after v2 INSERT)
|
||||
# Split at the v2 migration header and keep only the first part
|
||||
# - Version >= 2: migration already applied
|
||||
# - Version == 0: fresh database, CREATE TABLE already has the columns
|
||||
migration_start = schema.find('-- ── Migration: v2')
|
||||
if migration_start > 0:
|
||||
schema = schema[:migration_start]
|
||||
schema += "\n-- v2 migration already applied, skipping ALTER TABLE statements\n"
|
||||
schema += "\n-- v2 migration not needed, skipping ALTER TABLE statements\n"
|
||||
|
||||
await db.executescript(schema)
|
||||
await db.commit()
|
||||
|
||||
Reference in new issue
Block a user