Fix jwt-token

This commit is contained in:
2025-09-17 06:33:03 +02:00
parent 5e230b996b
commit 7cc24c0a5d

View File

@@ -7,32 +7,44 @@
module.exports = { module.exports = {
async up(queryInterface, Sequelize) { async up(queryInterface, Sequelize) {
// Check if is_approved column already exists try {
const tableDescription = await queryInterface.describeTable('devices'); // Check if devices table exists first
const tables = await queryInterface.showAllTables();
if (!tableDescription.is_approved) { if (!tables.includes('devices')) {
// Add is_approved column to devices table console.log('⚠️ Devices table does not exist yet, skipping device approval migration...');
await queryInterface.addColumn('devices', 'is_approved', { return;
type: Sequelize.BOOLEAN, }
defaultValue: false,
allowNull: false,
comment: 'Whether the device is approved to send data'
});
// Add index for is_approved for better query performance // Check if is_approved column already exists
await queryInterface.addIndex('devices', ['is_approved'], { const tableDescription = await queryInterface.describeTable('devices');
name: 'devices_is_approved_idx'
}); if (!tableDescription.is_approved) {
// Add is_approved column to devices table
await queryInterface.addColumn('devices', 'is_approved', {
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false,
comment: 'Whether the device is approved to send data'
});
// Approve all existing devices by default (backward compatibility) // Add index for is_approved for better query performance
await queryInterface.sequelize.query( await queryInterface.addIndex('devices', ['is_approved'], {
'UPDATE devices SET is_approved = true WHERE created_at < NOW()' name: 'devices_is_approved_idx'
); });
console.log('✅ Added is_approved field to devices table'); // Approve all existing devices by default (backward compatibility)
console.log('✅ Approved all existing devices for backward compatibility'); await queryInterface.sequelize.query(
} else { 'UPDATE devices SET is_approved = true WHERE created_at < NOW()'
console.log('⚠️ Column is_approved already exists, skipping...'); );
console.log('✅ Added is_approved field to devices table');
console.log('✅ Approved all existing devices for backward compatibility');
} 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
} }
}, },