Skip to content

Commit

Permalink
fix: upgrade sql requirements to support the online mode (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Crocfer <nicolas.crocfer@ovhcloud.com>
  • Loading branch information
ncrocfer authored Nov 25, 2022
1 parent 78a5024 commit aa8b079
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
17 changes: 6 additions & 11 deletions director/migrations/versions/2ac615d6850b_force_varchar_255.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,27 @@
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():
"""
This migration is only useful for an existing Celery Director instance.
"""
with op.batch_alter_table("tasks", copy_from=tables["tasks"]) as batch_op:
with op.batch_alter_table("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", copy_from=tables["users"]) as batch_op:
with op.batch_alter_table("users") as batch_op:
batch_op.alter_column(
"password",
existing_type=sa.VARCHAR(),
Expand All @@ -47,7 +42,7 @@ def upgrade():
existing_nullable=False,
)

with op.batch_alter_table("workflows", copy_from=tables["workflows"]) as batch_op:
with op.batch_alter_table("workflows") as batch_op:
batch_op.alter_column(
"name",
existing_type=sa.VARCHAR(),
Expand All @@ -63,7 +58,7 @@ def upgrade():


def downgrade():
with op.batch_alter_table("workflows", copy_from=tables["workflows"]) as batch_op:
with op.batch_alter_table("workflows") as batch_op:
batch_op.alter_column(
"project",
existing_type=sa.String(length=255),
Expand All @@ -77,7 +72,7 @@ def downgrade():
existing_nullable=False,
)

with op.batch_alter_table("users", copy_from=tables["users"]) as batch_op:
with op.batch_alter_table("users") as batch_op:
batch_op.alter_column(
"username",
existing_type=sa.String(length=255),
Expand All @@ -91,7 +86,7 @@ def downgrade():
existing_nullable=False,
)

with op.batch_alter_table("tasks", copy_from=tables["tasks"]) as batch_op:
with op.batch_alter_table("tasks") as batch_op:
batch_op.alter_column(
"key",
existing_type=sa.String(length=255),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
from alembic import op
from director.extensions import db


# revision identifiers, used by Alembic.
Expand All @@ -15,16 +14,14 @@
branch_labels = None
depends_on = None

tables = db.metadata.tables


def upgrade():
bind = op.get_bind()
if bind.engine.name == "sqlite":
# SQLite does not support to alter constraints on existing tables.
# Batch mode is used to copy data to a temporary table meanwhile creating a brand new
# table with the required constraint.
with op.batch_alter_table("tasks", copy_from=tables["tasks"]) as batch_op:
with op.batch_alter_table("tasks") as batch_op:
batch_op.drop_constraint(
op.f("fk_tasks_workflow_id_workflows"), type_="foreignkey"
)
Expand Down Expand Up @@ -53,7 +50,7 @@ def upgrade():
def downgrade():
bind = op.get_bind()
if bind.engine.name == "sqlite":
with op.batch_alter_table("tasks", copy_from=tables["tasks"]) as batch_op:
with op.batch_alter_table("tasks") as batch_op:
batch_op.drop_constraint(
op.f("fk_tasks_workflow_id_workflows"), type_="foreignkey"
)
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ flower==1.2.0
kombu==5.2.4

# Databases
psycopg2-binary==2.9.3
SQLAlchemy==1.3.11
sqlalchemy-utils==0.35.0
mysql-connector-python==8.0.21
psycopg2-binary==2.9.5
SQLAlchemy==1.4.44
sqlalchemy-utils==0.38.3
mysql-connector-python==8.0.31
redis==4.2.2
alembic==1.3.2
alembic==1.8.1

# Flask
Flask==2.1.1
Expand Down

0 comments on commit aa8b079

Please sign in to comment.