/** * @type {import('node-pg-migrate').ColumnDefinitions | undefined} */ exports.shorthands = undefined; /** * @param pgm {import('node-pg-migrate').MigrationBuilder} * @param run {() => void | undefined} * @returns {Promise | void} */ exports.up = (pgm) => { // Add missing columns to devices table pgm.addColumns('devices', { device_token: { type: 'varchar(255)', unique: true, }, hardware_fingerprint_hash: { type: 'varchar(128)', }, firmware_version: { type: 'varchar(100)', }, device_model: { type: 'varchar(100)', }, location: { type: 'jsonb', }, capabilities: { type: 'jsonb', }, network_info: { type: 'jsonb', }, security_level: { type: 'varchar(20)', default: 'standard', }, trust_score: { type: 'float', default: 1.0, }, last_heartbeat_at: { type: 'timestamp with time zone', }, activated_at: { type: 'timestamp with time zone', }, deactivated_at: { type: 'timestamp with time zone', }, metadata: { type: 'jsonb', }, }); // Add indexes for commonly queried columns pgm.createIndex('devices', 'device_token'); pgm.createIndex('devices', 'last_heartbeat_at'); }; /** * @param pgm {import('node-pg-migrate').MigrationBuilder} * @param run {() => void | undefined} * @returns {Promise | void} */ exports.down = (pgm) => { pgm.dropIndex('devices', 'last_heartbeat_at'); pgm.dropIndex('devices', 'device_token'); pgm.dropColumns('devices', [ 'device_token', 'hardware_fingerprint_hash', 'firmware_version', 'device_model', 'location', 'capabilities', 'network_info', 'security_level', 'trust_score', 'last_heartbeat_at', 'activated_at', 'deactivated_at', 'metadata', ]); };