diff options
| author | Aurélien Bompard | 2015-09-14 10:16:05 +0200 |
|---|---|---|
| committer | Barry Warsaw | 2015-09-15 01:33:37 +0000 |
| commit | 2b09149598144e49cf06e6293b3b9de5364bba2a (patch) | |
| tree | 87eca958bfd91c78c6eb2a32a6af780812146c9f /src | |
| parent | d8e96d95e2f1c2d82fd43c04cbc31a8b558a01c6 (diff) | |
| download | mailman-2b09149598144e49cf06e6293b3b9de5364bba2a.tar.gz mailman-2b09149598144e49cf06e6293b3b9de5364bba2a.tar.zst mailman-2b09149598144e49cf06e6293b3b9de5364bba2a.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/database/alembic/versions/33e1f5f6fa8_.py | 36 | ||||
| -rw-r--r-- | src/mailman/database/tests/test_migrations.py | 7 |
2 files changed, 27 insertions, 16 deletions
diff --git a/src/mailman/database/alembic/versions/33e1f5f6fa8_.py b/src/mailman/database/alembic/versions/33e1f5f6fa8_.py index 0d6bddf37..3d1840005 100644 --- a/src/mailman/database/alembic/versions/33e1f5f6fa8_.py +++ b/src/mailman/database/alembic/versions/33e1f5f6fa8_.py @@ -41,21 +41,33 @@ revision = '33e1f5f6fa8' down_revision = '51b7f92bd06c' +COLUMNS_TO_CHANGE = ( + ('message', 'message_id_hash'), + ('message', 'path'), + ('pended', 'token'), + ('_request', 'data_hash'), + ('user', 'password'), + ) + + def upgrade(): - if not is_sqlite(op.get_bind()): + if is_sqlite(op.get_bind()): # SQLite does not support altering columns. - op.alter_column('message', 'message_id_hash', type_=sa.Unicode) - op.alter_column('message', 'path', type_=sa.Unicode) - op.alter_column('pended', 'token', type_=sa.Unicode) - op.alter_column('_request', 'data_hash', type_=sa.Unicode) - op.alter_column('user', 'password', type_=sa.Unicode) + return + for table, column in COLUMNS_TO_CHANGE: + op.alter_column(table, column, type_=sa.Unicode) def downgrade(): - if not is_sqlite(op.get_bind()): + if is_sqlite(op.get_bind()): # SQLite does not support altering columns. - op.alter_column('message', 'message_id_hash', type_=sa.LargeBinary) - op.alter_column('message', 'path', type_=sa.LargeBinary) - op.alter_column('pended', 'token', type_=sa.LargeBinary) - op.alter_column('_request', 'data_hash', type_=sa.LargeBinary) - op.alter_column('user', 'password', type_=sa.LargeBinary) + return + for table, column in COLUMNS_TO_CHANGE: + if op.get_bind().dialect.name == 'postgresql': + # PostgreSQL needs the USING clause that Alembic does not support + # yet. + op.execute(('ALTER TABLE "{table}" ALTER COLUMN "{column}" ' + 'TYPE BYTEA USING decode("{column}", \'UTF8\')').format( + table=table, column=column)) + else: + op.alter_column(table, column, type_=sa.LargeBinary) diff --git a/src/mailman/database/tests/test_migrations.py b/src/mailman/database/tests/test_migrations.py index e0a2c471d..8a57fde1a 100644 --- a/src/mailman/database/tests/test_migrations.py +++ b/src/mailman/database/tests/test_migrations.py @@ -42,10 +42,9 @@ class TestMigrations(unittest.TestCase): def tearDown(self): # Drop and restore a virgin database. - md = sa.MetaData() - md.reflect(bind=config.db.engine) - for table in md.sorted_tables: - table.drop(config.db.engine) + md = sa.MetaData(bind=config.db.engine) + md.reflect() + md.drop_all() Model.metadata.create_all(config.db.engine) def test_all_migrations(self): |
