harden migration (#2476)

* harden migration

* remove duplicate line
This commit is contained in:
rkuo-danswer 2024-09-17 09:44:53 -07:00 committed by GitHub
parent 5b18409c89
commit 5596a68d08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,6 +19,19 @@ DEFAULT_ASSISTANTS = [-2, -1, 0]
def upgrade() -> None:
# Step 1: Update any NULL values to the default value
op.execute(
f"""
UPDATE "user"
SET chosen_assistants = '{DEFAULT_ASSISTANTS}'
WHERE chosen_assistants IS NULL
OR chosen_assistants = 'null'
OR jsonb_typeof(chosen_assistants) = 'null'
OR (jsonb_typeof(chosen_assistants) = 'string' AND chosen_assistants = '"null"')
"""
)
# Step 2: Alter the column to make it non-nullable
op.alter_column(
"user",
"chosen_assistants",