Files
afrov2/prisma/seed.ts
2026-04-24 14:39:01 +02:00

162 lines
5.6 KiB
TypeScript

import { PrismaClient, UserRole, Plan } from '@prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
import pg from 'pg';
import bcrypt from 'bcryptjs';
import dotenv from 'dotenv';
dotenv.config({ path: '.env.local' });
dotenv.config();
const connectionString = process.env.DATABASE_URL!;
const pool = new pg.Pool({ connectionString });
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });
async function main() {
console.log('🌱 Starting Core Database Seeding...');
const hashedPassword = await bcrypt.hash('afrohub2025', 10);
// 1. CLEANING DATA
console.log('🧹 Cleaning existing data...');
// Note: Only clean structure/system tables for a fresh core seed
await prisma.rating.deleteMany({});
await prisma.comment.deleteMany({});
await prisma.offer.deleteMany({});
await prisma.business.deleteMany({});
await prisma.businessCategory.deleteMany({});
await prisma.event.deleteMany({});
await prisma.blogPost.deleteMany({});
await prisma.interview.deleteMany({});
await prisma.pricingPlan.deleteMany({});
await prisma.user.deleteMany({});
await prisma.country.deleteMany({});
// 2. COUNTRIES
console.log('🌍 Seeding countries (Core)...');
for (const country of COUNTRIES_DATA) {
await prisma.country.create({ data: country });
}
// 3. CATEGORIES
console.log('📂 Seeding business categories (Core)...');
for (const cat of CATEGORIES_DATA) {
await prisma.businessCategory.create({ data: { ...cat, isActive: true } });
}
// 4. PRICING PLANS
console.log('💳 Seeding pricing plans (Core)...');
for (const plan of PLANS_DATA) {
await prisma.pricingPlan.create({ data: plan });
}
// 5. ADMIN USER
console.log('👤 Creating main Admin...');
await prisma.user.create({
data: {
name: 'Admin Afrohub',
email: 'admin@afrohub.com',
password: hashedPassword,
role: UserRole.ADMIN,
}
});
console.log('✅ CORE SEED COMPLETED SUCCESSFULLY!');
console.log('💡 Note: Use seed-30.ts and seed-events.ts for mockup data.');
}
// --- CORE DATA ---
const CATEGORIES_DATA = [
{ name: "Technologie & IT", slug: "technologie-it" },
{ name: "Agriculture & Agrobusiness", slug: "agriculture-agrobusiness" },
{ name: "Mode & Textile", slug: "mode-textile" },
{ name: "Cosmétique & Beauté", slug: "cosmetique-beaute" },
{ name: "Services aux entreprises", slug: "services-entreprises" },
{ name: "Restauration & Alimentation", slug: "restauration-alimentation" },
{ name: "Construction & BTP", slug: "construction-btp" },
{ name: "Éducation & Formation", slug: "education-formation" },
{ name: "Santé & Bien-être", slug: "sante-bien-etre" },
{ name: "Artisanat & Déco", slug: "artisanat-deco" },
{ name: "Tourisme & Loisirs", slug: "tourisme-loisirs" },
{ name: "Finance & Assurance", slug: "finance-assurance" }
];
const PLANS_DATA = [
{
tier: Plan.STARTER,
name: 'Starter',
priceXOF: 'Gratuit',
yearlyPriceXOF: 'Gratuit',
priceEUR: '0€',
yearlyPriceEUR: '0€',
description: 'Pour démarrer votre présence en ligne.',
features: ['Fiche entreprise basique', 'Visible dans la recherche', '1 Offre produit/service', 'Support par email'],
offerLimit: 1,
recommended: false,
color: 'gray'
},
{
tier: Plan.BOOSTER,
name: 'Booster',
priceXOF: '3 500 FCFA',
yearlyPriceXOF: '33 500 FCFA',
priceEUR: '5€',
yearlyPriceEUR: '48€',
description: "L'indispensable pour les entreprises en croissance.",
features: ['Tout du plan Starter', 'Badge "Vérifié" ✅', 'Jusqu\'à 10 Offres produits', 'Lien vers réseaux sociaux & Site Web', 'Statistiques de base (Vues)'],
offerLimit: 10,
recommended: true,
color: 'brand'
},
{
tier: Plan.EMPIRE,
name: 'Empire',
priceXOF: '13 000 FCFA',
yearlyPriceXOF: '125 000 FCFA',
priceEUR: '20€',
yearlyPriceEUR: '192€',
description: 'Dominez votre marché avec une visibilité maximale.',
features: ['Tout du plan Booster', 'Badge "Recommandé" 🏆', 'Offres illimitées', 'Intégration vidéo Youtube', 'Interview écrite sur le Blog', 'Support prioritaire WhatsApp'],
offerLimit: 1000,
recommended: false,
color: 'amber'
}
];
const COUNTRIES_DATA = [
{ name: "Bénin", code: "BJ", flag: "🇧🇯" },
{ name: "Burkina Faso", code: "BF", flag: "🇧🇫" },
{ name: "Cameroun", code: "CM", flag: "🇨🇲" },
{ name: "Congo-Kinshasa", code: "CD", flag: "🇨🇩" },
{ name: "Côte d'Ivoire", code: "CI", flag: "🇨🇮" },
{ name: "France", code: "FR", flag: "🇫🇷" },
{ name: "Belgique", code: "BE", flag: "🇧🇪" },
{ name: "Suisse", code: "CH", flag: "🇨🇭" },
{ name: "Luxembourg", code: "LU", flag: "🇱🇺" },
{ name: "Allemagne", code: "DE", flag: "🇩🇪" },
{ name: "Italie", code: "IT", flag: "🇮🇹" },
{ name: "Espagne", code: "ES", flag: "🇪🇸" },
{ name: "Portugal", code: "PT", flag: "🇵🇹" },
{ name: "Royaume-Uni", code: "GB", flag: "🇬🇧" },
{ name: "Pays-Bas", code: "NL", flag: "🇳🇱" },
{ name: "Gabon", code: "GA", flag: "🇬🇦" },
{ name: "Ghana", code: "GH", flag: "🇬🇭" },
{ name: "Guinée", code: "GN", flag: "🇬🇳" },
{ name: "Mali", code: "ML", flag: "🇲🇱" },
{ name: "Maroc", code: "MA", flag: "🇲🇦" },
{ name: "Niger", code: "NE", flag: "🇳🇪" },
{ name: "Nigéria", code: "NG", flag: "🇳🇬" },
{ name: "Sénégal", code: "SN", flag: "🇸🇳" },
{ name: "Togo", code: "TG", flag: "🇹🇬" }
];
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
await pool.end();
});