runtipi/packages/worker/assets/migrations/00006-add-totp-user-fields.sql
2023-11-16 20:49:27 +01:00

23 lines
616 B
SQL

-- Create totp_secret field if it doesn't exist
ALTER TABLE "user"
ADD COLUMN IF NOT EXISTS "totp_secret" text DEFAULT NULL;
-- Create totp_enabled field if it doesn't exist
ALTER TABLE "user"
ADD COLUMN IF NOT EXISTS "totp_enabled" boolean DEFAULT FALSE;
-- Add salt field to user table
ALTER TABLE "user"
ADD COLUMN IF NOT EXISTS "salt" text DEFAULT NULL;
-- Set all users to have totp enabled false
UPDATE
"user"
SET
"totp_enabled" = FALSE
WHERE
"totp_enabled" IS NULL;
-- Set totp_enabled column to not null constraint
ALTER TABLE "user"
ALTER COLUMN "totp_enabled" SET NOT NULL;