142 lines
3.7 KiB
JavaScript
142 lines
3.7 KiB
JavaScript
/**
|
||
* 天气数据管理相关表
|
||
*/
|
||
|
||
export const up = (pgm) => {
|
||
// 1. 气象站表
|
||
pgm.createTable('weather_stations', {
|
||
id: { type: 'serial', primaryKey: true },
|
||
station_name: {
|
||
type: 'varchar(255)',
|
||
unique: true,
|
||
notNull: true,
|
||
comment: '气象站名称'
|
||
},
|
||
location: {
|
||
type: 'varchar(255)',
|
||
notNull: true,
|
||
comment: '气象站位置'
|
||
},
|
||
latitude: {
|
||
type: 'decimal(10,8)',
|
||
comment: '纬度'
|
||
},
|
||
longitude: {
|
||
type: 'decimal(11,8)',
|
||
comment: '经度'
|
||
},
|
||
altitude: {
|
||
type: 'decimal(8,2)',
|
||
comment: '海拔高度(米)'
|
||
},
|
||
status: {
|
||
type: 'varchar(50)',
|
||
notNull: true,
|
||
default: 'active',
|
||
comment: 'active, maintenance, offline'
|
||
},
|
||
created_at: { type: 'timestamptz', notNull: true, default: pgm.func('current_timestamp') },
|
||
updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('current_timestamp') }
|
||
});
|
||
|
||
// 2. 天气观测数据表
|
||
pgm.createTable('weather_observations', {
|
||
id: { type: 'serial', primaryKey: true },
|
||
weather_station_id: {
|
||
type: 'integer',
|
||
notNull: true,
|
||
references: 'weather_stations(id)',
|
||
onDelete: 'CASCADE'
|
||
},
|
||
observation_time: {
|
||
type: 'timestamptz',
|
||
notNull: true,
|
||
comment: '观测时间'
|
||
},
|
||
temperature: {
|
||
type: 'decimal(5,2)',
|
||
comment: '温度(摄氏度)'
|
||
},
|
||
humidity: {
|
||
type: 'decimal(5,2)',
|
||
comment: '湿度(%)'
|
||
},
|
||
cloud_cover: {
|
||
type: 'decimal(5,2)',
|
||
comment: '云量(%)'
|
||
},
|
||
visibility: {
|
||
type: 'decimal(6,2)',
|
||
comment: '能见度(公里)'
|
||
},
|
||
wind_speed: {
|
||
type: 'decimal(5,2)',
|
||
comment: '风速(km/h)'
|
||
},
|
||
wind_direction: {
|
||
type: 'integer',
|
||
comment: '风向(度,0-360)'
|
||
},
|
||
condition: {
|
||
type: 'varchar(100)',
|
||
comment: '天气状况描述'
|
||
},
|
||
observation_quality: {
|
||
type: 'varchar(50)',
|
||
comment: 'excellent, moderate, poor'
|
||
},
|
||
pressure: {
|
||
type: 'decimal(7,2)',
|
||
comment: '气压(hPa)'
|
||
},
|
||
precipitation: {
|
||
type: 'decimal(6,2)',
|
||
comment: '降水量(mm)'
|
||
},
|
||
created_at: { type: 'timestamptz', notNull: true, default: pgm.func('current_timestamp') }
|
||
});
|
||
|
||
// 3. 天气预报数据表
|
||
pgm.createTable('weather_forecasts', {
|
||
id: { type: 'serial', primaryKey: true },
|
||
weather_station_id: {
|
||
type: 'integer',
|
||
notNull: true,
|
||
references: 'weather_stations(id)',
|
||
onDelete: 'CASCADE'
|
||
},
|
||
forecast_time: {
|
||
type: 'timestamptz',
|
||
notNull: true,
|
||
comment: '预报时间'
|
||
},
|
||
issued_at: {
|
||
type: 'timestamptz',
|
||
notNull: true,
|
||
comment: '预报发布时间'
|
||
},
|
||
temperature: { type: 'decimal(5,2)' },
|
||
cloud_cover: { type: 'decimal(5,2)' },
|
||
precipitation: { type: 'decimal(6,2)' },
|
||
visibility: { type: 'decimal(6,2)' },
|
||
condition: { type: 'varchar(100)' },
|
||
confidence: {
|
||
type: 'decimal(3,2)',
|
||
comment: '预报置信度(0-1)'
|
||
},
|
||
created_at: { type: 'timestamptz', notNull: true, default: pgm.func('current_timestamp') }
|
||
});
|
||
|
||
// 添加索引
|
||
pgm.createIndex('weather_stations', 'station_name');
|
||
pgm.createIndex('weather_observations', 'weather_station_id');
|
||
pgm.createIndex('weather_observations', 'observation_time');
|
||
pgm.createIndex('weather_forecasts', 'weather_station_id');
|
||
pgm.createIndex('weather_forecasts', 'forecast_time');
|
||
};
|
||
|
||
export const down = (pgm) => {
|
||
pgm.dropTable('weather_forecasts');
|
||
pgm.dropTable('weather_observations');
|
||
pgm.dropTable('weather_stations');
|
||
}; |