mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-23 09:10:55 -05:00
refac
This commit is contained in:
@@ -72,7 +72,6 @@ def _convert_column_to_json(table: str, column: str):
|
||||
dialect = conn.dialect.name
|
||||
|
||||
t = sa.table(table, sa.column('id', sa.Text), sa.column(column, sa.Text))
|
||||
t_json = sa.column(f'{column}_json', sa.JSON)
|
||||
|
||||
# SQLite cannot ALTER COLUMN → must recreate column
|
||||
if dialect == 'sqlite':
|
||||
@@ -90,9 +89,11 @@ def _convert_column_to_json(table: str, column: str):
|
||||
parsed = None
|
||||
|
||||
conn.execute(
|
||||
sa.update(sa.table(table, sa.column('id'), t_json))
|
||||
sa.update(
|
||||
sa.table(table, sa.column('id'), sa.column(f'{column}_json', sa.JSON))
|
||||
)
|
||||
.where(sa.column('id') == uid)
|
||||
.values({f'{column}_json': json.dumps(parsed) if parsed else None})
|
||||
.values({f'{column}_json': parsed})
|
||||
)
|
||||
|
||||
op.drop_column(table, column)
|
||||
@@ -112,8 +113,7 @@ def _convert_column_to_text(table: str, column: str):
|
||||
conn = op.get_bind()
|
||||
dialect = conn.dialect.name
|
||||
|
||||
t = sa.table(table, sa.column('id', sa.Text), sa.column(column))
|
||||
t_text = sa.column(f'{column}_text', sa.Text)
|
||||
t = sa.table(table, sa.column('id', sa.Text), sa.column(column, sa.JSON))
|
||||
|
||||
if dialect == 'sqlite':
|
||||
op.add_column(table, sa.Column(f'{column}_text', sa.Text(), nullable=True))
|
||||
@@ -122,9 +122,11 @@ def _convert_column_to_text(table: str, column: str):
|
||||
|
||||
for uid, raw in rows:
|
||||
conn.execute(
|
||||
sa.update(sa.table(table, sa.column('id'), t_text))
|
||||
sa.update(
|
||||
sa.table(table, sa.column('id'), sa.column(f'{column}_text', sa.Text))
|
||||
)
|
||||
.where(sa.column('id') == uid)
|
||||
.values({f'{column}_text': json.dumps(raw) if raw else None})
|
||||
.values({f'{column}_text': json.dumps(raw) if raw is not None else None})
|
||||
)
|
||||
|
||||
op.drop_column(table, column)
|
||||
|
||||
Reference in New Issue
Block a user