175 lines
4.5 KiB
JavaScript
175 lines
4.5 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
const bcrypt = require('bcryptjs');
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('🌱 Starting database seed...');
|
|
|
|
// Create admin user
|
|
const adminPasswordHash = await bcrypt.hash('admin123', 12);
|
|
const admin = await prisma.user.upsert({
|
|
where: { email: 'admin@vaishnavi.com' },
|
|
update: {},
|
|
create: {
|
|
email: 'admin@vaishnavi.com',
|
|
passwordHash: adminPasswordHash,
|
|
firstName: 'Admin',
|
|
lastName: 'User',
|
|
username: 'admin',
|
|
role: 'ADMIN',
|
|
isVerified: true,
|
|
isActive: true,
|
|
},
|
|
});
|
|
|
|
// Create test customer
|
|
const customerPasswordHash = await bcrypt.hash('customer123', 12);
|
|
const customer = await prisma.user.upsert({
|
|
where: { email: 'customer@example.com' },
|
|
update: {},
|
|
create: {
|
|
email: 'customer@example.com',
|
|
passwordHash: customerPasswordHash,
|
|
firstName: 'John',
|
|
lastName: 'Doe',
|
|
username: 'johndoe',
|
|
role: 'CUSTOMER',
|
|
isVerified: true,
|
|
isActive: true,
|
|
},
|
|
});
|
|
|
|
// Create categories
|
|
const categories = [
|
|
{
|
|
name: 'Women\'s Clothing',
|
|
slug: 'womens-clothing',
|
|
description: 'Beautiful women\'s fashion and apparel',
|
|
metaTitle: 'Women\'s Clothing - Vaishnavi Creation',
|
|
metaDescription: 'Discover our collection of women\'s clothing and fashion items.',
|
|
},
|
|
{
|
|
name: 'Men\'s Clothing',
|
|
slug: 'mens-clothing',
|
|
description: 'Stylish men\'s fashion and apparel',
|
|
metaTitle: 'Men\'s Clothing - Vaishnavi Creation',
|
|
metaDescription: 'Explore our range of men\'s clothing and fashion items.',
|
|
},
|
|
{
|
|
name: 'Accessories',
|
|
slug: 'accessories',
|
|
description: 'Fashion accessories and jewelry',
|
|
metaTitle: 'Accessories - Vaishnavi Creation',
|
|
metaDescription: 'Complete your look with our fashion accessories.',
|
|
},
|
|
{
|
|
name: 'Shoes',
|
|
slug: 'shoes',
|
|
description: 'Comfortable and stylish footwear',
|
|
metaTitle: 'Shoes - Vaishnavi Creation',
|
|
metaDescription: 'Find the perfect pair of shoes for any occasion.',
|
|
},
|
|
];
|
|
|
|
for (const categoryData of categories) {
|
|
await prisma.category.upsert({
|
|
where: { slug: categoryData.slug },
|
|
update: {},
|
|
create: categoryData,
|
|
});
|
|
}
|
|
|
|
// Create sample coupons
|
|
const coupons = [
|
|
{
|
|
code: 'WELCOME10',
|
|
description: '10% off for new customers',
|
|
type: 'PERCENTAGE',
|
|
value: 10,
|
|
minOrderAmount: 50,
|
|
maxUses: 1000,
|
|
validFrom: new Date(),
|
|
validUntil: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days
|
|
isActive: true,
|
|
},
|
|
{
|
|
code: 'FREESHIP',
|
|
description: 'Free shipping on orders over $100',
|
|
type: 'FREE_SHIPPING',
|
|
value: 0,
|
|
minOrderAmount: 100,
|
|
maxUses: null,
|
|
validFrom: new Date(),
|
|
validUntil: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000), // 90 days
|
|
isActive: true,
|
|
},
|
|
];
|
|
|
|
for (const couponData of coupons) {
|
|
await prisma.coupon.upsert({
|
|
where: { code: couponData.code },
|
|
update: {},
|
|
create: couponData,
|
|
});
|
|
}
|
|
|
|
// Create system configuration
|
|
const systemConfigs = [
|
|
{
|
|
key: 'site_name',
|
|
value: 'Vaishnavi Creation',
|
|
type: 'STRING',
|
|
},
|
|
{
|
|
key: 'site_description',
|
|
value: 'Your premier destination for fashion and style',
|
|
type: 'STRING',
|
|
},
|
|
{
|
|
key: 'currency',
|
|
value: 'USD',
|
|
type: 'STRING',
|
|
},
|
|
{
|
|
key: 'tax_rate',
|
|
value: '10',
|
|
type: 'NUMBER',
|
|
},
|
|
{
|
|
key: 'free_shipping_threshold',
|
|
value: '100',
|
|
type: 'NUMBER',
|
|
},
|
|
{
|
|
key: 'maintenance_mode',
|
|
value: 'false',
|
|
type: 'BOOLEAN',
|
|
},
|
|
];
|
|
|
|
for (const configData of systemConfigs) {
|
|
await prisma.systemConfig.upsert({
|
|
where: { key: configData.key },
|
|
update: {},
|
|
create: configData,
|
|
});
|
|
}
|
|
|
|
console.log('✅ Database seeded successfully!');
|
|
console.log(`👤 Admin user created: admin@vaishnavi.com / admin123`);
|
|
console.log(`👤 Customer user created: customer@example.com / customer123`);
|
|
console.log(`📦 ${categories.length} categories created`);
|
|
console.log(`🎫 ${coupons.length} coupons created`);
|
|
console.log(`⚙️ ${systemConfigs.length} system configs created`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('❌ Seed failed:', e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|