Skip to content

Commit

Permalink
fix(migrations): use the offline mode for sqlite engine
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Crocfer <nicolas.crocfer@corp.ovh.com>
  • Loading branch information
ncrocfer committed Oct 16, 2020
1 parent d3884ac commit 44415ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
28 changes: 15 additions & 13 deletions director/migrations/versions/2ac615d6850b_force_varchar_255.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""force varchar 255
"""Force varchar 255
Revision ID: 2ac615d6850b
Revises: 063ff371f2da
Expand All @@ -8,25 +8,32 @@
from alembic import op
import sqlalchemy as sa

from director.extensions import db


# revision identifiers, used by Alembic.
revision = "2ac615d6850b"
down_revision = "063ff371f2da"
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(),
type_=sa.String(length=255),
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(),
Expand All @@ -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(),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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 ###
4 changes: 0 additions & 4 deletions director/migrations/versions/3f8466b16023_add_users_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 ###

0 comments on commit 44415ab

Please sign in to comment.