(connection: sqlite3.Connection)
| 414 | |
| 415 | |
| 416 | def apply_migrations(connection: sqlite3.Connection) -> None: |
| 417 | connection.commit() |
| 418 | connection.execute("BEGIN IMMEDIATE") |
| 419 | try: |
| 420 | connection.execute( |
| 421 | """ |
| 422 | CREATE TABLE IF NOT EXISTS schema_migrations ( |
| 423 | version INTEGER PRIMARY KEY, |
| 424 | name TEXT NOT NULL, |
| 425 | applied_at TEXT NOT NULL |
| 426 | ) |
| 427 | """ |
| 428 | ) |
| 429 | normalize_pre_release_migrations(connection) |
| 430 | applied = { |
| 431 | row["version"] for row in connection.execute("SELECT version FROM schema_migrations") |
| 432 | } |
| 433 | for version, name, sql in MIGRATIONS: |
| 434 | if version in applied: |
| 435 | continue |
| 436 | for statement in sql_statements(sql): |
| 437 | connection.execute(statement) |
| 438 | connection.execute( |
| 439 | "INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)", |
| 440 | (version, name, now()), |
| 441 | ) |
| 442 | connection.commit() |
| 443 | except BaseException: |
| 444 | connection.rollback() |
| 445 | raise |
| 446 | |
| 447 | |
| 448 | def normalize_pre_release_migrations(connection: sqlite3.Connection) -> None: |
no test coverage detected