feat(db): add totp_secret, totp_enabled and salt to user table

This commit is contained in:
Nicolas Meienberger 2023-04-05 17:10:27 +02:00 committed by Nicolas Meienberger
parent 98c931ed4c
commit 762ccd1a15
2 changed files with 32 additions and 6 deletions

View File

@ -42,12 +42,15 @@ model Update {
}
model User {
id Int @id(map: "PK_cace4a159ff9f2512dd42373760") @default(autoincrement())
username String @unique(map: "UQ_78a916df40e02a9deb1c4b75edb") @db.VarChar
password String @db.VarChar
createdAt DateTime @default(now()) @db.Timestamp(6)
updatedAt DateTime @default(now()) @db.Timestamp(6)
operator Boolean @default(false)
id Int @id(map: "PK_cace4a159ff9f2512dd42373760") @default(autoincrement())
username String @unique(map: "UQ_78a916df40e02a9deb1c4b75edb") @db.VarChar
password String @db.VarChar
createdAt DateTime @default(now()) @db.Timestamp(6)
updatedAt DateTime @default(now()) @db.Timestamp(6)
operator Boolean @default(false)
totp_secret String?
totp_enabled Boolean @default(false)
salt String?
@@map("user")
}

View File

@ -0,0 +1,23 @@
-- 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;