summaryrefslogtreecommitdiff
path: root/src/mailman/database
diff options
context:
space:
mode:
authorAurélien Bompard2016-02-02 11:49:00 +0100
committerBarry Warsaw2016-02-29 21:52:13 -0500
commit15238cb5683eb9a0eab9dcd251f509a693a22451 (patch)
treeb57d661d1a6f2b1ff4b8c6920d898c36aa016164 /src/mailman/database
parent14dbe7fb4a6b29ce955fa1c8d4c1859c514e8e13 (diff)
downloadmailman-15238cb5683eb9a0eab9dcd251f509a693a22451.tar.gz
mailman-15238cb5683eb9a0eab9dcd251f509a693a22451.tar.zst
mailman-15238cb5683eb9a0eab9dcd251f509a693a22451.zip
The order of a mailing list's header matches is significant
Add a numerical index property to HeaderMatch objects, and change the HeaderMatchSet manager to take the order into account. Items can now be inserted and removed by index.
Diffstat (limited to 'src/mailman/database')
-rw-r--r--src/mailman/database/alembic/versions/d4fbb4fd34ca_header_match_order.py40
-rw-r--r--src/mailman/database/tests/test_migrations.py6
2 files changed, 44 insertions, 2 deletions
diff --git a/src/mailman/database/alembic/versions/d4fbb4fd34ca_header_match_order.py b/src/mailman/database/alembic/versions/d4fbb4fd34ca_header_match_order.py
new file mode 100644
index 000000000..00064bc1e
--- /dev/null
+++ b/src/mailman/database/alembic/versions/d4fbb4fd34ca_header_match_order.py
@@ -0,0 +1,40 @@
+"""Add a numerical index to sort header matches.
+
+Revision ID: d4fbb4fd34ca
+Revises: bfda02ab3a9b
+Create Date: 2016-02-01 15:57:09.807678
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'd4fbb4fd34ca'
+down_revision = 'bfda02ab3a9b'
+
+import sqlalchemy as sa
+from alembic import op
+from mailman.database.helpers import is_sqlite
+
+
+def upgrade():
+ op.add_column(
+ 'headermatch', sa.Column('index', sa.Integer(), nullable=True))
+ if not is_sqlite(op.get_bind()):
+ op.alter_column(
+ 'headermatch', 'mailing_list_id',
+ existing_type=sa.INTEGER(), nullable=False)
+ op.create_index(
+ op.f('ix_headermatch_index'), 'headermatch', ['index'], unique=False)
+ op.create_index(
+ op.f('ix_headermatch_mailing_list_id'), 'headermatch',
+ ['mailing_list_id'], unique=False)
+
+
+def downgrade():
+ op.drop_index(
+ op.f('ix_headermatch_mailing_list_id'), table_name='headermatch')
+ op.drop_index(op.f('ix_headermatch_index'), table_name='headermatch')
+ if not is_sqlite(op.get_bind()):
+ op.alter_column(
+ 'headermatch', 'mailing_list_id',
+ existing_type=sa.INTEGER(), nullable=True)
+ op.drop_column('headermatch', 'index')
diff --git a/src/mailman/database/tests/test_migrations.py b/src/mailman/database/tests/test_migrations.py
index 89173e26b..c3558abea 100644
--- a/src/mailman/database/tests/test_migrations.py
+++ b/src/mailman/database/tests/test_migrations.py
@@ -85,7 +85,9 @@ class TestMigrations(unittest.TestCase):
sa.sql.column('header', sa.Unicode),
sa.sql.column('pattern', sa.Unicode),
)
- # Downgrading.
+ # Bring the DB to the revision that is being tested.
+ alembic.command.downgrade(alembic_cfg, '42756496720')
+ # Test downgrading.
config.db.store.execute(mlist_table.insert().values(id=1))
config.db.store.execute(header_match_table.insert().values(
[{'mailing_list_id': 1, 'header': hm[0], 'pattern': hm[1]}
@@ -97,7 +99,7 @@ class TestMigrations(unittest.TestCase):
self.assertEqual(results[0].header_matches, test_header_matches)
self.assertFalse(exists_in_db(config.db.engine, 'headermatch'))
config.db.store.commit()
- # Upgrading.
+ # Test upgrading.
alembic.command.upgrade(alembic_cfg, '42756496720')
results = config.db.store.execute(
header_match_table.select()).fetchall()