Fix jwt-token

This commit is contained in:
2025-09-17 06:59:17 +02:00
parent a0e0343989
commit 98444a26cc
2 changed files with 39 additions and 50 deletions

View File

@@ -156,32 +156,33 @@ async function startServer() {
await sequelize.authenticate();
console.log('Database connected successfully.');
// Run migrations first
try {
await runMigrations();
} catch (migrationError) {
console.error('Migration error:', migrationError);
console.log('Continuing with database sync...');
}
// Always sync database in containerized environments or development
// Check if tables exist before syncing
// STEP 1: Sync database first to create base tables
try {
// Use alter: false to prevent destructive changes in production
await sequelize.sync({ force: false, alter: false });
console.log('Database synchronized.');
// Seed database with initial data
await seedDatabase();
} catch (syncError) {
console.error('Database sync error:', syncError);
// If sync fails, try force sync (this will drop and recreate tables)
console.log('Attempting force sync...');
await sequelize.sync({ force: true });
console.log('Database force synchronized.');
}
// Seed database with initial data
// STEP 2: Run migrations after tables exist
try {
await runMigrations();
} catch (migrationError) {
console.error('Migration error:', migrationError);
throw migrationError; // Fatal error - don't continue
}
// STEP 3: Seed database with initial data
try {
await seedDatabase();
} catch (seedError) {
console.error('Seeding error:', seedError);
throw seedError; // Fatal error - don't continue
}
server.listen(PORT, () => {

View File

@@ -7,14 +7,6 @@
module.exports = {
async up(queryInterface, Sequelize) {
try {
// Check if devices table exists first
const tables = await queryInterface.showAllTables();
if (!tables.includes('devices')) {
console.log('⚠️ Devices table does not exist yet, skipping device approval migration...');
return;
}
// Check if is_approved column already exists
const tableDescription = await queryInterface.describeTable('devices');
@@ -42,10 +34,6 @@ module.exports = {
} else {
console.log('⚠️ Column is_approved already exists, skipping...');
}
} catch (error) {
console.log('⚠️ Migration skipped - tables may not exist yet:', error.message);
// Don't throw error, just skip this migration if tables don't exist
}
},
async down(queryInterface, Sequelize) {