meteor_detection_system/meteor-web-backend/src/entities/weather-observation.entity.ts
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

70 lines
2.0 KiB
TypeScript

import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
JoinColumn,
CreateDateColumn,
DeleteDateColumn,
Index,
} from 'typeorm';
import { WeatherStation } from './weather-station.entity';
@Entity('weather_observations')
export class WeatherObservation {
// Changed from serial to UUID in migration 1766300000006-1766300000008
@PrimaryGeneratedColumn('uuid')
id: string;
// Changed from number to UUID in migration 1766300000007-1766300000008
@Column({ name: 'weather_station_id', type: 'uuid' })
@Index('idx_weather_observations_station_id')
weatherStationId: string;
@ManyToOne(() => WeatherStation, (station) => station.observations, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'weather_station_id' })
weatherStation: WeatherStation;
@Column({ name: 'observation_time', type: 'timestamptz' })
@Index('idx_weather_observations_time')
observationTime: Date;
@Column({ type: 'decimal', precision: 5, scale: 2 })
temperature: number;
@Column({ type: 'decimal', precision: 5, scale: 2 })
humidity: number;
@Column({ name: 'cloud_cover', type: 'decimal', precision: 5, scale: 2 })
cloudCover: number;
@Column({ type: 'decimal', precision: 6, scale: 2 })
visibility: number;
@Column({ name: 'wind_speed', type: 'decimal', precision: 5, scale: 2 })
windSpeed: number;
@Column({ name: 'wind_direction', type: 'int' })
windDirection: number;
@Column()
condition: string;
@Column({ name: 'observation_quality' })
observationQuality: 'excellent' | 'moderate' | 'poor';
@Column({ type: 'decimal', precision: 7, scale: 2 })
pressure: number;
@Column({ type: 'decimal', precision: 5, scale: 2 })
precipitation: number;
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
createdAt: Date;
// Soft delete support (added in migration 1766300000005)
@DeleteDateColumn({ name: 'deleted_at', type: 'timestamptz', nullable: true })
@Index('idx_weather_observations_deleted_at', { where: 'deleted_at IS NULL' })
deletedAt?: Date;
}