const { sequelize, connectDB } = require('./config/database'); const Block = require('./models/Block'); const bcrypt = require('bcryptjs'); const eventBlocks = [ { name: 'Stuhl (Standard)', category: 'Bestuhlung', is_public: true, svg_data: ` ` }, { name: 'Tisch (Rechteck 180x80)', category: 'Möbel', is_public: true, svg_data: ` ` }, { name: 'Tisch (Rund Ø120)', category: 'Möbel', is_public: true, svg_data: ` ` }, { name: 'Bühne (Modular 200x100)', category: 'Bühne', is_public: true, svg_data: ` ` }, { name: 'Stehtisch', category: 'Möbel', is_public: true, svg_data: ` ` }, { name: 'Barhocker', category: 'Bestuhlung', is_public: true, svg_data: ` ` }, { name: 'Mischpult', category: 'Technik', is_public: true, svg_data: ` ` }, { name: 'Lautsprecher', category: 'Technik', is_public: true, svg_data: ` ` }, { name: 'Trennwand', category: 'Raum', is_public: true, svg_data: ` ` }, { name: 'Notausgang-Schild', category: 'Sicherheit', is_public: true, svg_data: ` EXIT ` }, ]; async function seed() { try { await connectDB(); // Use raw SQL to create user, bcrypt hashing via sequelize might fail, so we do raw const hashedPassword = bcrypt.hashSync('admin123', 10); await sequelize.query(` INSERT INTO "Users" ("email", "password", "createdAt", "updatedAt") VALUES (:email, :password, datetime('now'), datetime('now')) ON CONFLICT ("email") DO NOTHING; `, { replacements: { email: 'admin@cad.local', password: hashedPassword }, type: sequelize.QueryTypes.INSERT }); console.log('Admin user ensured.'); // Clear existing blocks await Block.destroy({ where: {} }); console.log('Existing blocks cleared.'); for (const block of eventBlocks) { await Block.create(block); } console.log(`${eventBlocks.length} blocks created.`); process.exit(0); } catch (err) { console.error('Seed failed:', err); process.exit(1); } } seed();