From 44415ab0d2cb7e72cea88511553f201904f0fe9b Mon Sep 17 00:00:00 2001 From: Nicolas Crocfer Date: Thu, 15 Oct 2020 18:34:04 +0200 Subject: [PATCH] fix(migrations): use the offline mode for sqlite engine Signed-off-by: Nicolas Crocfer --- ..._add_index_on_workflow_id_in_task_table.py | 4 --- .../2ac615d6850b_force_varchar_255.py | 28 ++++++++++--------- .../versions/3f8466b16023_add_users_table.py | 4 --- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/director/migrations/versions/063ff371f2da_add_index_on_workflow_id_in_task_table.py b/director/migrations/versions/063ff371f2da_add_index_on_workflow_id_in_task_table.py index 618a8c3..3414f3a 100644 --- a/director/migrations/versions/063ff371f2da_add_index_on_workflow_id_in_task_table.py +++ b/director/migrations/versions/063ff371f2da_add_index_on_workflow_id_in_task_table.py @@ -17,14 +17,10 @@ def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.create_index( op.f("ix_tasks_workflow_id"), "tasks", ["workflow_id"], unique=False ) - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f("ix_tasks_workflow_id"), table_name="tasks") - # ### end Alembic commands ### diff --git a/director/migrations/versions/2ac615d6850b_force_varchar_255.py b/director/migrations/versions/2ac615d6850b_force_varchar_255.py index 5b5de1d..f97d065 100644 --- a/director/migrations/versions/2ac615d6850b_force_varchar_255.py +++ b/director/migrations/versions/2ac615d6850b_force_varchar_255.py @@ -1,4 +1,4 @@ -"""force varchar 255 +"""Force varchar 255 Revision ID: 2ac615d6850b Revises: 063ff371f2da @@ -8,6 +8,8 @@ from alembic import op import sqlalchemy as sa +from director.extensions import db + # revision identifiers, used by Alembic. revision = "2ac615d6850b" @@ -15,10 +17,15 @@ branch_labels = None depends_on = None +# Store the list of tables +tables = {t[0]: t[1] for t in db.metadata.tables.items()} + def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("tasks", schema=None) as batch_op: + """ + This migration is only useful for an existing Celery Director instance. + """ + with op.batch_alter_table("tasks", copy_from=tables["tasks"]) as batch_op: batch_op.alter_column( "key", existing_type=sa.VARCHAR(), @@ -26,7 +33,7 @@ def upgrade(): existing_nullable=False, ) - with op.batch_alter_table("users", schema=None) as batch_op: + with op.batch_alter_table("users", copy_from=tables["users"]) as batch_op: batch_op.alter_column( "password", existing_type=sa.VARCHAR(), @@ -40,7 +47,7 @@ def upgrade(): existing_nullable=False, ) - with op.batch_alter_table("workflows", schema=None) as batch_op: + with op.batch_alter_table("workflows", copy_from=tables["workflows"]) as batch_op: batch_op.alter_column( "name", existing_type=sa.VARCHAR(), @@ -54,12 +61,9 @@ def upgrade(): existing_nullable=False, ) - # ### end Alembic commands ### - def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("workflows", schema=None) as batch_op: + with op.batch_alter_table("workflows", copy_from=tables["workflows"]) as batch_op: batch_op.alter_column( "project", existing_type=sa.String(length=255), @@ -73,7 +77,7 @@ def downgrade(): existing_nullable=False, ) - with op.batch_alter_table("users", schema=None) as batch_op: + with op.batch_alter_table("users", copy_from=tables["users"]) as batch_op: batch_op.alter_column( "username", existing_type=sa.String(length=255), @@ -87,12 +91,10 @@ def downgrade(): existing_nullable=False, ) - with op.batch_alter_table("tasks", schema=None) as batch_op: + with op.batch_alter_table("tasks", copy_from=tables["tasks"]) as batch_op: batch_op.alter_column( "key", existing_type=sa.String(length=255), type_=sa.VARCHAR(), existing_nullable=False, ) - - # ### end Alembic commands ### diff --git a/director/migrations/versions/3f8466b16023_add_users_table.py b/director/migrations/versions/3f8466b16023_add_users_table.py index dd7648e..4fd74ed 100644 --- a/director/migrations/versions/3f8466b16023_add_users_table.py +++ b/director/migrations/versions/3f8466b16023_add_users_table.py @@ -18,7 +18,6 @@ def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.create_table( "users", sa.Column("id", UUIDType(binary=False), nullable=False), @@ -30,11 +29,8 @@ def upgrade(): sa.UniqueConstraint("username", name=op.f("uq_users_username")), ) op.create_index(op.f("ix_users_created_at"), "users", ["created_at"], unique=False) - # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f("ix_users_created_at"), table_name="users") op.drop_table("users") - # ### end Alembic commands ###