Add primary key and unique constraints to user, apikey, and flow tables

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-01-16 23:13:09 -03:00
commit 8cb4fe9f5f
4 changed files with 14 additions and 14 deletions

View file

@ -60,8 +60,8 @@ def upgrade() -> None:
sa.Column("create_at", sa.DateTime(), nullable=False), sa.Column("create_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False), sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.Column("last_login_at", sa.DateTime(), nullable=True), sa.Column("last_login_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id", name="pk_user"),
sa.UniqueConstraint("id"), sa.UniqueConstraint("id", name="uq_user_id"),
) )
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_index( batch_op.create_index(
@ -83,8 +83,8 @@ def upgrade() -> None:
["user_id"], ["user_id"],
["user.id"], ["user.id"],
), ),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id", name="pk_apikey"),
sa.UniqueConstraint("id"), sa.UniqueConstraint("id", name="uq_apikey_id"),
) )
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_index( batch_op.create_index(
@ -106,8 +106,8 @@ def upgrade() -> None:
["user_id"], ["user_id"],
["user.id"], ["user.id"],
), ),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id", name="pk_flow"),
sa.UniqueConstraint("id"), sa.UniqueConstraint("id", name="uq_flow_id"),
) )
# Conditionally create indices for 'flow' table # Conditionally create indices for 'flow' table
# if _alembic_tmp_flow exists, then we need to drop it first # if _alembic_tmp_flow exists, then we need to drop it first

View file

@ -29,7 +29,7 @@ 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') sa.PrimaryKeyConstraint('id', name=op.f('pk_credential')),
) )
except Exception: except Exception:
pass pass

View file

@ -67,8 +67,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'), sa.PrimaryKeyConstraint('id', name=op.f('pk_flowstyle'))
sa.UniqueConstraint('id') sa.UniqueConstraint('id', name=op.f('uq_flowstyle_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 +81,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') sa.PrimaryKeyConstraint('id', name=op.f('pk_component'))
) )
with op.batch_alter_table('component', schema=None) as batch_op: with op.batch_alter_table('component', schema=None) as batch_op:

View file

@ -57,7 +57,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"), sa.PrimaryKeyConstraint("id", name="pk_component"),
) )
with op.batch_alter_table("component", schema=None) as batch_op: with op.batch_alter_table("component", schema=None) as batch_op:
batch_op.create_index("ix_component_name", ["name"], unique=False) batch_op.create_index("ix_component_name", ["name"], unique=False)
@ -78,8 +78,8 @@ def downgrade() -> None:
["flow_id"], ["flow_id"],
["flow.id"], ["flow.id"],
), ),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id", name="pk_flowstyle"),
sa.UniqueConstraint("id"), sa.UniqueConstraint("id", name="uq_flowstyle_id"),
) )
except Exception: except Exception:
pass pass