ci(netlify): set up database generation and seeding for serverless deployment
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
[build]
|
[build]
|
||||||
command = "npm run build"
|
command = "npx prisma db push && node scripts/seed-db.js && npm run build"
|
||||||
publish = ".next"
|
publish = ".next"
|
||||||
|
|
||||||
[[plugins]]
|
[[plugins]]
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default defineConfig({
|
|||||||
workers: process.env.CI ? 1 : undefined,
|
workers: process.env.CI ? 1 : undefined,
|
||||||
reporter: 'html',
|
reporter: 'html',
|
||||||
use: {
|
use: {
|
||||||
baseURL: 'http://localhost:3000',
|
baseURL: 'https://6a4e2de4d2a4e8009da3afbe--mobile2-staging-falah.netlify.app',
|
||||||
trace: 'on-first-retry',
|
trace: 'on-first-retry',
|
||||||
video: 'retain-on-failure',
|
video: 'retain-on-failure',
|
||||||
},
|
},
|
||||||
@@ -18,9 +18,4 @@ export default defineConfig({
|
|||||||
use: { ...devices['Desktop Chrome'] },
|
use: { ...devices['Desktop Chrome'] },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
webServer: {
|
|
||||||
command: 'node .next/standalone/server.js',
|
|
||||||
url: 'http://localhost:3000',
|
|
||||||
reuseExistingServer: !process.env.CI,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
const { PrismaClient } = require('@prisma/client');
|
||||||
|
const bcrypt = require('bcryptjs');
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log("Seeding database...");
|
||||||
|
try {
|
||||||
|
const password = await bcrypt.hash('password123', 10);
|
||||||
|
|
||||||
|
const userData = [
|
||||||
|
{ email: 'ghazali@falahos.my', name: 'Abu Hamid Al-Ghazali', passwordHash: password, flhBalance: 5000 },
|
||||||
|
{ email: 'ibnabbas@falahos.my', name: 'Abdullah Ibn Abbas', passwordHash: password, flhBalance: 3000 },
|
||||||
|
{ email: 'rabia@falahos.my', name: "Rabi'a Al-Adawiyya", passwordHash: password, flhBalance: 2000 },
|
||||||
|
{ email: 'demo@falahos.my', name: 'Demo User', passwordHash: password, flhBalance: 500 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const users = [];
|
||||||
|
for (const u of userData) {
|
||||||
|
let user = await prisma.user.findUnique({ where: { email: u.email } });
|
||||||
|
if (!user) {
|
||||||
|
user = await prisma.user.create({ data: u });
|
||||||
|
}
|
||||||
|
users.push(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
const listings = [
|
||||||
|
{ title: 'Digital Quran Study Planner', description: 'Comprehensive digital planner for Quran memorization tracking with daily logs and revision schedules.', category: 'E-Books', priceFlh: 150, sellerId: users[0].id },
|
||||||
|
{ title: 'Islamic Art Calligraphy Print', description: 'Beautiful "Bismillah" calligraphy print, handmade. High-quality 300gsm paper, A3 size.', category: 'Design', priceFlh: 250, sellerId: users[1].id },
|
||||||
|
{ title: 'Online Arabic Course - Beginner', description: '12-week structured Arabic course with weekly live sessions, worksheets, and community support.', category: 'Courses', priceFlh: 500, sellerId: users[2].id },
|
||||||
|
{ title: 'Halal Snack Box - Monthly Subscription', description: 'Curated box of halal-certified snacks delivered monthly. International treats included.', category: 'Other', priceFlh: 80, sellerId: users[3].id },
|
||||||
|
{ title: 'Digital Dhikr Counter App', description: 'Beautiful dhikr counter with daily adhkar tracking, goals, and badges.', category: 'Software', priceFlh: 30, sellerId: users[0].id },
|
||||||
|
{ title: 'Handcrafted Tasbih (Prayer Beads)', description: 'Premium olive wood tasbih, 33 beads with tassel. Handcrafted by artisans. Gift box included.', category: 'Other', priceFlh: 120, sellerId: users[1].id },
|
||||||
|
{ title: 'Islamic Parenting E-Book Bundle', description: '5 e-books on raising righteous children: discipline, faith, education, screen time, character.', category: 'E-Books', priceFlh: 45, sellerId: users[2].id },
|
||||||
|
{ title: 'Tajweed Mastery Video Course', description: 'Complete Tajweed rules with 20 video lessons, practice exercises, and progress quizzes.', category: 'Courses', priceFlh: 350, sellerId: users[0].id },
|
||||||
|
];
|
||||||
|
|
||||||
|
let created = 0;
|
||||||
|
for (const l of listings) {
|
||||||
|
const existing = await prisma.listing.findFirst({ where: { title: l.title } });
|
||||||
|
if (!existing) {
|
||||||
|
await prisma.listing.create({ data: l });
|
||||||
|
created++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Successfully seeded ${users.length} users and ${created} new listings.`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error during seeding:", error);
|
||||||
|
process.exit(1);
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
Reference in New Issue
Block a user