diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/database/alembic/versions/16c2b25c7b_list_subscription_policy.py | 41 | ||||
| -rw-r--r-- | src/mailman/database/tests/test_factory.py | 11 | ||||
| -rw-r--r-- | src/mailman/model/mailinglist.py | 3 |
3 files changed, 46 insertions, 9 deletions
diff --git a/src/mailman/database/alembic/versions/16c2b25c7b_list_subscription_policy.py b/src/mailman/database/alembic/versions/16c2b25c7b_list_subscription_policy.py new file mode 100644 index 000000000..d5f8c3d96 --- /dev/null +++ b/src/mailman/database/alembic/versions/16c2b25c7b_list_subscription_policy.py @@ -0,0 +1,41 @@ +"""List subscription policy + +Revision ID: 16c2b25c7b +Revises: 33e1f5f6fa8 +Create Date: 2015-03-21 11:00:44.634883 + +""" + +# revision identifiers, used by Alembic. +revision = '16c2b25c7b' +down_revision = '33e1f5f6fa8' + +from alembic import op +import sqlalchemy as sa + +from mailman.database.types import Enum +from mailman.interfaces.mailinglist import SubscriptionPolicy + + +def upgrade(): + + ### Update the schema + op.add_column('mailinglist', sa.Column( + 'subscription_policy', Enum(SubscriptionPolicy), nullable=True)) + + ### Now migrate the data + # 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) + mlist = sa.sql.table('mailinglist', + sa.sql.column('subscription_policy', Enum(SubscriptionPolicy)) + ) + # there were no enforced subscription policy before, so all lists are + # considered open + op.execute(mlist.update().values( + {'subscription_policy': op.inline_literal(SubscriptionPolicy.open)})) + + +def downgrade(): + if op.get_bind().dialect.name != 'sqlite': + # SQLite does not support dropping columns. + op.drop_column('mailinglist', 'subscription_policy') diff --git a/src/mailman/database/tests/test_factory.py b/src/mailman/database/tests/test_factory.py index 6a16c74ab..acb7c32a4 100644 --- a/src/mailman/database/tests/test_factory.py +++ b/src/mailman/database/tests/test_factory.py @@ -129,17 +129,14 @@ class TestSchemaManager(unittest.TestCase): md.tables['alembic_version'].select()).scalar() self.assertEqual(current_rev, head_rev) - @patch('alembic.command.stamp') - def test_storm(self, alembic_command_stamp): + @patch('alembic.command') + def test_storm(self, alembic_command): # Existing Storm database. Model.metadata.create_all(config.db.engine) self._create_storm_database(LAST_STORM_SCHEMA_VERSION) self.schema_mgr.setup_database() - self.assertFalse(alembic_command_stamp.called) - self.assertTrue( - self._table_exists('mailinglist') - and self._table_exists('alembic_version') - and not self._table_exists('version')) + self.assertFalse(alembic_command.stamp.called) + self.assertTrue(alembic_command.upgrade.called) @patch('alembic.command') def test_old_storm(self, alembic_command): diff --git a/src/mailman/model/mailinglist.py b/src/mailman/model/mailinglist.py index a5ecfddbe..0607b90e4 100644 --- a/src/mailman/model/mailinglist.py +++ b/src/mailman/model/mailinglist.py @@ -183,6 +183,7 @@ class MailingList(Model): send_goodbye_message = Column(Boolean) send_welcome_message = Column(Boolean) subject_prefix = Column(Unicode) + subscription_policy = Column(Enum(SubscriptionPolicy)) topics = Column(PickleType) topics_bodylines_limit = Column(Integer) topics_enabled = Column(Boolean) @@ -197,8 +198,6 @@ class MailingList(Model): self._list_id = '{0}.{1}'.format(listname, hostname) # For the pending database self.next_request_id = 1 - # XXX Make this a database column: Enum(SubscriptionPolicy) - self.subscription_policy = None # We need to set up the rosters. Normally, this method will get called # when the MailingList object is loaded from the database, but when the # constructor is called, SQLAlchemy's `load` event isn't triggered. |
