Skip to content

Commit 9296d2c

Browse files
committed
feat(prisma): add db:resetadmin and db:setup scripts for database management
1 parent 4e4d170 commit 9296d2c

File tree

5 files changed

+439
-909
lines changed

5 files changed

+439
-909
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"db:push": "prisma db push",
1414
"db:studio": "prisma studio",
1515
"db:seed": "prisma db seed",
16+
"db:resetadmin": "npx tsx prisma/reset-admin.ts",
17+
"db:setup": "prisma generate && prisma migrate dev && db:seed",
1618
"setup": "node scripts/setup.js",
1719
"generate:examples": "npx tsx scripts/generate-examples.ts",
1820
"postinstall": "prisma generate"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- AlterTable
2+
ALTER TABLE "users" ALTER COLUMN "dailyGenerationLimit" SET DEFAULT 3,
3+
ALTER COLUMN "generationCreditsRemaining" SET DEFAULT 3;

prisma/reset-admin.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { PrismaClient } from "@prisma/client";
2+
import bcrypt from "bcryptjs";
3+
4+
const prisma = new PrismaClient();
5+
6+
async function main() {
7+
console.log("🔐 Resetting admin user...");
8+
9+
const password = await bcrypt.hash("password123", 12);
10+
11+
const admin = await prisma.user.upsert({
12+
where: { email: "[email protected]" },
13+
update: {
14+
password: password,
15+
role: "ADMIN",
16+
},
17+
create: {
18+
19+
username: "admin",
20+
name: "Admin User",
21+
password: password,
22+
role: "ADMIN",
23+
locale: "en",
24+
},
25+
});
26+
27+
console.log("✅ Admin user reset successfully!");
28+
console.log("\n📋 Credentials:");
29+
console.log(" Email: [email protected]");
30+
console.log(" Password: password123");
31+
}
32+
33+
main()
34+
.catch((e) => {
35+
console.error("❌ Failed to reset admin:", e);
36+
process.exit(1);
37+
})
38+
.finally(async () => {
39+
await prisma.$disconnect();
40+
});

0 commit comments

Comments
 (0)