Skip to content

Commit 6406ce4

Browse files
authored
Merge pull request #5608 from freedomofpress/alembic_migration_fix_due_to_sqlite_upgrade
Fixes #5605 alembic migration errors on Focal
2 parents 59917d1 + ba68bfb commit 6406ce4

7 files changed

+14
-10
lines changed

securedrop/alembic/versions/2d0ce3ee5bdc_added_passphrase_hash_column_to_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def upgrade():
2323
def downgrade():
2424
# sqlite has no `drop column` command, so we recreate the original table
2525
# then load it from a temp table
26-
26+
conn = op.get_bind()
27+
conn.execute("PRAGMA legacy_alter_table=ON")
2728
op.rename_table("journalists", "journalists_tmp")
2829

2930
op.create_table(
@@ -43,7 +44,6 @@ def downgrade():
4344
sa.UniqueConstraint("username"),
4445
)
4546

46-
conn = op.get_bind()
4747
conn.execute(
4848
"""
4949
INSERT INTO journalists

securedrop/alembic/versions/3d91d6948753_create_source_uuid_column.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919

2020
def upgrade():
21+
conn = op.get_bind()
22+
conn.execute("PRAGMA legacy_alter_table=ON")
2123
# Schema migration
2224
op.rename_table("sources", "sources_tmp")
2325

2426
# Add UUID column.
2527
op.add_column("sources_tmp", sa.Column("uuid", sa.String(length=36)))
2628

2729
# Add UUIDs to sources_tmp table.
28-
conn = op.get_bind()
2930
sources = conn.execute(sa.text("SELECT * FROM sources_tmp")).fetchall()
3031

3132
for source in sources:

securedrop/alembic/versions/60f41bb14d98_add_session_nonce_to_journalist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818

1919
def upgrade():
20+
conn = op.get_bind()
21+
conn.execute("PRAGMA legacy_alter_table=ON")
2022
# Save existing journalist table.
2123
op.rename_table('journalists', 'journalists_tmp')
2224

2325
# Add nonce column.
2426
op.add_column('journalists_tmp', sa.Column('session_nonce', sa.Integer()))
2527

2628
# Populate nonce column.
27-
conn = op.get_bind()
2829
journalists = conn.execute(
2930
sa.text("SELECT * FROM journalists_tmp")).fetchall()
3031

@@ -57,7 +58,6 @@ def upgrade():
5758
sa.UniqueConstraint('uuid')
5859
)
5960

60-
conn = op.get_bind()
6161
conn.execute('''
6262
INSERT INTO journalists
6363
SELECT id, uuid, username, first_name, last_name, pw_salt, pw_hash,

securedrop/alembic/versions/6db892e17271_add_reply_uuid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919

2020
def upgrade():
21+
conn = op.get_bind()
22+
conn.execute("PRAGMA legacy_alter_table=ON")
2123
# Schema migration
2224
op.rename_table("replies", "replies_tmp")
2325

2426
# Add new column.
2527
op.add_column("replies_tmp", sa.Column("uuid", sa.String(length=36)))
2628

2729
# Populate new column in replies_tmp table.
28-
conn = op.get_bind()
2930
replies = conn.execute(sa.text("SELECT * FROM replies_tmp")).fetchall()
3031

3132
for reply in replies:

securedrop/alembic/versions/e0a525cbab83_add_column_to_track_source_deletion_of_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818

1919
def upgrade():
20+
conn = op.get_bind()
21+
conn.execute("PRAGMA legacy_alter_table=ON")
2022
# Schema migration
2123
op.rename_table("replies", "replies_tmp")
2224

2325
# Add new column.
2426
op.add_column("replies_tmp", sa.Column("deleted_by_source", sa.Boolean()))
2527

2628
# Populate deleted_by_source column in replies_tmp table.
27-
conn = op.get_bind()
2829
replies = conn.execute(sa.text("SELECT * FROM replies_tmp")).fetchall()
2930

3031
for reply in replies:

securedrop/alembic/versions/f2833ac34bb6_add_uuid_column_for_users_table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919

2020
def upgrade():
21+
conn = op.get_bind()
22+
conn.execute("PRAGMA legacy_alter_table=ON")
2123
# Save existing journalist table.
2224
op.rename_table("journalists", "journalists_tmp")
2325

2426
# Add UUID column.
2527
op.add_column("journalists_tmp", sa.Column("uuid", sa.String(length=36)))
2628

2729
# Add UUIDs to journalists_tmp table.
28-
conn = op.get_bind()
2930
journalists = conn.execute(sa.text("SELECT * FROM journalists_tmp")).fetchall()
3031

3132
for journalist in journalists:
@@ -57,7 +58,6 @@ def upgrade():
5758
sa.UniqueConstraint("uuid"),
5859
)
5960

60-
conn = op.get_bind()
6161
conn.execute(
6262
"""
6363
INSERT INTO journalists

securedrop/alembic/versions/fccf57ceef02_create_submission_uuid_column.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919

2020
def upgrade():
21+
conn = op.get_bind()
22+
conn.execute("PRAGMA legacy_alter_table=ON")
2123
# Schema migration
2224
op.rename_table("submissions", "submissions_tmp")
2325

2426
# Add UUID column.
2527
op.add_column("submissions_tmp", sa.Column("uuid", sa.String(length=36)))
2628

2729
# Add UUIDs to submissions_tmp table.
28-
conn = op.get_bind()
2930
submissions = conn.execute(sa.text("SELECT * FROM submissions_tmp")).fetchall()
3031

3132
for submission in submissions:

0 commit comments

Comments
 (0)