🐛 fix(adds_tables.py): create "user" and "apikey" tables only if they don't exist to prevent duplicate table creation
✨ feat(adds_tables.py): add unique index on "username" column in "user" table for faster username lookups ✨ feat(adds_tables.py): add unique index on "api_key" column in "apikey" table for faster API key lookups ✨ feat(adds_tables.py): add index on "name" column in "apikey" table for faster name lookups ✨ feat(adds_tables.py): add index on "user_id" column in "apikey" table for faster user ID lookups
This commit is contained in:
parent
cb6fafb723
commit
2d22737c31
1 changed files with 44 additions and 38 deletions
|
|
@ -39,6 +39,7 @@ def upgrade() -> None:
|
|||
for fk in inspector.get_foreign_keys("flow")
|
||||
]
|
||||
|
||||
if "user" not in existing_tables:
|
||||
op.create_table(
|
||||
"user",
|
||||
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
|
||||
|
|
@ -53,8 +54,11 @@ def upgrade() -> None:
|
|||
sa.UniqueConstraint("id"),
|
||||
)
|
||||
with op.batch_alter_table("user", schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f("ix_user_username"), ["username"], unique=True)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_user_username"), ["username"], unique=True
|
||||
)
|
||||
|
||||
if "apikey" not in existing_tables:
|
||||
op.create_table(
|
||||
"apikey",
|
||||
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
|
||||
|
|
@ -73,7 +77,9 @@ def upgrade() -> None:
|
|||
sa.UniqueConstraint("id"),
|
||||
)
|
||||
with op.batch_alter_table("apikey", schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f("ix_apikey_api_key"), ["api_key"], unique=True)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_apikey_api_key"), ["api_key"], unique=True
|
||||
)
|
||||
batch_op.create_index(batch_op.f("ix_apikey_name"), ["name"], unique=False)
|
||||
batch_op.create_index(
|
||||
batch_op.f("ix_apikey_user_id"), ["user_id"], unique=False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue