Add unique constraints to tables

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-20 08:17:55 -03:00
commit 481606ef00

View file

@ -8,8 +8,7 @@ Create Date: 2023-12-13 18:55:52.587360
from typing import Sequence, Union from typing import Sequence, Union
from alembic import op from alembic import op
import sqlalchemy as sa # noqa: F401
import sqlmodel # noqa: F401
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision: str = '006b3990db50' revision: str = '006b3990db50'
down_revision: Union[str, None] = '1ef9c4f3765d' down_revision: Union[str, None] = '1ef9c4f3765d'
@ -19,6 +18,7 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None: def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
try:
with op.batch_alter_table('apikey', schema=None) as batch_op: with op.batch_alter_table('apikey', schema=None) as batch_op:
batch_op.create_unique_constraint('uq_apikey_id', ['id']) batch_op.create_unique_constraint('uq_apikey_id', ['id'])
@ -27,12 +27,15 @@ 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:
pass
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade() -> None: def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
try:
with op.batch_alter_table('user', schema=None) as batch_op: with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_constraint('uq_user_id', type_='unique') batch_op.drop_constraint('uq_user_id', type_='unique')
@ -41,5 +44,6 @@ 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:
pass
# ### end Alembic commands ### # ### end Alembic commands ###