Projektstart
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "ExportJob" ADD COLUMN "progress" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "MailboxAccount" ADD COLUMN "oauthLastCheckedAt" TIMESTAMP(3),
|
||||
ADD COLUMN "oauthLastErrorCode" TEXT;
|
||||
@@ -68,6 +68,7 @@ model ExportJob {
|
||||
status ExportStatus @default(QUEUED)
|
||||
format String
|
||||
scope String
|
||||
progress Int @default(0)
|
||||
filePath String?
|
||||
error String?
|
||||
expiresAt DateTime?
|
||||
@@ -109,6 +110,8 @@ model MailboxAccount {
|
||||
oauthAccessToken String?
|
||||
oauthExpiresAt DateTime?
|
||||
providerUserId String?
|
||||
oauthLastCheckedAt DateTime?
|
||||
oauthLastErrorCode String?
|
||||
appPassword String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -4,27 +4,34 @@ import { PrismaClient, UserRole } from "@prisma/client";
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const tenantName = process.env.SEED_TENANT ?? "Default Tenant";
|
||||
const email = process.env.SEED_EMAIL ?? "admin@example.com";
|
||||
const password = process.env.SEED_PASSWORD ?? "change-me-please";
|
||||
const email = process.env.SEED_ADMIN_EMAIL ?? process.env.SEED_EMAIL ?? "admin@example.com";
|
||||
const password = process.env.SEED_ADMIN_PASSWORD ?? process.env.SEED_PASSWORD ?? "change-me-please";
|
||||
const role = (process.env.SEED_ROLE as UserRole | undefined) ?? "ADMIN";
|
||||
|
||||
const main = async () => {
|
||||
const hash = await argon2.hash(password);
|
||||
const tenantId = process.env.SEED_TENANT_ID ?? "seed-tenant";
|
||||
const tenant = await prisma.tenant.upsert({
|
||||
where: { id: tenantId },
|
||||
update: { name: tenantName },
|
||||
create: { id: tenantId, name: tenantName }
|
||||
});
|
||||
|
||||
const existing = await prisma.user.findUnique({ where: { email } });
|
||||
if (existing) {
|
||||
process.stdout.write("Seed user already exists.\n");
|
||||
await prisma.user.update({
|
||||
where: { email },
|
||||
data: { password: hash, role, tenantId: tenant.id }
|
||||
});
|
||||
process.stdout.write("Seed admin updated.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const hash = await argon2.hash(password);
|
||||
const tenant = await prisma.tenant.create({
|
||||
data: { name: tenantName }
|
||||
});
|
||||
|
||||
await prisma.user.create({
|
||||
data: { tenantId: tenant.id, email, password: hash, role }
|
||||
});
|
||||
|
||||
process.stdout.write("Seeded tenant and user.\n");
|
||||
process.stdout.write("Seeded admin user.\n");
|
||||
};
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user