feat(db): create migration to add operator field on user

This commit is contained in:
Nicolas Meienberger 2023-02-21 22:55:58 +01:00
parent 9c340faecb
commit 51c2dfa816
4 changed files with 26 additions and 5 deletions

View file

@ -3,7 +3,7 @@
"version": "0.8.1",
"description": "A homeserver for everyone",
"scripts": {
"copy:migrations": "mkdir -p dist/migrations && cp -r ./src/server/migrations dist/migrations",
"copy:migrations": "mkdir -p dist/migrations && cp -r ./src/server/migrations dist",
"prisma:pull": "prisma db pull",
"test": "dotenv -e .env.test -- jest --colors",
"test:client": "jest --colors --selectProjects client --",

View file

@ -23,9 +23,10 @@ model App {
}
model Migrations {
id Int @id(map: "PK_8c82d7f526340ab734260ea46be") @default(autoincrement())
timestamp BigInt
name String @db.VarChar
id Int @id
name String @unique @db.VarChar(100)
hash String @db.VarChar(40)
executed_at DateTime? @default(now()) @db.Timestamp(6)
@@map("migrations")
}
@ -46,6 +47,7 @@ model User {
password String @db.VarChar
createdAt DateTime @default(now()) @db.Timestamp(6)
updatedAt DateTime @default(now()) @db.Timestamp(6)
operator Boolean @default(false)
@@map("user")
}

View file

@ -8,7 +8,8 @@ UPDATE
SET
"version" = '1'
WHERE
"version" IS NULL;
"version" IS NULL
OR "version" = '0';
-- Set version field to not null
ALTER TABLE "app"

View file

@ -0,0 +1,18 @@
-- Create operator field if it doesn't exist
ALTER TABLE "user"
ADD COLUMN IF NOT EXISTS "operator" boolean DEFAULT NULL;
UPDATE
"user"
SET
"operator" = TRUE
WHERE
"operator" IS NULL;
-- Set operator column to default false
ALTER TABLE "user"
ALTER COLUMN "operator" SET DEFAULT FALSE;
-- Set operator column to not null constraint
ALTER TABLE "user"
ALTER COLUMN "operator" SET NOT NULL;