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

@@ -7,44 +7,32 @@
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');
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'
});
// Check if is_approved column already exists
const tableDescription = await queryInterface.describeTable('devices');
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'
});
// Add index for is_approved for better query performance
await queryInterface.addIndex('devices', ['is_approved'], {
name: 'devices_is_approved_idx'
});
// Add index for is_approved for better query performance
await queryInterface.addIndex('devices', ['is_approved'], {
name: 'devices_is_approved_idx'
});
// Approve all existing devices by default (backward compatibility)
await queryInterface.sequelize.query(
'UPDATE devices SET is_approved = true WHERE created_at < NOW()'
);
// Approve all existing devices by default (backward compatibility)
await queryInterface.sequelize.query(
'UPDATE devices SET is_approved = true WHERE created_at < NOW()'
);
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
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...');
}
},