MCPcopy
hub / github.com/tirth8205/code-review-graph / run_migrations

Function run_migrations

code_review_graph/migrations.py:259–284  ·  view source on GitHub ↗

Run all pending migrations in order. Each migration runs in its own transaction. The schema_version metadata entry is updated after each successful migration.

(conn: sqlite3.Connection)

Source from the content-addressed store, hash-verified

257
258
259def run_migrations(conn: sqlite3.Connection) -> None:
260 """Run all pending migrations in order.
261
262 Each migration runs in its own transaction. The schema_version metadata
263 entry is updated after each successful migration.
264 """
265 current = get_schema_version(conn)
266 if current >= LATEST_VERSION:
267 return
268
269 logger.info("Schema version %d -> %d: running migrations", current, LATEST_VERSION)
270
271 for version in sorted(MIGRATIONS.keys()):
272 if version <= current:
273 continue
274 logger.info("Running migration v%d", version)
275 try:
276 MIGRATIONS[version](conn)
277 _set_schema_version(conn, version)
278 conn.commit()
279 except sqlite3.Error:
280 conn.rollback()
281 logger.error("Migration v%d failed, rolling back", version, exc_info=True)
282 raise
283
284 logger.info("Migrations complete, now at schema version %d", LATEST_VERSION)

Callers 2

__init__Method · 0.85

Calls 4

get_schema_versionFunction · 0.85
_set_schema_versionFunction · 0.85
commitMethod · 0.80
rollbackMethod · 0.80