diff options
| author | Aurélien Bompard | 2016-02-29 12:08:43 +0100 |
|---|---|---|
| committer | Barry Warsaw | 2016-02-29 21:52:13 -0500 |
| commit | 9684f1fc0e8bbe2c41566bf16dab92a0ff0f8b81 (patch) | |
| tree | 19ccd0ee3a5d7500a4ad97f792a040ece7ffc663 /src/mailman/database | |
| parent | ef9cdf45000b1172c3973b329ebe7ed32d604fb1 (diff) | |
| download | mailman-9684f1fc0e8bbe2c41566bf16dab92a0ff0f8b81.tar.gz mailman-9684f1fc0e8bbe2c41566bf16dab92a0ff0f8b81.tar.zst mailman-9684f1fc0e8bbe2c41566bf16dab92a0ff0f8b81.zip | |
Revert "Rename the HeaderMatch.chain column to action"
This reverts commit 703fc135dfcd496a704562ddc263aa0f4f828de9.
Diffstat (limited to 'src/mailman/database')
| -rw-r--r-- | src/mailman/database/alembic/versions/cb7fc8476779_header_match_chain_renamed_to_action.py | 57 | ||||
| -rw-r--r-- | src/mailman/database/tests/test_migrations.py | 51 |
2 files changed, 0 insertions, 108 deletions
diff --git a/src/mailman/database/alembic/versions/cb7fc8476779_header_match_chain_renamed_to_action.py b/src/mailman/database/alembic/versions/cb7fc8476779_header_match_chain_renamed_to_action.py deleted file mode 100644 index 45a09b936..000000000 --- a/src/mailman/database/alembic/versions/cb7fc8476779_header_match_chain_renamed_to_action.py +++ /dev/null @@ -1,57 +0,0 @@ -"""HeaderMatch chain renamed to action - -Revision ID: cb7fc8476779 -Revises: d4fbb4fd34ca -Create Date: 2016-02-02 17:23:36.199207 - -""" - -# revision identifiers, used by Alembic. -revision = 'cb7fc8476779' -down_revision = 'd4fbb4fd34ca' - -import sqlalchemy as sa -from alembic import op -from mailman.database.helpers import is_sqlite, exists_in_db -from mailman.database.types import Enum -from mailman.interfaces.action import Action - - -# Don't import the table definition from the models, it may break this -# migration when the model is updated in the future (see the Alembic doc) -hm_table = sa.sql.table('headermatch', - sa.sql.column('action', Enum(Action)), - sa.sql.column('chain', sa.VARCHAR()) - ) - - -def upgrade(): - if not exists_in_db(op.get_bind(), 'headermatch', 'action'): - op.add_column( - 'headermatch', sa.Column('action', Enum(Action), nullable=True)) - - # Now migrate the data - for action_enum in Action: - op.execute(hm_table.update( - ).values(action=action_enum - ).where(hm_table.c.chain == action_enum.name)) - # Now that data is migrated, drop the old column (except on SQLite which - # does not support this) - if not is_sqlite(op.get_bind()): - op.drop_column('headermatch', 'chain') - - -def downgrade(): - if not exists_in_db(op.get_bind(), 'headermatch', 'chain'): - op.add_column( - 'headermatch', sa.Column('chain', sa.VARCHAR(), nullable=True)) - - # Now migrate the data - for action_enum in Action: - op.execute(hm_table.update( - ).values(chain=action_enum.name - ).where(hm_table.c.action == action_enum)) - # Now that data is migrated, drop the new column (except on SQLite which - # does not support this) - if not is_sqlite(op.get_bind()): - op.drop_column('headermatch', 'action') diff --git a/src/mailman/database/tests/test_migrations.py b/src/mailman/database/tests/test_migrations.py index 560c10648..c3558abea 100644 --- a/src/mailman/database/tests/test_migrations.py +++ b/src/mailman/database/tests/test_migrations.py @@ -33,9 +33,6 @@ from mailman.database.alembic import alembic_cfg from mailman.database.helpers import exists_in_db from mailman.database.model import Model from mailman.database.transaction import transaction -from mailman.database.types import Enum -from mailman.interfaces.action import Action -from mailman.interfaces.mailinglist import IHeaderMatchList from mailman.testing.layers import ConfigLayer @@ -226,51 +223,3 @@ class TestMigrations(unittest.TestCase): os.path.join(config.LIST_DATA_DIR, 'ant@example.com'))) self.assertTrue(os.path.exists(ant.data_path)) self.assertTrue(os.path.exists(bee.data_path)) - - def test_cb7fc8476779_header_match_action(self): - data = { - 'header-1': Action.accept, - 'header-2': Action.hold, - 'header-3': Action.discard, - 'header-4': Action.reject, - } - # Create a mailing list through the standard API. - with transaction(): - ant = create_list('ant@example.com') - # Create header matches - header_matches = IHeaderMatchList(ant) - for header, action in data.items(): - header_matches.append(header, 'pattern', action) - hm_table = sa.sql.table( - 'headermatch', - sa.sql.column('header', sa.Unicode), - sa.sql.column('action', Enum(Action)), - sa.sql.column('chain', sa.Unicode), - ) - # Downgrade and verify that the chain names are correct. - with transaction(): - alembic.command.downgrade(alembic_cfg, 'd4fbb4fd34ca') - with transaction(): - results = config.db.store.execute( - sa.select([hm_table.c.header, hm_table.c.chain])).fetchall() - self.assertEqual(len(results), 4) - for header, chain in results: - self.assertEqual(chain, data[header].name) - if config.db.store.bind.dialect.name == 'sqlite': - # Clear the previous values for testing, since SQLite did not - # remove the column. - with transaction(): - config.db.store.execute( - hm_table.update().values(action=None)) - for action in config.db.store.execute( - sa.select([hm_table.c.action])).fetchall(): - self.assertEqual(action[0], None) - # Upgrade and verify that the actions are back to normal. - with transaction(): - alembic.command.upgrade(alembic_cfg, 'cb7fc8476779') - with transaction(): - results = config.db.store.execute( - sa.select([hm_table.c.header, hm_table.c.action])).fetchall() - self.assertEqual(len(results), 4) - for header, action in results: - self.assertEqual(action, data[header]) |
