Fix login: seed.js creates admin user, run seed before server start
This commit is contained in:
@@ -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.');
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user