73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
/**
|
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
|
*/
|
|
export const shorthands = undefined;
|
|
|
|
/**
|
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
|
* @param run {() => void | undefined}
|
|
* @returns {Promise<void> | void}
|
|
*/
|
|
export const up = (pgm) => {
|
|
// 创建天气站点表
|
|
pgm.createTable('weather_stations', {
|
|
id: 'id',
|
|
station_name: { type: 'varchar(100)', notNull: true },
|
|
current_temperature: { type: 'decimal(4,1)', notNull: false },
|
|
humidity: { type: 'integer', notNull: false },
|
|
cloud_cover: { type: 'integer', notNull: false },
|
|
visibility: { type: 'decimal(5,1)', notNull: false },
|
|
wind_speed: { type: 'decimal(5,1)', notNull: false },
|
|
wind_direction: { type: 'integer', notNull: false },
|
|
condition: { type: 'varchar(50)', notNull: false },
|
|
observation_quality: { type: 'varchar(20)', notNull: false },
|
|
created_at: {
|
|
type: 'timestamp',
|
|
notNull: true,
|
|
default: pgm.func('current_timestamp'),
|
|
},
|
|
updated_at: {
|
|
type: 'timestamp',
|
|
notNull: true,
|
|
default: pgm.func('current_timestamp'),
|
|
},
|
|
});
|
|
|
|
// 创建天气预报表
|
|
pgm.createTable('weather_forecasts', {
|
|
id: 'id',
|
|
station_id: {
|
|
type: 'integer',
|
|
notNull: true,
|
|
references: '"weather_stations"',
|
|
onDelete: 'cascade',
|
|
},
|
|
forecast_time: { type: 'timestamp', notNull: true },
|
|
temperature: { type: 'decimal(4,1)', notNull: false },
|
|
cloud_cover: { type: 'integer', notNull: false },
|
|
precipitation: { type: 'decimal(5,1)', notNull: false, default: 0 },
|
|
visibility: { type: 'decimal(5,1)', notNull: false },
|
|
condition: { type: 'varchar(50)', notNull: false },
|
|
created_at: {
|
|
type: 'timestamp',
|
|
notNull: true,
|
|
default: pgm.func('current_timestamp'),
|
|
},
|
|
});
|
|
|
|
// 添加索引
|
|
pgm.createIndex('weather_stations', 'station_name');
|
|
pgm.createIndex('weather_forecasts', 'station_id');
|
|
pgm.createIndex('weather_forecasts', 'forecast_time');
|
|
};
|
|
|
|
/**
|
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
|
* @param run {() => void | undefined}
|
|
* @returns {Promise<void> | void}
|
|
*/
|
|
export const down = (pgm) => {
|
|
pgm.dropTable('weather_forecasts');
|
|
pgm.dropTable('weather_stations');
|
|
};
|