Fix unique constraints and column nullability

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-01-17 07:07:45 -03:00
commit fa55e98a0b
7 changed files with 31 additions and 21 deletions

View file

@ -27,7 +27,8 @@ def upgrade() -> None:
with op.batch_alter_table('user', schema=None) as batch_op: with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.create_unique_constraint('uq_user_id', ['id']) batch_op.create_unique_constraint('uq_user_id', ['id'])
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###
@ -44,6 +45,7 @@ def downgrade() -> None:
with op.batch_alter_table('apikey', schema=None) as batch_op: with op.batch_alter_table('apikey', schema=None) as batch_op:
batch_op.drop_constraint('uq_apikey_id', type_='unique') batch_op.drop_constraint('uq_apikey_id', type_='unique')
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###

View file

@ -29,9 +29,10 @@ def upgrade() -> None:
sa.Column('id', sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column('id', sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('pk_credential')), sa.PrimaryKeyConstraint('id'),
) )
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###
@ -40,6 +41,7 @@ def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
try: try:
op.drop_table('credential') op.drop_table('credential')
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###

View file

@ -45,6 +45,7 @@ def downgrade() -> None:
with op.batch_alter_table("flow", schema=None) as batch_op: with op.batch_alter_table("flow", schema=None) as batch_op:
batch_op.drop_column("is_component") batch_op.drop_column("is_component")
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###

View file

@ -37,7 +37,6 @@ def upgrade() -> None:
with op.batch_alter_table('flow', schema=None) as batch_op: with op.batch_alter_table('flow', schema=None) as batch_op:
batch_op.add_column(sa.Column('updated_at', sa.DateTime(), nullable=True)) batch_op.add_column(sa.Column('updated_at', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('folder', sqlmodel.sql.sqltypes.AutoString(), nullable=True)) batch_op.add_column(sa.Column('folder', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###
@ -67,8 +66,8 @@ def downgrade() -> None:
sa.Column('flow_id', sa.CHAR(length=32), nullable=True), sa.Column('flow_id', sa.CHAR(length=32), nullable=True),
sa.Column('id', sa.CHAR(length=32), nullable=False), sa.Column('id', sa.CHAR(length=32), nullable=False),
sa.ForeignKeyConstraint(['flow_id'], ['flow.id'], ), sa.ForeignKeyConstraint(['flow_id'], ['flow.id'], ),
sa.PrimaryKeyConstraint('id', name=op.f('pk_flowstyle')) sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('id', name=op.f('uq_flowstyle_id')) sa.UniqueConstraint('id')
) )
op.create_table('component', op.create_table('component',
sa.Column('id', sa.CHAR(length=32), nullable=False), sa.Column('id', sa.CHAR(length=32), nullable=False),
@ -81,7 +80,7 @@ def downgrade() -> None:
sa.Column('is_read_only', sa.BOOLEAN(), nullable=False), sa.Column('is_read_only', sa.BOOLEAN(), nullable=False),
sa.Column('create_at', sa.DATETIME(), nullable=False), sa.Column('create_at', sa.DATETIME(), nullable=False),
sa.Column('update_at', sa.DATETIME(), nullable=False), sa.Column('update_at', sa.DATETIME(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_component')) sa.PrimaryKeyConstraint('id')
) )
with op.batch_alter_table('component', schema=None) as batch_op: with op.batch_alter_table('component', schema=None) as batch_op:

View file

@ -29,7 +29,8 @@ def upgrade() -> None:
except exc.SQLAlchemyError: except exc.SQLAlchemyError:
# connection.execute(text("ROLLBACK")) # connection.execute(text("ROLLBACK"))
pass pass
except Exception: except Exception as e:
print(e)
pass pass
try: try:
@ -37,7 +38,8 @@ def upgrade() -> None:
except exc.SQLAlchemyError: except exc.SQLAlchemyError:
# connection.execute(text("ROLLBACK")) # connection.execute(text("ROLLBACK"))
pass pass
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###
@ -64,7 +66,8 @@ def downgrade() -> None:
batch_op.create_index( batch_op.create_index(
"ix_component_frontend_node_id", ["frontend_node_id"], unique=False "ix_component_frontend_node_id", ["frontend_node_id"], unique=False
) )
except Exception: except Exception as e:
print(e)
pass pass
try: try:
@ -81,6 +84,7 @@ def downgrade() -> None:
sa.PrimaryKeyConstraint("id", name="pk_flowstyle"), sa.PrimaryKeyConstraint("id", name="pk_flowstyle"),
sa.UniqueConstraint("id", name="uq_flowstyle_id"), sa.UniqueConstraint("id", name="uq_flowstyle_id"),
) )
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###

View file

@ -7,10 +7,8 @@ Create Date: 2023-10-18 23:12:27.297016
""" """
from typing import Sequence, Union from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
import sqlmodel from alembic import op
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision: str = "f5ee9749d1a6" revision: str = "f5ee9749d1a6"
@ -26,7 +24,8 @@ def upgrade() -> None:
batch_op.alter_column( batch_op.alter_column(
"user_id", existing_type=sa.CHAR(length=32), nullable=True "user_id", existing_type=sa.CHAR(length=32), nullable=True
) )
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###
@ -39,7 +38,8 @@ def downgrade() -> None:
batch_op.alter_column( batch_op.alter_column(
"user_id", existing_type=sa.CHAR(length=32), nullable=False "user_id", existing_type=sa.CHAR(length=32), nullable=False
) )
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###

View file

@ -21,7 +21,8 @@ def upgrade() -> None:
try: try:
with op.batch_alter_table('credential', schema=None) as batch_op: with op.batch_alter_table('credential', schema=None) as batch_op:
batch_op.create_foreign_key("fk_credential_user_id", 'user', ['user_id'], ['id']) batch_op.create_foreign_key("fk_credential_user_id", 'user', ['user_id'], ['id'])
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###
@ -32,7 +33,8 @@ def downgrade() -> None:
try: try:
with op.batch_alter_table('credential', schema=None) as batch_op: with op.batch_alter_table('credential', schema=None) as batch_op:
batch_op.drop_constraint("fk_credential_user_id", type_='foreignkey') batch_op.drop_constraint("fk_credential_user_id", type_='foreignkey')
except Exception: except Exception as e:
print(e)
pass pass
# ### end Alembic commands ### # ### end Alembic commands ###