🔧 fix(update_all_tables.py): handle potential OperationalError when adding columns to 'apikey' table
✨ feat(update_all_tables.py): add support for 'user_id' column in 'apikey' table ✨ feat(update_all_tables.py): add support for 'created_at' column in 'apikey' table ✨ feat(update_all_tables.py): add support for index on 'name' column in 'apikey' table ✨ feat(update_all_tables.py): add support for index on 'user_id' column in 'apikey' table ✨ feat(update_all_tables.py): add foreign key constraint on 'user_id' column in 'apikey' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping 'create_at' column from 'apikey' table ✨ feat(update_all_tables.py): add support for 'user_id' column in 'flow' table ✨ feat(update_all_tables.py): add support for index on 'user_id' column in 'flow' table ✨ feat(update_all_tables.py): add foreign key constraint on 'user_id' column in 'flow' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping foreign key constraint from 'flow' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping index on 'user_id' column from 'flow' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping 'user_id' column from 'flow' table 🔧 fix(update_all_tables.py): handle potential OperationalError when adding 'create_at' column to 'apikey' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping foreign key constraint from 'apikey' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping index on 'user_id' column from 'apikey' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping index on 'name' column from 'apikey' table 🔧 fix(update_all_tables.py): handle potential OperationalError when altering 'name' column in 'apikey' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping 'user_id' column from 'apikey' table 🔧 fix(update_all_tables.py): handle potential OperationalError when dropping 'created_at' column from 'apikey' table
This commit is contained in:
parent
706cdc0874
commit
8b99cc06c4
1 changed files with 32 additions and 27 deletions
|
|
@ -10,44 +10,49 @@ from typing import Sequence, Union
|
|||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
|
||||
import contextlib
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'd3749cf7ac7e'
|
||||
down_revision: Union[str, None] = '5512e39b4012'
|
||||
revision: str = "d3749cf7ac7e"
|
||||
down_revision: Union[str, None] = "5512e39b4012"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('apikey', sa.Column('created_at', sa.DateTime(), nullable=False))
|
||||
op.add_column('apikey', sa.Column('user_id', sqlmodel.sql.sqltypes.GUID(), nullable=False))
|
||||
op.alter_column('apikey', 'name',
|
||||
existing_type=sa.VARCHAR(),
|
||||
nullable=True)
|
||||
op.create_index(op.f('ix_apikey_name'), 'apikey', ['name'], unique=False)
|
||||
op.create_index(op.f('ix_apikey_user_id'), 'apikey', ['user_id'], unique=False)
|
||||
op.create_foreign_key(None, 'apikey', 'user', ['user_id'], ['id'])
|
||||
op.drop_column('apikey', 'create_at')
|
||||
op.add_column('flow', sa.Column('user_id', sqlmodel.sql.sqltypes.GUID(), nullable=False))
|
||||
op.create_index(op.f('ix_flow_user_id'), 'flow', ['user_id'], unique=False)
|
||||
op.create_foreign_key(None, 'flow', 'user', ['user_id'], ['id'])
|
||||
with contextlib.suppress(sa.exc.OperationalError):
|
||||
op.add_column("apikey", sa.Column("created_at", sa.DateTime(), nullable=False))
|
||||
with contextlib.suppress(sa.exc.OperationalError):
|
||||
op.add_column(
|
||||
"apikey", sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=False)
|
||||
)
|
||||
with contextlib.suppress(sa.exc.OperationalError):
|
||||
op.alter_column("apikey", "name", existing_type=sa.VARCHAR(), nullable=True)
|
||||
with contextlib.suppress(sa.exc.OperationalError):
|
||||
op.create_index(op.f("ix_apikey_name"), "apikey", ["name"], unique=False)
|
||||
op.create_index(op.f("ix_apikey_user_id"), "apikey", ["user_id"], unique=False)
|
||||
op.create_foreign_key(None, "apikey", "user", ["user_id"], ["id"])
|
||||
with contextlib.suppress(sa.exc.OperationalError):
|
||||
op.drop_column("apikey", "create_at")
|
||||
op.add_column(
|
||||
"flow", sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=False)
|
||||
)
|
||||
op.create_index(op.f("ix_flow_user_id"), "flow", ["user_id"], unique=False)
|
||||
op.create_foreign_key(None, "flow", "user", ["user_id"], ["id"])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'flow', type_='foreignkey')
|
||||
op.drop_index(op.f('ix_flow_user_id'), table_name='flow')
|
||||
op.drop_column('flow', 'user_id')
|
||||
op.add_column('apikey', sa.Column('create_at', sa.DATETIME(), nullable=False))
|
||||
op.drop_constraint(None, 'apikey', type_='foreignkey')
|
||||
op.drop_index(op.f('ix_apikey_user_id'), table_name='apikey')
|
||||
op.drop_index(op.f('ix_apikey_name'), table_name='apikey')
|
||||
op.alter_column('apikey', 'name',
|
||||
existing_type=sa.VARCHAR(),
|
||||
nullable=False)
|
||||
op.drop_column('apikey', 'user_id')
|
||||
op.drop_column('apikey', 'created_at')
|
||||
op.drop_constraint(None, "flow", type_="foreignkey")
|
||||
op.drop_index(op.f("ix_flow_user_id"), table_name="flow")
|
||||
op.drop_column("flow", "user_id")
|
||||
op.add_column("apikey", sa.Column("create_at", sa.DATETIME(), nullable=False))
|
||||
op.drop_constraint(None, "apikey", type_="foreignkey")
|
||||
op.drop_index(op.f("ix_apikey_user_id"), table_name="apikey")
|
||||
op.drop_index(op.f("ix_apikey_name"), table_name="apikey")
|
||||
op.alter_column("apikey", "name", existing_type=sa.VARCHAR(), nullable=False)
|
||||
op.drop_column("apikey", "user_id")
|
||||
op.drop_column("apikey", "created_at")
|
||||
# ### end Alembic commands ###
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue