1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-12 10:45:38 +02:00

add migration script

This commit is contained in:
hoellen 2019-01-06 15:36:57 +01:00
parent 78f544c678
commit 501ecf13c1

View File

@ -0,0 +1,65 @@
"""change default unlimited value for max_users and max_aliases to -1
Revision ID: fc099bd15cbe
Revises: cd79ed46d9c2
Create Date: 2019-01-06 13:40:23.372373
"""
# revision identifiers, used by Alembic.
revision = 'fc099bd15cbe'
down_revision = 'cd79ed46d9c2'
from alembic import op
import sqlalchemy as sa
domain_table = sa.Table(
'domain',
sa.MetaData(),
sa.Column('max_users', sa.Integer(), nullable=False),
sa.Column('max_aliases', sa.Integer(), nullable=False),
)
def upgrade():
connection = op.get_bind()
connection.execute(
domain_table.update().where(
domain_table.c.max_users == 0
).values(
max_users=-1
)
)
connection.execute(
domain_table.update().where(
domain_table.c.max_aliases == 0
).values(
max_aliases=-1
)
)
#set new unlimited default to -1
with op.batch_alter_table('domain') as batch:
batch.alter_column('max_users', server_default='-1')
batch.alter_column('max_aliases', server_default='-1')
def downgrade():
connection = op.get_bind()
connection.execute(
domain_table.update().where(
domain_table.c.max_users == -1
).values(
max_users=0
)
)
connection.execute(
domain_table.update().where(
domain_table.c.max_aliases == -1
).values(
max_aliases=0
)
)
#set default to 0
with op.batch_alter_table('domain') as batch:
batch.alter_column('max_users', server_default='0')
batch.alter_column('max_aliases', server_default='0')