meteor_detection_system/meteor-web-backend/migrations/1766250271179_add-missing-device-columns.js
grabbit f557c06771 feat: complete database schema migration to UUID primary keys
## Database Migrations (18 new)
- Migrate all primary keys from SERIAL to UUID
- Add soft delete (deleted_at) to all 19 entities
- Add missing indexes for performance optimization
- Add CHECK constraints for data validation
- Add user audit fields (last_login_at, timezone, locale)
- Add weather station location fields (latitude, longitude, elevation)
- Add foreign key relationships (CameraDevice→Device, ValidatedEvent→WeatherStation)
- Prepare private key encryption fields

## Backend Entity Updates
- All entities updated with UUID primary keys
- Added @DeleteDateColumn for soft delete support
- Updated relations and foreign key types

## Backend Service/Controller Updates
- Changed ID parameters from number to string (UUID)
- Removed ParseIntPipe from controllers
- Updated TypeORM queries for string IDs

## Frontend Updates
- Updated all service interfaces to use string IDs
- Fixed CameraDevice.location as JSONB object
- Updated weather.ts with new fields (elevation, timezone)
- Added Supabase integration hooks and lib
- Fixed chart components for new data structure

## Cleanup
- Removed deprecated .claude/agents configuration files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 03:33:26 +08:00

88 lines
1.8 KiB
JavaScript

/**
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
*/
exports.shorthands = undefined;
/**
* @param pgm {import('node-pg-migrate').MigrationBuilder}
* @param run {() => void | undefined}
* @returns {Promise<void> | 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> | 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',
]);
};