first commit: Complete phishing test management panel with Node.js backend and React frontend
This commit is contained in:
31
backend/migrations/001-create-tables.js
Normal file
31
backend/migrations/001-create-tables.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const { sequelize } = require('../src/models');
|
||||
|
||||
async function up() {
|
||||
try {
|
||||
console.log('🔄 Creating database tables...');
|
||||
|
||||
// Sync all models (create tables)
|
||||
await sequelize.sync({ force: false });
|
||||
|
||||
console.log('✅ All tables created successfully!');
|
||||
} catch (error) {
|
||||
console.error('❌ Error creating tables:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function down() {
|
||||
try {
|
||||
console.log('🔄 Dropping all tables...');
|
||||
|
||||
await sequelize.drop();
|
||||
|
||||
console.log('✅ All tables dropped successfully!');
|
||||
} catch (error) {
|
||||
console.error('❌ Error dropping tables:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { up, down };
|
||||
|
||||
32
backend/migrations/run-migrations.js
Normal file
32
backend/migrations/run-migrations.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
require('dotenv').config();
|
||||
|
||||
async function runMigrations() {
|
||||
console.log('🚀 Starting database migrations...\n');
|
||||
|
||||
const migrationsDir = __dirname;
|
||||
const migrationFiles = fs
|
||||
.readdirSync(migrationsDir)
|
||||
.filter(file => file.endsWith('.js') && file !== 'run-migrations.js')
|
||||
.sort();
|
||||
|
||||
for (const file of migrationFiles) {
|
||||
console.log(`📦 Running migration: ${file}`);
|
||||
const migration = require(path.join(migrationsDir, file));
|
||||
|
||||
try {
|
||||
await migration.up();
|
||||
console.log(`✅ ${file} completed\n`);
|
||||
} catch (error) {
|
||||
console.error(`❌ ${file} failed:`, error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🎉 All migrations completed successfully!');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
runMigrations();
|
||||
|
||||
Reference in New Issue
Block a user