summaryrefslogtreecommitdiff
path: root/src/mailman/database/alembic/versions/448a93984c35_unsubscription_workflow.py
blob: 64fcdffcdd52767bef4fb20c57e15d689656c236 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""unsubscription_workflow

Revision ID: 448a93984c35
Revises: 7b254d88f122
Create Date: 2016-06-02 14:34:24.154723
"""

import sqlalchemy as sa
from alembic import op
from mailman.database.helpers import exists_in_db
from mailman.database.types import Enum
from mailman.interfaces.mailinglist import SubscriptionPolicy


# revision identifiers, used by Alembic.
revision = '448a93984c35'
down_revision = '7b254d88f122'


def upgrade():
    if not exists_in_db(op.get_bind(), 'mailinglist', 'unsubscription_policy'):
        with op.batch_alter_table('mailinglist') as batch_op:
            # SQLite may not have removed it when downgrading.
            batch_op.add_column('mailinglist', sa.Column(
                'unsubscription_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('unsubscription_policy', Enum(SubscriptionPolicy))
            )
        # There were no enforced subscription policy before, so all lists are
        # considered open.
        op.execute(mlist.update().values(
            {'unsubscription_policy':
             op.inline_literal(SubscriptionPolicy.open)}))


def downgrade():
    with op.batch_alter_table('mailinglist') as batch_op:
        batch_op.drop_column('mailinglist', 'unsubscription_policy')