Update migration script for linting.

This commit is contained in:
Alexis Lahouze 2017-05-19 08:58:12 +02:00
parent 4b6c52dce6
commit f5415c3d66
2 changed files with 31 additions and 17 deletions

View File

@ -6,15 +6,22 @@ Create Date: 2015-08-31 10:24:40.578432
""" """
# revision identifiers, used by Alembic. # pylint: disable=no-member
revision = '1232daf66ac' # flake8: noqa
down_revision = '144929e0f5f' # flake8: noqa
from alembic import op # revision identifiers, used by Alembic.
import sqlalchemy as sa # pylint: disable=invalid-name
revision = '1232daf66ac'
down_revision = '144929e0f5f'
# pylint: enable=invalid-name
# pylint: disable=wrong-import-position
from alembic import op # noqa
import sqlalchemy as sa # noqa
# pylint: enable=wrong-import-position
def upgrade(): def upgrade():
"""Upgrades for revision 1232daf66ac"""
op.create_table( op.create_table(
'user', 'user',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
@ -28,5 +35,6 @@ def upgrade():
def downgrade(): def downgrade():
"""Downgrades for revision 1232daf66ac"""
op.drop_index(op.f('ix_user_email'), table_name='user') op.drop_index(op.f('ix_user_email'), table_name='user')
op.drop_table('user') op.drop_table('user')

View File

@ -6,17 +6,24 @@ Create Date: 2015-07-17 15:04:01.002581
""" """
# pylint: disable=no-member
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '144929e0f5f' # flake8: noqa # pylint: disable=invalid-name
down_revision = None # flake8: noqa revision = '144929e0f5f'
down_revision = None
# pylint: enable=invalid-name
from alembic import op # pylint: disable=wrong-import-position
import sqlalchemy as sa from alembic import op # noqa
import sqlalchemy as sa # noqa
from accountant.models.scheduled_operations import ScheduledOperation from accountant.models.scheduled_operations import ScheduledOperation # noqa
# pylint: enable=wrong-import-position
def upgrade(): def upgrade():
"""Upgrades for revision 144929e0f5f"""
op.get_bind().execute("DROP VIEW operation") op.get_bind().execute("DROP VIEW operation")
op.rename_table('entry', 'operation') op.rename_table('entry', 'operation')
@ -51,18 +58,15 @@ def upgrade():
"alter sequence entry_id_seq rename to operation_id_seq" "alter sequence entry_id_seq rename to operation_id_seq"
) )
connection = op.get_bind()
Session = sa.orm.sessionmaker()
session = Session(bind=connection)
# Get all scheduled operations # Get all scheduled operations
scheduled_operations = ScheduledOperation.query(session).all() scheduled_operations = ScheduledOperation.query().all()
for scheduled_operation in scheduled_operations: for scheduled_operation in scheduled_operations:
scheduled_operation.reschedule(session) scheduled_operation.reschedule()
def downgrade(): def downgrade():
"""Downgrades for revision 144929e0f5f"""
op.create_table( op.create_table(
"canceled_operation", "canceled_operation",
@ -81,6 +85,7 @@ def downgrade():
) )
op.rename_table('operation', 'entry') op.rename_table('operation', 'entry')
# pylint: disable=line-too-long
op.get_bind().execute( op.get_bind().execute(
""" """
CREATE VIEW operation AS CREATE VIEW operation AS
@ -138,5 +143,6 @@ SELECT NULL::bigint AS id,
true AS canceled true AS canceled
FROM scheduled_operation FROM scheduled_operation
JOIN canceled_operation ON canceled_operation.scheduled_operation_id = scheduled_operation.id; JOIN canceled_operation ON canceled_operation.scheduled_operation_id = scheduled_operation.id;
""" # flake8: noqa """ # noqa
) )
# pylint: enable=line-too-long