Initial commit: Setup Bun, Elysia, Vite, React, TanStack Router, Mantine, and Biome
This commit is contained in:
88
prisma/schema.prisma
Normal file
88
prisma/schema.prisma
Normal file
@@ -0,0 +1,88 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = "../generated/prisma"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
name String?
|
||||
emailVerified Boolean?
|
||||
image String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
role String? @default("user")
|
||||
accounts Account[]
|
||||
sessions Session[]
|
||||
apiKeys ApiKey[]
|
||||
|
||||
@@map("user")
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
expiresAt DateTime
|
||||
token String @unique
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
ipAddress String?
|
||||
userAgent String?
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
@@map("session")
|
||||
}
|
||||
|
||||
model Account {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
accountId String
|
||||
providerId String
|
||||
accessToken String?
|
||||
refreshToken String?
|
||||
expiresAt DateTime?
|
||||
password String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
idToken String?
|
||||
accessTokenExpiresAt DateTime?
|
||||
refreshTokenExpiresAt DateTime?
|
||||
scope String?
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
@@map("account")
|
||||
}
|
||||
|
||||
model Verification {
|
||||
id String @id @default(cuid())
|
||||
identifier String
|
||||
value String
|
||||
expiresAt DateTime
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([identifier])
|
||||
@@map("verification")
|
||||
}
|
||||
|
||||
model ApiKey {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
key String @unique
|
||||
userId String
|
||||
isActive Boolean @default(true)
|
||||
expiresAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
@@map("api_key")
|
||||
}
|
||||
49
prisma/seed.ts
Normal file
49
prisma/seed.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { prisma } from "@/utils/db";
|
||||
|
||||
async function seedAdminUser() {
|
||||
// Load environment variables
|
||||
const adminEmail = process.env.ADMIN_EMAIL;
|
||||
|
||||
if (!adminEmail) {
|
||||
console.log("No ADMIN_EMAIL environment variable found. Skipping admin role assignment.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if admin user already exists
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: { email: adminEmail },
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
// Update existing user to have admin role if they don't already
|
||||
if (existingUser.role !== "admin") {
|
||||
await prisma.user.update({
|
||||
where: { email: adminEmail },
|
||||
data: { role: "admin" },
|
||||
});
|
||||
console.log(`User with email ${adminEmail} updated to admin role.`);
|
||||
} else {
|
||||
console.log(`User with email ${adminEmail} already has admin role.`);
|
||||
}
|
||||
} else {
|
||||
console.log(`No user found with email ${adminEmail}. Skipping admin role assignment.`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error seeding admin user:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log("Seeding database...");
|
||||
|
||||
await seedAdminUser();
|
||||
|
||||
console.log("Database seeding completed.");
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error("Error during seeding:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user