"Fossies" - the Fresh Open Source Software Archive

Member "mailman-3.3.7/src/mailman/database/alembic/versions/16c2b25c7b_list_subscription_policy.py" (10 Nov 2022, 1427 Bytes) of package /linux/misc/mailman-3.3.7.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "16c2b25c7b_list_subscription_policy.py" see the Fossies "Dox" file reference documentation.

    1 """List subscription policy
    2 
    3 Revision ID: 16c2b25c7b
    4 Revises: 46e92facee7
    5 Create Date: 2015-03-21 11:00:44.634883
    6 
    7 """
    8 
    9 import sqlalchemy as sa
   10 
   11 from alembic import op
   12 from mailman.database.helpers import exists_in_db, is_sqlite
   13 from mailman.database.types import Enum
   14 from mailman.interfaces.mailinglist import SubscriptionPolicy
   15 
   16 
   17 # Revision identifiers, used by Alembic.
   18 revision = '16c2b25c7b'
   19 down_revision = '46e92facee7'
   20 
   21 
   22 def upgrade():
   23     # Update the schema.
   24     if not exists_in_db(op.get_bind(), 'mailinglist', 'subscription_policy'):
   25         # SQLite may not have removed it when downgrading.
   26         op.add_column('mailinglist', sa.Column(
   27             'subscription_policy', Enum(SubscriptionPolicy), nullable=True))
   28     # Now migrate the data.  Don't import the table definition from the
   29     # models, it may break this migration when the model is updated in the
   30     # future (see the Alembic doc).
   31     mlist = sa.sql.table(
   32         'mailinglist',
   33         sa.sql.column('subscription_policy', Enum(SubscriptionPolicy))
   34         )
   35     # There were no enforced subscription policy before, so all lists are
   36     # considered open.
   37     op.execute(mlist.update().values(
   38         {'subscription_policy': op.inline_literal(SubscriptionPolicy.open)}))
   39 
   40 
   41 def downgrade():
   42     if not is_sqlite(op.get_bind()):
   43         # SQLite does not support dropping columns.
   44         op.drop_column('mailinglist', 'subscription_policy')