mirror of
https://github.com/open-webui/open-webui
synced 2025-04-26 01:00:20 +00:00
fix: tag migration
This commit is contained in:
parent
86bc3023b3
commit
f0179270e2
@ -28,25 +28,39 @@ def upgrade():
|
|||||||
unique_constraints = inspector.get_unique_constraints("tag")
|
unique_constraints = inspector.get_unique_constraints("tag")
|
||||||
existing_indexes = inspector.get_indexes("tag")
|
existing_indexes = inspector.get_indexes("tag")
|
||||||
|
|
||||||
print(existing_pk, unique_constraints)
|
print(f"Primary Key: {existing_pk}")
|
||||||
|
print(f"Unique Constraints: {unique_constraints}")
|
||||||
|
print(f"Indexes: {existing_indexes}")
|
||||||
|
|
||||||
with op.batch_alter_table("tag", schema=None) as batch_op:
|
with op.batch_alter_table("tag", schema=None) as batch_op:
|
||||||
# Drop unique constraints that could conflict with new primary key
|
# Drop existing primary key constraint if it exists
|
||||||
|
if existing_pk and existing_pk.get("constrained_columns"):
|
||||||
|
pk_name = existing_pk.get("name")
|
||||||
|
if pk_name:
|
||||||
|
print(f"Dropping primary key constraint: {pk_name}")
|
||||||
|
batch_op.drop_constraint(pk_name, type_="primary")
|
||||||
|
|
||||||
|
# Now create the new primary key with the combination of 'id' and 'user_id'
|
||||||
|
print("Creating new primary key with 'id' and 'user_id'.")
|
||||||
|
batch_op.create_primary_key("pk_id_user_id", ["id", "user_id"])
|
||||||
|
|
||||||
|
# Drop unique constraints that could conflict with the new primary key
|
||||||
for constraint in unique_constraints:
|
for constraint in unique_constraints:
|
||||||
if constraint["name"] == "uq_id_user_id":
|
if (
|
||||||
|
constraint["name"] == "uq_id_user_id"
|
||||||
|
): # Adjust this name according to what is actually returned by the inspector
|
||||||
|
print(f"Dropping unique constraint: {constraint['name']}")
|
||||||
batch_op.drop_constraint(constraint["name"], type_="unique")
|
batch_op.drop_constraint(constraint["name"], type_="unique")
|
||||||
|
|
||||||
for index in existing_indexes:
|
for index in existing_indexes:
|
||||||
if index["unique"]:
|
if index["unique"]:
|
||||||
# Drop the unique index
|
if not any(
|
||||||
batch_op.drop_index(index["name"])
|
constraint["name"] == index["name"]
|
||||||
|
for constraint in unique_constraints
|
||||||
# Drop existing primary key constraint if it exists
|
):
|
||||||
if existing_pk and existing_pk.get("constrained_columns"):
|
# You are attempting to drop unique indexes
|
||||||
batch_op.drop_constraint(existing_pk["name"], type_="primary")
|
print(f"Dropping unique index: {index['name']}")
|
||||||
|
batch_op.drop_index(index["name"])
|
||||||
# Immediately after dropping the old primary key, create the new one
|
|
||||||
batch_op.create_primary_key("pk_id_user_id", ["id", "user_id"])
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
Loading…
Reference in New Issue
Block a user