fix: Hold the migration lock for the whole run (v2.8.1)

create_migrations_table() committed right after BEGIN IMMEDIATE, and
executescript() commits before running, so gunicorn workers applied
migrations concurrently; the v2.8.0 deploy failed to boot once with
'duplicate column name'. Run migration statements with conn.execute inside
the transaction and don't commit when creating the tracking table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-03 09:58:20 -07:00
1 parent 42c77e34b7
commit 8c51b52ed6
6 files changed
+172 -10

No files matched your search

+3 -2
View File
@@ -302,12 +302,13 @@ class TestErrorHandling:
def test_rollback_failure_causes_system_exit(self, temp_db):
"""Test that rollback failure raises SystemExit"""
with patch('sqlite3.connect') as mock_connect:
with patch('sqlite3.connect') as mock_connect, \
patch('starpunk.migrations.execute_in_transaction',
side_effect=Exception("Migration failed")):
mock_conn = MagicMock()
mock_connect.return_value = mock_conn
# Make both migration and rollback fail
mock_conn.executescript.side_effect = Exception("Migration failed")
mock_conn.rollback.side_effect = Exception("Rollback failed")
mock_conn.execute.return_value.fetchone.return_value = (0,)