Fix jwt-token
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const { Sequelize } = require('sequelize');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const runMigrations = require('./migrate');
|
||||
|
||||
// Import models from the main models index
|
||||
const {
|
||||
@@ -25,10 +26,19 @@ const setupDatabase = async () => {
|
||||
// Models are already initialized through the imports
|
||||
console.log('<27> Models loaded and ready...');
|
||||
|
||||
// Sync database (create tables)
|
||||
console.log('🏗️ Creating database tables...');
|
||||
await sequelize.sync({ force: true }); // WARNING: This will drop existing tables
|
||||
console.log('✅ Database tables created successfully.\n');
|
||||
// Run migrations first to create proper schema
|
||||
console.log('🏗️ Running database migrations...');
|
||||
await runMigrations();
|
||||
console.log('✅ Database migrations completed successfully.\n');
|
||||
|
||||
// Check if sample data already exists
|
||||
const existingTenants = await Tenant.count();
|
||||
if (existingTenants > 0) {
|
||||
console.log('📊 Sample data already exists, skipping data creation...\n');
|
||||
console.log('🎉 Database setup completed successfully!\n');
|
||||
await sequelize.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create sample data
|
||||
console.log('📊 Creating sample data...\n');
|
||||
@@ -284,8 +294,8 @@ const setupDatabase = async () => {
|
||||
`);
|
||||
|
||||
await sequelize.query(`
|
||||
CREATE INDEX IF NOT EXISTS idx_alert_logs_user_created
|
||||
ON "alert_logs" (user_id, "created_at");
|
||||
CREATE INDEX IF NOT EXISTS idx_alert_logs_rule_created
|
||||
ON "alert_logs" (alert_rule_id, "created_at");
|
||||
`);
|
||||
|
||||
console.log('✅ Database indexes created\n');
|
||||
|
||||
Reference in New Issue
Block a user