Skip to content

Commit

Permalink
🐛migration of api_keys fails (ITISFoundation#4935)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg authored Oct 26, 2023
1 parent 71117c3 commit 783e50b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _find_default_product_name_or_none(conn):

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("api_keys", sa.Column("product_name", sa.String(), nullable=False))
op.add_column("api_keys", sa.Column("product_name", sa.String(), nullable=True))
op.create_foreign_key(
"fk_api_keys_product_name",
"api_keys",
Expand All @@ -39,7 +39,12 @@ def upgrade():
conn = op.get_bind()
default_product = _find_default_product_name_or_none(conn)
if default_product:
op.execute(f"UPDATE api_keys SET product_name = '{default_product}'")
op.execute(sa.DDL(f"UPDATE api_keys SET product_name = '{default_product}'"))

# make it non nullable now
op.alter_column(
"api_keys", "product_name", existing_type=sa.String(), nullable=False
)


def downgrade():
Expand Down

0 comments on commit 783e50b

Please sign in to comment.