mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
refac
This commit is contained in:
parent
d19023288e
commit
9f6c91987f
1 changed files with 16 additions and 7 deletions
|
|
@ -82,6 +82,12 @@ def upgrade() -> None:
|
||||||
sa.Column("updated_at", sa.BigInteger()),
|
sa.Column("updated_at", sa.BigInteger()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
file_table = sa.Table(
|
||||||
|
"file",
|
||||||
|
sa.MetaData(),
|
||||||
|
sa.Column("id", sa.Text()),
|
||||||
|
)
|
||||||
|
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
for knowledge_id, user_id, data in results:
|
for knowledge_id, user_id, data in results:
|
||||||
if not data:
|
if not data:
|
||||||
|
|
@ -98,8 +104,15 @@ def upgrade() -> None:
|
||||||
|
|
||||||
file_ids = data.get("file_ids", [])
|
file_ids = data.get("file_ids", [])
|
||||||
|
|
||||||
rows = [
|
for file_id in file_ids:
|
||||||
{
|
file_exists = connection.execute(
|
||||||
|
sa.select(file_table.c.id).where(file_table.c.id == file_id)
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
if not file_exists:
|
||||||
|
continue # skip non-existing files
|
||||||
|
|
||||||
|
row = {
|
||||||
"id": str(uuid.uuid4()),
|
"id": str(uuid.uuid4()),
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"knowledge_id": knowledge_id,
|
"knowledge_id": knowledge_id,
|
||||||
|
|
@ -107,11 +120,7 @@ def upgrade() -> None:
|
||||||
"created_at": now,
|
"created_at": now,
|
||||||
"updated_at": now,
|
"updated_at": now,
|
||||||
}
|
}
|
||||||
for file_id in file_ids
|
connection.execute(kf_table.insert().values(**row))
|
||||||
]
|
|
||||||
|
|
||||||
if rows:
|
|
||||||
connection.execute(kf_table.insert(), rows)
|
|
||||||
|
|
||||||
with op.batch_alter_table("knowledge") as batch:
|
with op.batch_alter_table("knowledge") as batch:
|
||||||
batch.drop_column("data")
|
batch.drop_column("data")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue