diff options
Diffstat (limited to 'src/mailman/database')
3 files changed, 86 insertions, 0 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..8534f4b73 --- /dev/null +++ b/src/mailman/database/alembic/versions/16c2b25c7b_list_subscription_policy.py @@ -0,0 +1,41 @@ +"""List subscription policy + +Revision ID: 16c2b25c7b +Revises: 46e92facee7 +Create Date: 2015-03-21 11:00:44.634883 + +""" + +# revision identifiers, used by Alembic. +revision = '16c2b25c7b' +down_revision = '46e92facee7' + +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/alembic/versions/2bb9b382198_workflow_state_table.py b/src/mailman/database/alembic/versions/2bb9b382198_workflow_state_table.py new file mode 100644 index 000000000..59cb1121e --- /dev/null +++ b/src/mailman/database/alembic/versions/2bb9b382198_workflow_state_table.py @@ -0,0 +1,28 @@ +"""Workflow state table + +Revision ID: 2bb9b382198 +Revises: 16c2b25c7b +Create Date: 2015-03-25 18:09:18.338790 + +""" + +# revision identifiers, used by Alembic. +revision = '2bb9b382198' +down_revision = '16c2b25c7b' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.create_table('workflowstate', + sa.Column('name', sa.Unicode(), nullable=False), + sa.Column('key', sa.Unicode(), nullable=False), + sa.Column('step', sa.Unicode(), nullable=True), + sa.Column('data', sa.Unicode(), nullable=True), + sa.PrimaryKeyConstraint('name', 'key') + ) + + +def downgrade(): + op.drop_table('workflowstate') diff --git a/src/mailman/database/transaction.py b/src/mailman/database/transaction.py index b96562d3f..fef76b73c 100644 --- a/src/mailman/database/transaction.py +++ b/src/mailman/database/transaction.py @@ -19,6 +19,7 @@ __all__ = [ 'dbconnection', + 'flush', 'transaction', 'transactional', ] @@ -63,6 +64,22 @@ def transactional(function): +@contextmanager +def flush(): + """Context manager for flushing SQLAlchemy. + + We need this for SA whereas we didn't need it for Storm because the latter + did auto-reloads. However, in SA this is needed when we add or delete + objects from the database. Use it when you need the id after adding, or + when you want to be sure the object won't be found after a delete. + + This is lighter weight than committing the transaction. + """ + yield + config.db.store.flush() + + + def dbconnection(function): """Decorator for getting at the database connection. |
