upd: auth
Deskripsi: -update login - update struktur database No Issues
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The values [USER,SUPER_ADMIN] on the enum `Role` will be removed. If these variants are still used in the database, this will fail.
|
||||
- You are about to drop the column `app` on the `bug` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterEnum
|
||||
BEGIN;
|
||||
CREATE TYPE "Role_new" AS ENUM ('ADMIN', 'DEVELOPER');
|
||||
ALTER TABLE "public"."user" ALTER COLUMN "role" DROP DEFAULT;
|
||||
ALTER TABLE "user" ALTER COLUMN "role" TYPE "Role_new" USING ("role"::text::"Role_new");
|
||||
ALTER TYPE "Role" RENAME TO "Role_old";
|
||||
ALTER TYPE "Role_new" RENAME TO "Role";
|
||||
DROP TYPE "public"."Role_old";
|
||||
ALTER TABLE "user" ALTER COLUMN "role" SET DEFAULT 'ADMIN';
|
||||
COMMIT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "bug" DROP COLUMN "app",
|
||||
ADD COLUMN "appId" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "user" ALTER COLUMN "role" SET DEFAULT 'ADMIN';
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "App" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"version" TEXT NOT NULL,
|
||||
"minVersion" TEXT NOT NULL,
|
||||
"maintenance" BOOLEAN NOT NULL DEFAULT false,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "App_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "bug" ADD CONSTRAINT "bug_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "App" ALTER COLUMN "version" DROP NOT NULL,
|
||||
ALTER COLUMN "minVersion" DROP NOT NULL;
|
||||
@@ -9,9 +9,7 @@ datasource db {
|
||||
}
|
||||
|
||||
enum Role {
|
||||
USER
|
||||
ADMIN
|
||||
SUPER_ADMIN
|
||||
DEVELOPER
|
||||
}
|
||||
|
||||
@@ -44,7 +42,7 @@ model User {
|
||||
name String
|
||||
email String @unique
|
||||
password String
|
||||
role Role @default(USER)
|
||||
role Role @default(ADMIN)
|
||||
active Boolean @default(true)
|
||||
image String?
|
||||
createdAt DateTime @default(now())
|
||||
@@ -71,6 +69,19 @@ model Session {
|
||||
@@map("session")
|
||||
}
|
||||
|
||||
model App {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
version String?
|
||||
minVersion String?
|
||||
maintenance Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
bugs Bug[]
|
||||
|
||||
}
|
||||
|
||||
model Log {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
@@ -86,12 +97,12 @@ model Log {
|
||||
model Bug {
|
||||
id String @id @default(uuid())
|
||||
userId String?
|
||||
app String?
|
||||
appId String?
|
||||
affectedVersion String
|
||||
device String
|
||||
os String
|
||||
status BugStatus
|
||||
source BugSource
|
||||
source BugSource
|
||||
description String
|
||||
stackTrace String?
|
||||
fixedVersion String?
|
||||
@@ -100,6 +111,7 @@ model Bug {
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
app App? @relation(fields: [appId], references: [id])
|
||||
|
||||
images BugImage[]
|
||||
logs BugLog[]
|
||||
|
||||
@@ -6,9 +6,7 @@ const SUPER_ADMIN_EMAILS = (process.env.SUPER_ADMIN_EMAIL ?? '').split(',').map(
|
||||
|
||||
async function main() {
|
||||
const users = [
|
||||
{ name: 'Super Admin', email: 'superadmin@example.com', password: 'superadmin123', role: 'SUPER_ADMIN' as const },
|
||||
{ name: 'Admin', email: 'admin@example.com', password: 'admin123', role: 'ADMIN' as const },
|
||||
{ name: 'User', email: 'user@example.com', password: 'user123', role: 'USER' as const },
|
||||
]
|
||||
|
||||
for (const u of users) {
|
||||
@@ -21,13 +19,28 @@ async function main() {
|
||||
console.log(`Seeded: ${u.email} (${u.role})`)
|
||||
}
|
||||
|
||||
// Promote super admin emails from env
|
||||
// Promote DEVELOPER emails from env
|
||||
for (const email of SUPER_ADMIN_EMAILS) {
|
||||
const user = await prisma.user.findUnique({ where: { email } })
|
||||
if (user && user.role !== 'SUPER_ADMIN') {
|
||||
await prisma.user.update({ where: { email }, data: { role: 'SUPER_ADMIN' } })
|
||||
console.log(`Promoted to SUPER_ADMIN: ${email}`)
|
||||
}
|
||||
const password = await Bun.password.hash('developer123', { algorithm: 'bcrypt' })
|
||||
await prisma.user.upsert({
|
||||
where: { email },
|
||||
update: { role: 'DEVELOPER', password },
|
||||
create: { name: email.split('@')[0].toUpperCase(), email, password, role: 'DEVELOPER' },
|
||||
})
|
||||
console.log(`Promoted to DEVELOPER: ${email}`)
|
||||
}
|
||||
|
||||
const apps = [
|
||||
{ id: 'desa-plus', name: 'Desa+' },
|
||||
]
|
||||
|
||||
for (const a of apps) {
|
||||
await prisma.app.upsert({
|
||||
where: { id: a.id },
|
||||
update: { name: a.name },
|
||||
create: { id: a.id, name: a.name },
|
||||
})
|
||||
console.log(`Seeded: ${a.name}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user