const { Client } = require('pg'); const bcrypt = require('bcryptjs'); const dotenv = require('dotenv'); const path = require('path'); dotenv.config({ path: path.join(__dirname, '.env') }); const client = new Client({ host: process.env.DB_HOST, port: parseInt(process.env.DB_PORT || '5432'), user: process.env.DB_USER, password: process.env.DB_PASSWORD, database: process.env.DB_NAME, }); async function main() { try { await client.connect(); console.log('Connected to PostgreSQL to seed Super Admin and initial configurations...'); const email = 'ruibto@gmail.com'; const password = 'Rc362514'; const name = 'Rui Dono'; const hash = await bcrypt.hash(password, 10); // Check if user already exists const check = await client.query('SELECT id FROM users WHERE email = $1', [email]); if (check.rows.length > 0) { console.log('Super Admin already exists!'); } else { // Insert Super Admin await client.query( 'INSERT INTO users (name, email, password_hash, role, status, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, NOW(), NOW())', [name, email, hash, 'super_admin', 'active'] ); console.log('Super Admin seeded successfully!'); } // Seed default categories for Clube67 const categories = [ { name: 'Gastronomia', slug: 'gastronomia', icon: 'Utensils' }, { name: 'Saúde & Bem-Estar', slug: 'saude-e-bem-estar', icon: 'HeartPulse' }, { name: 'Educação', slug: 'educacao', icon: 'GraduationCap' }, { name: 'Lazer & Viagens', slug: 'lazer-e-viagens', icon: 'Compass' }, { name: 'Serviços', slug: 'servicos', icon: 'Wrench' }, { name: 'Moda & Beleza', slug: 'moda-e-beleza', icon: 'Sparkles' } ]; for (const cat of categories) { const cCheck = await client.query('SELECT id FROM categories WHERE slug = $1', [cat.slug]); if (cCheck.rows.length === 0) { await client.query( 'INSERT INTO categories (name, slug, icon, created_at, updated_at) VALUES ($1, $2, $3, NOW(), NOW())', [cat.name, cat.slug, cat.icon] ); console.log(`Category '${cat.name}' seeded!`); } } await client.end(); console.log('Database seeding successfully finished!'); } catch (err) { console.error('Seeding failed:', err); } } main();