"Fossies" - the Fresh Open Source Software Archive

Member "mailman-3.3.7/src/mailman/database/alembic/versions/3002bac0c25a_dmarc_attributes.py" (10 Nov 2022, 2518 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 "3002bac0c25a_dmarc_attributes.py" see the Fossies "Dox" file reference documentation.

    1 """dmarc_attributes
    2 
    3 Revision ID: 3002bac0c25a
    4 Revises: a46993b05703
    5 Create Date: 2016-10-30 22:05:17.881880
    6 
    7 """
    8 
    9 import sqlalchemy as sa
   10 
   11 from alembic import op
   12 from mailman.database.helpers import exists_in_db
   13 from mailman.database.types import Enum, SAUnicodeLarge
   14 from mailman.interfaces.mailinglist import DMARCMitigateAction
   15 
   16 
   17 # revision identifiers, used by Alembic.
   18 revision = '3002bac0c25a'
   19 down_revision = 'a46993b05703'
   20 
   21 
   22 def upgrade():
   23     if not exists_in_db(op.get_bind(),
   24                         'mailinglist',
   25                         'dmarc_mitigate_action'
   26                         ):
   27         # SQLite may not have removed it when downgrading.  It should be OK
   28         # to just test one.
   29         op.add_column('mailinglist', sa.Column(
   30             'dmarc_mitigate_action',
   31             Enum(DMARCMitigateAction),
   32             nullable=True))
   33         op.add_column('mailinglist', sa.Column(
   34             'dmarc_mitigate_unconditionally',
   35             sa.Boolean,
   36             nullable=True))
   37         op.add_column('mailinglist', sa.Column(
   38             'dmarc_moderation_notice',
   39             SAUnicodeLarge(),
   40             nullable=True))
   41         op.add_column('mailinglist', sa.Column(
   42             'dmarc_wrapped_message_text',
   43             SAUnicodeLarge(),
   44             nullable=True))
   45     # Now migrate the data.  Don't import the table definition from the
   46     # models, it may break this migration when the model is updated in the
   47     # future (see the Alembic doc).
   48     mlist = sa.sql.table(
   49         'mailinglist',
   50         sa.sql.column('dmarc_mitigate_action', Enum(DMARCMitigateAction)),
   51         sa.sql.column('dmarc_mitigate_unconditionally', sa.Boolean),
   52         sa.sql.column('dmarc_moderation_notice', SAUnicodeLarge()),
   53         sa.sql.column('dmarc_wrapped_message_text', SAUnicodeLarge()),
   54         )
   55     # These are all new attributes so just set defaults.
   56     op.execute(mlist.update().values(dict(
   57         dmarc_mitigate_action=op.inline_literal(
   58             DMARCMitigateAction.no_mitigation),
   59         dmarc_mitigate_unconditionally=op.inline_literal(False),
   60         dmarc_moderation_notice=op.inline_literal(''),
   61         dmarc_wrapped_message_text=op.inline_literal(''),
   62         )))
   63 
   64 
   65 def downgrade():
   66     with op.batch_alter_table('mailinglist') as batch_op:
   67         batch_op.drop_column('dmarc_mitigate_action')
   68         batch_op.drop_column('dmarc_mitigate_unconditionally')
   69         batch_op.drop_column('dmarc_moderation_notice')
   70         batch_op.drop_column('dmarc_wrapped_message_text')