Fix jwt-token

This commit is contained in:
2025-09-21 09:03:09 +02:00
parent a1cf28f76a
commit e52d6a8384
3 changed files with 633 additions and 28 deletions

View File

@@ -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');