Fix jwt-token
This commit is contained in:
41
server/migrations/20250828000001-add-device-approval.js
Normal file
41
server/migrations/20250828000001-add-device-approval.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Migration: Add is_approved field to devices table
|
||||
* This migration adds device approval functionality to the system
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
// 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'
|
||||
});
|
||||
|
||||
// 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');
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
// Remove index first
|
||||
await queryInterface.removeIndex('devices', 'devices_is_approved_idx');
|
||||
|
||||
// Remove the column
|
||||
await queryInterface.removeColumn('devices', 'is_approved');
|
||||
|
||||
console.log('✅ Removed is_approved field from devices table');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user