Fix login: seed.js creates admin user, run seed before server start

This commit is contained in:
Agent Zero
2026-05-25 16:49:20 +00:00
parent a1d377e8e5
commit c2905fdfe4
2 changed files with 8 additions and 1 deletions
+7
View File
@@ -1,5 +1,6 @@
const { sequelize, connectDB } = require('./config/database'); const { sequelize, connectDB } = require('./config/database');
const Block = require('./models/Block'); const Block = require('./models/Block');
const User = require('./models/User');
const eventBlocks = [ const eventBlocks = [
{ {
@@ -114,6 +115,12 @@ const eventBlocks = [
async function seed() { async function seed() {
try { try {
await connectDB(); await connectDB();
// Create admin user if not exists
const existingUser = await User.findOne({ where: { email: 'admin@cad.local' } });
if (!existingUser) {
await User.create({ email: 'admin@cad.local', password: 'admin123' });
console.log('Admin user created: admin@cad.local / admin123');
}
// Clear existing blocks // Clear existing blocks
await Block.destroy({ where: {} }); await Block.destroy({ where: {} });
console.log('Existing blocks cleared.'); console.log('Existing blocks cleared.');
+1 -1
View File
@@ -39,7 +39,7 @@ services:
cp -r /tmp/repo/backend/* /app/ cp -r /tmp/repo/backend/* /app/
rm -rf /tmp/repo rm -rf /tmp/repo
npm ci --only=production npm ci --only=production
node server.js node seed.js && node server.js
depends_on: depends_on:
postgres: postgres:
condition: service_healthy condition: service_healthy