- Remove problematic .env files that override Docker environment variables - Add automatic database initialization script (init-database.js) - Create admin@oliver.agency user automatically with admin123 password - Auto-run database migrations and seeding on first startup - Update setup scripts to display admin credentials - Add comprehensive Docker deployment README - Make deployment truly plug-and-play: git clone → cd docker → ./simple-setup.sh 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
67 lines
No EOL
2.1 KiB
JavaScript
67 lines
No EOL
2.1 KiB
JavaScript
const bcrypt = require('bcrypt');
|
|
const { sequelize, testConnection } = require('../config/database');
|
|
const { User } = require('../models');
|
|
|
|
async function initDatabase() {
|
|
try {
|
|
console.log('🔄 Initializing database...');
|
|
|
|
// Test connection
|
|
await testConnection();
|
|
|
|
// Run migrations (sync models)
|
|
console.log('📋 Running database migrations...');
|
|
await sequelize.sync({ force: false, alter: true });
|
|
console.log('✅ Database migrations completed');
|
|
|
|
// Check if admin user exists
|
|
const existingAdmin = await User.findOne({
|
|
where: { email: 'admin@oliver.agency' }
|
|
});
|
|
|
|
if (!existingAdmin) {
|
|
// Create admin user
|
|
console.log('👑 Creating admin user...');
|
|
const hashedPassword = await bcrypt.hash('admin123', 10);
|
|
|
|
await User.create({
|
|
email: 'admin@oliver.agency',
|
|
name: 'Administrator',
|
|
password: hashedPassword,
|
|
isActive: true,
|
|
preferences: {
|
|
theme: 'light',
|
|
notifications: true,
|
|
defaultAssistant: 'creator-bot-push-the-boundaries-of-technology',
|
|
role: 'admin',
|
|
allowedAgents: null,
|
|
}
|
|
});
|
|
|
|
console.log('✅ Admin user created: admin@oliver.agency / admin123');
|
|
} else {
|
|
console.log('👑 Admin user already exists');
|
|
}
|
|
|
|
// Run seed data (agents) - import and check if it has the async function
|
|
try {
|
|
const seedModule = require('../migrations/seed');
|
|
if (typeof seedModule === 'function') {
|
|
console.log('🌱 Seeding initial data...');
|
|
await seedModule();
|
|
console.log('✅ Initial data seeded');
|
|
}
|
|
} catch (seedError) {
|
|
console.warn('⚠️ Seed data already exists or failed:', seedError.message);
|
|
}
|
|
|
|
console.log('🎉 Database initialization completed successfully!');
|
|
console.log('📋 Admin login: admin@oliver.agency / admin123');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Database initialization failed:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
module.exports = initDatabase; |