@techstream/quark-create-app 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/package.json +34 -0
- package/src/index.js +611 -0
- package/templates/base-project/README.md +35 -0
- package/templates/base-project/apps/web/next.config.js +6 -0
- package/templates/base-project/apps/web/package.json +32 -0
- package/templates/base-project/apps/web/postcss.config.mjs +7 -0
- package/templates/base-project/apps/web/public/file.svg +1 -0
- package/templates/base-project/apps/web/public/globe.svg +1 -0
- package/templates/base-project/apps/web/public/next.svg +1 -0
- package/templates/base-project/apps/web/public/vercel.svg +1 -0
- package/templates/base-project/apps/web/public/window.svg +1 -0
- package/templates/base-project/apps/web/src/app/api/auth/[...nextauth]/route.js +4 -0
- package/templates/base-project/apps/web/src/app/api/auth/register/route.js +39 -0
- package/templates/base-project/apps/web/src/app/api/csrf/route.js +42 -0
- package/templates/base-project/apps/web/src/app/api/error-handler.js +21 -0
- package/templates/base-project/apps/web/src/app/api/health/route.js +78 -0
- package/templates/base-project/apps/web/src/app/api/posts/[id]/route.js +61 -0
- package/templates/base-project/apps/web/src/app/api/posts/route.js +34 -0
- package/templates/base-project/apps/web/src/app/api/users/[id]/route.js +54 -0
- package/templates/base-project/apps/web/src/app/api/users/route.js +36 -0
- package/templates/base-project/apps/web/src/app/favicon.ico +0 -0
- package/templates/base-project/apps/web/src/app/globals.css +26 -0
- package/templates/base-project/apps/web/src/app/layout.js +12 -0
- package/templates/base-project/apps/web/src/app/page.js +10 -0
- package/templates/base-project/apps/web/src/app/page.test.js +11 -0
- package/templates/base-project/apps/web/src/lib/auth-middleware.js +14 -0
- package/templates/base-project/apps/web/src/lib/auth.js +102 -0
- package/templates/base-project/apps/web/src/middleware.js +265 -0
- package/templates/base-project/apps/worker/package.json +28 -0
- package/templates/base-project/apps/worker/src/index.js +154 -0
- package/templates/base-project/apps/worker/src/index.test.js +19 -0
- package/templates/base-project/docker-compose.yml +40 -0
- package/templates/base-project/package.json +26 -0
- package/templates/base-project/packages/db/package.json +29 -0
- package/templates/base-project/packages/db/prisma/migrations/20260202061128_initial/migration.sql +176 -0
- package/templates/base-project/packages/db/prisma/migrations/migration_lock.toml +3 -0
- package/templates/base-project/packages/db/prisma/schema.prisma +147 -0
- package/templates/base-project/packages/db/prisma.config.ts +25 -0
- package/templates/base-project/packages/db/scripts/seed.js +47 -0
- package/templates/base-project/packages/db/src/client.js +52 -0
- package/templates/base-project/packages/db/src/generated/prisma/browser.ts +53 -0
- package/templates/base-project/packages/db/src/generated/prisma/client.ts +82 -0
- package/templates/base-project/packages/db/src/generated/prisma/commonInputTypes.ts +649 -0
- package/templates/base-project/packages/db/src/generated/prisma/enums.ts +19 -0
- package/templates/base-project/packages/db/src/generated/prisma/internal/class.ts +305 -0
- package/templates/base-project/packages/db/src/generated/prisma/internal/prismaNamespace.ts +1428 -0
- package/templates/base-project/packages/db/src/generated/prisma/internal/prismaNamespaceBrowser.ts +217 -0
- package/templates/base-project/packages/db/src/generated/prisma/models/Account.ts +2098 -0
- package/templates/base-project/packages/db/src/generated/prisma/models/AuditLog.ts +1805 -0
- package/templates/base-project/packages/db/src/generated/prisma/models/Job.ts +1737 -0
- package/templates/base-project/packages/db/src/generated/prisma/models/Post.ts +1762 -0
- package/templates/base-project/packages/db/src/generated/prisma/models/Session.ts +1738 -0
- package/templates/base-project/packages/db/src/generated/prisma/models/User.ts +2298 -0
- package/templates/base-project/packages/db/src/generated/prisma/models/VerificationToken.ts +1450 -0
- package/templates/base-project/packages/db/src/generated/prisma/models.ts +18 -0
- package/templates/base-project/packages/db/src/index.js +3 -0
- package/templates/base-project/packages/db/src/queries.js +267 -0
- package/templates/base-project/packages/db/src/queries.test.js +79 -0
- package/templates/base-project/packages/db/src/schemas.js +31 -0
- package/templates/base-project/pnpm-workspace.yaml +7 -0
- package/templates/base-project/turbo.json +25 -0
- package/templates/config/package.json +8 -0
- package/templates/config/src/index.js +21 -0
- package/templates/jobs/package.json +8 -0
- package/templates/jobs/src/definitions.js +9 -0
- package/templates/jobs/src/handlers.js +20 -0
- package/templates/jobs/src/index.js +2 -0
- package/templates/ui/package.json +11 -0
- package/templates/ui/src/button.js +19 -0
- package/templates/ui/src/card.js +14 -0
- package/templates/ui/src/index.js +3 -0
- package/templates/ui/src/input.js +11 -0
package/templates/base-project/packages/db/prisma/migrations/20260202061128_initial/migration.sql
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "JobStatus" AS ENUM ('PENDING', 'IN_PROGRESS', 'COMPLETED', 'FAILED', 'CANCELLED');
|
|
3
|
+
|
|
4
|
+
-- CreateTable
|
|
5
|
+
CREATE TABLE "User" (
|
|
6
|
+
"id" TEXT NOT NULL,
|
|
7
|
+
"email" TEXT NOT NULL,
|
|
8
|
+
"emailVerified" TIMESTAMP(3),
|
|
9
|
+
"name" TEXT,
|
|
10
|
+
"password" TEXT,
|
|
11
|
+
"image" TEXT,
|
|
12
|
+
"role" TEXT NOT NULL DEFAULT 'viewer',
|
|
13
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
14
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
15
|
+
|
|
16
|
+
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
-- CreateTable
|
|
20
|
+
CREATE TABLE "Post" (
|
|
21
|
+
"id" TEXT NOT NULL,
|
|
22
|
+
"title" TEXT NOT NULL,
|
|
23
|
+
"content" TEXT,
|
|
24
|
+
"published" BOOLEAN NOT NULL DEFAULT false,
|
|
25
|
+
"authorId" TEXT NOT NULL,
|
|
26
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
27
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
28
|
+
|
|
29
|
+
CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
-- CreateTable
|
|
33
|
+
CREATE TABLE "Account" (
|
|
34
|
+
"id" TEXT NOT NULL,
|
|
35
|
+
"userId" TEXT NOT NULL,
|
|
36
|
+
"type" TEXT NOT NULL,
|
|
37
|
+
"provider" TEXT NOT NULL,
|
|
38
|
+
"providerAccountId" TEXT NOT NULL,
|
|
39
|
+
"refresh_token" TEXT,
|
|
40
|
+
"access_token" TEXT,
|
|
41
|
+
"expires_at" INTEGER,
|
|
42
|
+
"token_type" TEXT,
|
|
43
|
+
"scope" TEXT,
|
|
44
|
+
"id_token" TEXT,
|
|
45
|
+
"session_state" TEXT,
|
|
46
|
+
|
|
47
|
+
CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
-- CreateTable
|
|
51
|
+
CREATE TABLE "Session" (
|
|
52
|
+
"id" TEXT NOT NULL,
|
|
53
|
+
"sessionToken" TEXT NOT NULL,
|
|
54
|
+
"userId" TEXT NOT NULL,
|
|
55
|
+
"expires" TIMESTAMP(3) NOT NULL,
|
|
56
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
57
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
58
|
+
|
|
59
|
+
CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
-- CreateTable
|
|
63
|
+
CREATE TABLE "VerificationToken" (
|
|
64
|
+
"identifier" TEXT NOT NULL,
|
|
65
|
+
"token" TEXT NOT NULL,
|
|
66
|
+
"expires" TIMESTAMP(3) NOT NULL,
|
|
67
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
-- CreateTable
|
|
71
|
+
CREATE TABLE "Job" (
|
|
72
|
+
"id" TEXT NOT NULL,
|
|
73
|
+
"queue" TEXT NOT NULL,
|
|
74
|
+
"name" TEXT NOT NULL,
|
|
75
|
+
"data" JSONB,
|
|
76
|
+
"status" "JobStatus" NOT NULL DEFAULT 'PENDING',
|
|
77
|
+
"error" TEXT,
|
|
78
|
+
"attempts" INTEGER NOT NULL DEFAULT 0,
|
|
79
|
+
"maxRetries" INTEGER NOT NULL DEFAULT 3,
|
|
80
|
+
"runAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
81
|
+
"startedAt" TIMESTAMP(3),
|
|
82
|
+
"completedAt" TIMESTAMP(3),
|
|
83
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
84
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
85
|
+
|
|
86
|
+
CONSTRAINT "Job_pkey" PRIMARY KEY ("id")
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
-- CreateTable
|
|
90
|
+
CREATE TABLE "AuditLog" (
|
|
91
|
+
"id" TEXT NOT NULL,
|
|
92
|
+
"userId" TEXT NOT NULL,
|
|
93
|
+
"action" TEXT NOT NULL,
|
|
94
|
+
"entity" TEXT NOT NULL,
|
|
95
|
+
"entityId" TEXT NOT NULL,
|
|
96
|
+
"changes" JSONB,
|
|
97
|
+
"metadata" JSONB,
|
|
98
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
99
|
+
|
|
100
|
+
CONSTRAINT "AuditLog_pkey" PRIMARY KEY ("id")
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
-- CreateIndex
|
|
104
|
+
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
|
105
|
+
|
|
106
|
+
-- CreateIndex
|
|
107
|
+
CREATE INDEX "User_email_idx" ON "User"("email");
|
|
108
|
+
|
|
109
|
+
-- CreateIndex
|
|
110
|
+
CREATE INDEX "User_createdAt_idx" ON "User"("createdAt");
|
|
111
|
+
|
|
112
|
+
-- CreateIndex
|
|
113
|
+
CREATE INDEX "Post_authorId_idx" ON "Post"("authorId");
|
|
114
|
+
|
|
115
|
+
-- CreateIndex
|
|
116
|
+
CREATE INDEX "Post_published_idx" ON "Post"("published");
|
|
117
|
+
|
|
118
|
+
-- CreateIndex
|
|
119
|
+
CREATE INDEX "Post_createdAt_idx" ON "Post"("createdAt");
|
|
120
|
+
|
|
121
|
+
-- CreateIndex
|
|
122
|
+
CREATE INDEX "Account_userId_idx" ON "Account"("userId");
|
|
123
|
+
|
|
124
|
+
-- CreateIndex
|
|
125
|
+
CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId");
|
|
126
|
+
|
|
127
|
+
-- CreateIndex
|
|
128
|
+
CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken");
|
|
129
|
+
|
|
130
|
+
-- CreateIndex
|
|
131
|
+
CREATE INDEX "Session_userId_idx" ON "Session"("userId");
|
|
132
|
+
|
|
133
|
+
-- CreateIndex
|
|
134
|
+
CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token");
|
|
135
|
+
|
|
136
|
+
-- CreateIndex
|
|
137
|
+
CREATE INDEX "VerificationToken_token_idx" ON "VerificationToken"("token");
|
|
138
|
+
|
|
139
|
+
-- CreateIndex
|
|
140
|
+
CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token");
|
|
141
|
+
|
|
142
|
+
-- CreateIndex
|
|
143
|
+
CREATE INDEX "Job_queue_idx" ON "Job"("queue");
|
|
144
|
+
|
|
145
|
+
-- CreateIndex
|
|
146
|
+
CREATE INDEX "Job_status_idx" ON "Job"("status");
|
|
147
|
+
|
|
148
|
+
-- CreateIndex
|
|
149
|
+
CREATE INDEX "Job_runAt_idx" ON "Job"("runAt");
|
|
150
|
+
|
|
151
|
+
-- CreateIndex
|
|
152
|
+
CREATE INDEX "Job_createdAt_idx" ON "Job"("createdAt");
|
|
153
|
+
|
|
154
|
+
-- CreateIndex
|
|
155
|
+
CREATE INDEX "AuditLog_userId_idx" ON "AuditLog"("userId");
|
|
156
|
+
|
|
157
|
+
-- CreateIndex
|
|
158
|
+
CREATE INDEX "AuditLog_action_idx" ON "AuditLog"("action");
|
|
159
|
+
|
|
160
|
+
-- CreateIndex
|
|
161
|
+
CREATE INDEX "AuditLog_entity_idx" ON "AuditLog"("entity");
|
|
162
|
+
|
|
163
|
+
-- CreateIndex
|
|
164
|
+
CREATE INDEX "AuditLog_createdAt_idx" ON "AuditLog"("createdAt");
|
|
165
|
+
|
|
166
|
+
-- AddForeignKey
|
|
167
|
+
ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
168
|
+
|
|
169
|
+
-- AddForeignKey
|
|
170
|
+
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
171
|
+
|
|
172
|
+
-- AddForeignKey
|
|
173
|
+
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
174
|
+
|
|
175
|
+
-- AddForeignKey
|
|
176
|
+
ALTER TABLE "AuditLog" ADD CONSTRAINT "AuditLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// This is your Prisma schema file,
|
|
2
|
+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
3
|
+
|
|
4
|
+
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
|
5
|
+
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
|
6
|
+
|
|
7
|
+
generator client {
|
|
8
|
+
provider = "prisma-client"
|
|
9
|
+
output = "../src/generated/prisma"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
datasource db {
|
|
13
|
+
provider = "postgresql"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
model User {
|
|
17
|
+
id String @id @default(cuid())
|
|
18
|
+
email String @unique
|
|
19
|
+
emailVerified DateTime?
|
|
20
|
+
name String?
|
|
21
|
+
password String?
|
|
22
|
+
image String?
|
|
23
|
+
role String @default("viewer")
|
|
24
|
+
createdAt DateTime @default(now())
|
|
25
|
+
updatedAt DateTime @updatedAt
|
|
26
|
+
|
|
27
|
+
posts Post[]
|
|
28
|
+
accounts Account[]
|
|
29
|
+
sessions Session[]
|
|
30
|
+
auditLogs AuditLog[]
|
|
31
|
+
|
|
32
|
+
@@index([email])
|
|
33
|
+
@@index([createdAt])
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
model Post {
|
|
37
|
+
id String @id @default(cuid())
|
|
38
|
+
title String
|
|
39
|
+
content String? @db.Text
|
|
40
|
+
published Boolean @default(false)
|
|
41
|
+
authorId String
|
|
42
|
+
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
|
|
43
|
+
createdAt DateTime @default(now())
|
|
44
|
+
updatedAt DateTime @updatedAt
|
|
45
|
+
|
|
46
|
+
@@index([authorId])
|
|
47
|
+
@@index([published])
|
|
48
|
+
@@index([createdAt])
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// NextAuth Models
|
|
52
|
+
model Account {
|
|
53
|
+
id String @id @default(cuid())
|
|
54
|
+
userId String
|
|
55
|
+
type String
|
|
56
|
+
provider String
|
|
57
|
+
providerAccountId String
|
|
58
|
+
refresh_token String? @db.Text
|
|
59
|
+
access_token String? @db.Text
|
|
60
|
+
expires_at Int?
|
|
61
|
+
token_type String?
|
|
62
|
+
scope String?
|
|
63
|
+
id_token String? @db.Text
|
|
64
|
+
session_state String?
|
|
65
|
+
createdAt DateTime @default(now())
|
|
66
|
+
updatedAt DateTime @updatedAt
|
|
67
|
+
|
|
68
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
69
|
+
|
|
70
|
+
@@unique([provider, providerAccountId])
|
|
71
|
+
@@index([userId])
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
model Session {
|
|
75
|
+
id String @id @default(cuid())
|
|
76
|
+
sessionToken String @unique
|
|
77
|
+
userId String
|
|
78
|
+
expires DateTime
|
|
79
|
+
createdAt DateTime @default(now())
|
|
80
|
+
updatedAt DateTime @updatedAt
|
|
81
|
+
|
|
82
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
83
|
+
|
|
84
|
+
@@index([userId])
|
|
85
|
+
@@index([expires])
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
model VerificationToken {
|
|
89
|
+
identifier String
|
|
90
|
+
token String @unique
|
|
91
|
+
expires DateTime
|
|
92
|
+
createdAt DateTime @default(now())
|
|
93
|
+
|
|
94
|
+
@@unique([identifier, token])
|
|
95
|
+
@@index([token])
|
|
96
|
+
@@index([expires])
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Job Queue Model
|
|
100
|
+
model Job {
|
|
101
|
+
id String @id @default(cuid())
|
|
102
|
+
queue String
|
|
103
|
+
name String
|
|
104
|
+
data Json?
|
|
105
|
+
status JobStatus @default(PENDING)
|
|
106
|
+
error String?
|
|
107
|
+
attempts Int @default(0)
|
|
108
|
+
maxRetries Int @default(3)
|
|
109
|
+
runAt DateTime @default(now())
|
|
110
|
+
startedAt DateTime?
|
|
111
|
+
completedAt DateTime?
|
|
112
|
+
createdAt DateTime @default(now())
|
|
113
|
+
updatedAt DateTime @updatedAt
|
|
114
|
+
|
|
115
|
+
@@index([queue])
|
|
116
|
+
@@index([status])
|
|
117
|
+
@@index([runAt])
|
|
118
|
+
@@index([status, runAt])
|
|
119
|
+
@@index([createdAt])
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
enum JobStatus {
|
|
123
|
+
PENDING
|
|
124
|
+
IN_PROGRESS
|
|
125
|
+
COMPLETED
|
|
126
|
+
FAILED
|
|
127
|
+
CANCELLED
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Audit Log Model
|
|
131
|
+
model AuditLog {
|
|
132
|
+
id String @id @default(cuid())
|
|
133
|
+
userId String
|
|
134
|
+
action String
|
|
135
|
+
entity String
|
|
136
|
+
entityId String
|
|
137
|
+
changes Json?
|
|
138
|
+
metadata Json?
|
|
139
|
+
createdAt DateTime @default(now())
|
|
140
|
+
|
|
141
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
142
|
+
|
|
143
|
+
@@index([userId])
|
|
144
|
+
@@index([action])
|
|
145
|
+
@@index([entity])
|
|
146
|
+
@@index([createdAt])
|
|
147
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { config } from "dotenv";
|
|
3
|
+
import { defineConfig } from "prisma/config";
|
|
4
|
+
|
|
5
|
+
// Load .env from monorepo root
|
|
6
|
+
config({ path: resolve(__dirname, "../../.env") });
|
|
7
|
+
|
|
8
|
+
// Construct DATABASE_URL from individual env vars - single source of truth
|
|
9
|
+
const user = process.env.POSTGRES_USER || "quark_user";
|
|
10
|
+
const password = process.env.POSTGRES_PASSWORD || "quark_password";
|
|
11
|
+
const host = process.env.POSTGRES_HOST || "localhost";
|
|
12
|
+
const port = process.env.POSTGRES_PORT || "5432";
|
|
13
|
+
const db = process.env.POSTGRES_DB || "quark_dev";
|
|
14
|
+
|
|
15
|
+
const databaseUrl = `postgresql://${user}:${password}@${host}:${port}/${db}?schema=public`;
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
schema: "prisma/schema.prisma",
|
|
19
|
+
migrations: {
|
|
20
|
+
path: "prisma/migrations",
|
|
21
|
+
},
|
|
22
|
+
datasource: {
|
|
23
|
+
url: databaseUrl,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PrismaClient } from "../src/generated/prisma/client.js";
|
|
2
|
+
import bcrypt from "bcryptjs";
|
|
3
|
+
|
|
4
|
+
const prisma = new PrismaClient();
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
console.log("Seeding database...");
|
|
8
|
+
|
|
9
|
+
const email = "test@example.com";
|
|
10
|
+
const password = await bcrypt.hash("Password1", 12);
|
|
11
|
+
|
|
12
|
+
const user = await prisma.user.upsert({
|
|
13
|
+
where: { email },
|
|
14
|
+
update: {},
|
|
15
|
+
create: {
|
|
16
|
+
email,
|
|
17
|
+
name: "Test User",
|
|
18
|
+
password,
|
|
19
|
+
image: "https://api.dicebear.com/7.x/avataaars/svg?seed=test",
|
|
20
|
+
posts: {
|
|
21
|
+
create: [
|
|
22
|
+
{
|
|
23
|
+
title: "Hello World",
|
|
24
|
+
content: "This is a seeded post. Welcome to Quark!",
|
|
25
|
+
published: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: "Draft Post",
|
|
29
|
+
content: "This is a draft post. It is not published yet.",
|
|
30
|
+
published: false,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.log("Seeded user:", user.email);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
main()
|
|
41
|
+
.catch((e) => {
|
|
42
|
+
console.error(e);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
})
|
|
45
|
+
.finally(async () => {
|
|
46
|
+
await prisma.$disconnect();
|
|
47
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PrismaPg } from "@prisma/adapter-pg";
|
|
2
|
+
import { PrismaClient } from "./generated/prisma/client.ts";
|
|
3
|
+
|
|
4
|
+
// Construct DATABASE_URL from individual env vars (mirrors prisma.config.ts)
|
|
5
|
+
// POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB are required — no silent fallbacks.
|
|
6
|
+
const user = process.env.POSTGRES_USER;
|
|
7
|
+
if (!user) throw new Error("POSTGRES_USER environment variable is required");
|
|
8
|
+
const password = process.env.POSTGRES_PASSWORD;
|
|
9
|
+
if (!password) throw new Error("POSTGRES_PASSWORD environment variable is required");
|
|
10
|
+
const host = process.env.POSTGRES_HOST || "localhost";
|
|
11
|
+
const port = process.env.POSTGRES_PORT || "5432";
|
|
12
|
+
const db = process.env.POSTGRES_DB;
|
|
13
|
+
if (!db) throw new Error("POSTGRES_DB environment variable is required");
|
|
14
|
+
const connectionString = `postgresql://${user}:${password}@${host}:${port}/${db}?schema=public`;
|
|
15
|
+
|
|
16
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns the connection pool configuration for the `pg` driver.
|
|
20
|
+
*
|
|
21
|
+
* Reads from environment variables with sensible defaults:
|
|
22
|
+
* - `DB_POOL_MAX` — maximum number of connections (default: 10 in production, 5 in development)
|
|
23
|
+
* - `DB_POOL_IDLE_TIMEOUT` — milliseconds before an idle connection is closed (default: 30 000)
|
|
24
|
+
* - `DB_POOL_CONNECTION_TIMEOUT` — milliseconds to wait for a new connection (default: 5 000)
|
|
25
|
+
*
|
|
26
|
+
* @returns {{ max: number, idleTimeoutMillis: number, connectionTimeoutMillis: number }}
|
|
27
|
+
*/
|
|
28
|
+
export function getPoolConfig() {
|
|
29
|
+
return {
|
|
30
|
+
max: Number(process.env.DB_POOL_MAX) || (isProduction ? 10 : 5),
|
|
31
|
+
idleTimeoutMillis: Number(process.env.DB_POOL_IDLE_TIMEOUT) || 30_000,
|
|
32
|
+
connectionTimeoutMillis:
|
|
33
|
+
Number(process.env.DB_POOL_CONNECTION_TIMEOUT) || 5_000,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Create a singleton Prisma client with the PostgreSQL driver adapter and pool settings
|
|
38
|
+
const globalForPrisma = globalThis;
|
|
39
|
+
export const prisma =
|
|
40
|
+
globalForPrisma.prisma ||
|
|
41
|
+
new PrismaClient({
|
|
42
|
+
adapter: new PrismaPg({
|
|
43
|
+
connectionString,
|
|
44
|
+
...getPoolConfig(),
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (!isProduction) {
|
|
49
|
+
globalForPrisma.prisma = prisma;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export * from "./generated/prisma/client.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file should be your main import to use Prisma-related types and utilities in a browser.
|
|
7
|
+
* Use it to get access to models, enums, and input types.
|
|
8
|
+
*
|
|
9
|
+
* This file does not contain a `PrismaClient` class, nor several other helpers that are intended as server-side only.
|
|
10
|
+
* See `client.ts` for the standard, server-side entry point.
|
|
11
|
+
*
|
|
12
|
+
* 🟢 You can import this file directly.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as Prisma from "./internal/prismaNamespaceBrowser.ts";
|
|
16
|
+
export { Prisma };
|
|
17
|
+
export * as $Enums from "./enums.ts";
|
|
18
|
+
export * from "./enums.ts";
|
|
19
|
+
/**
|
|
20
|
+
* Model User
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export type User = Prisma.UserModel;
|
|
24
|
+
/**
|
|
25
|
+
* Model Post
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export type Post = Prisma.PostModel;
|
|
29
|
+
/**
|
|
30
|
+
* Model Account
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
export type Account = Prisma.AccountModel;
|
|
34
|
+
/**
|
|
35
|
+
* Model Session
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
export type Session = Prisma.SessionModel;
|
|
39
|
+
/**
|
|
40
|
+
* Model VerificationToken
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
export type VerificationToken = Prisma.VerificationTokenModel;
|
|
44
|
+
/**
|
|
45
|
+
* Model Job
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
export type Job = Prisma.JobModel;
|
|
49
|
+
/**
|
|
50
|
+
* Model AuditLog
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
export type AuditLog = Prisma.AuditLogModel;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file should be your main import to use Prisma. Through it you get access to all the models, enums, and input types.
|
|
7
|
+
* If you're looking for something you can import in the client-side of your application, please refer to the `browser.ts` file instead.
|
|
8
|
+
*
|
|
9
|
+
* 🟢 You can import this file directly.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import * as process from "node:process";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
|
|
16
|
+
globalThis["__dirname"] = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
|
|
18
|
+
import * as runtime from "@prisma/client/runtime/client";
|
|
19
|
+
import * as $Enums from "./enums.ts";
|
|
20
|
+
import * as $Class from "./internal/class.ts";
|
|
21
|
+
import * as Prisma from "./internal/prismaNamespace.ts";
|
|
22
|
+
|
|
23
|
+
export * as $Enums from "./enums.ts";
|
|
24
|
+
export * from "./enums.ts";
|
|
25
|
+
/**
|
|
26
|
+
* ## Prisma Client
|
|
27
|
+
*
|
|
28
|
+
* Type-safe database client for TypeScript
|
|
29
|
+
* @example
|
|
30
|
+
* ```
|
|
31
|
+
* const prisma = new PrismaClient()
|
|
32
|
+
* // Fetch zero or more Users
|
|
33
|
+
* const users = await prisma.user.findMany()
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Read more in our [docs](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client).
|
|
37
|
+
*/
|
|
38
|
+
export const PrismaClient = $Class.getPrismaClientClass();
|
|
39
|
+
export type PrismaClient<
|
|
40
|
+
LogOpts extends Prisma.LogLevel = never,
|
|
41
|
+
OmitOpts extends
|
|
42
|
+
Prisma.PrismaClientOptions["omit"] = Prisma.PrismaClientOptions["omit"],
|
|
43
|
+
ExtArgs extends
|
|
44
|
+
runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs,
|
|
45
|
+
> = $Class.PrismaClient<LogOpts, OmitOpts, ExtArgs>;
|
|
46
|
+
export { Prisma };
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Model User
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
export type User = Prisma.UserModel;
|
|
53
|
+
/**
|
|
54
|
+
* Model Post
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
export type Post = Prisma.PostModel;
|
|
58
|
+
/**
|
|
59
|
+
* Model Account
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
export type Account = Prisma.AccountModel;
|
|
63
|
+
/**
|
|
64
|
+
* Model Session
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
export type Session = Prisma.SessionModel;
|
|
68
|
+
/**
|
|
69
|
+
* Model VerificationToken
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
export type VerificationToken = Prisma.VerificationTokenModel;
|
|
73
|
+
/**
|
|
74
|
+
* Model Job
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
export type Job = Prisma.JobModel;
|
|
78
|
+
/**
|
|
79
|
+
* Model AuditLog
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
export type AuditLog = Prisma.AuditLogModel;
|