from tortoise import connections async def migrate(): conn = connections.get("default") result = await conn.execute_query("PRAGMA table_info(filecodes)") columns = {row[1] for row in (result[1] if result and len(result) > 1 else [])} additions = [ ("is_trashed", "BOOLEAN NOT NULL DEFAULT 0"), ("trashed_at", "TIMESTAMP NULL"), ("trash_expires_at", "TIMESTAMP NULL"), ("trash_reason", "VARCHAR(32) NULL"), ("trash_original_path", "VARCHAR(1024) NULL"), ("trash_purged_at", "TIMESTAMP NULL"), ] for name, definition in additions: if name not in columns: await conn.execute_query(f"ALTER TABLE filecodes ADD COLUMN {name} {definition}") await conn.execute_script( """ CREATE INDEX IF NOT EXISTS idx_filecodes_is_trashed ON filecodes(is_trashed); CREATE INDEX IF NOT EXISTS idx_filecodes_trash_expires_at ON filecodes(trash_expires_at); """ )