| 123456789101112131415161718192021222324252627282930313233343536 |
- import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
- import { DeleteStatus } from "../../client/share/types.ts";
- import { AlertStatus } from "../../client/share/monitorTypes.ts";
- // 设备告警记录表迁移
- const createDeviceAlertsTable: MigrationLiveDefinition = {
- name: 'create_device_alerts_table',
- up: async (api) => {
- await api.schema.createTable('device_alerts', (table) => {
- table.increments('id').primary();
- table.integer('device_id').unsigned().comment('关联的设备ID')
- .references('id').inTable('device_instances').onDelete('CASCADE');
- table.string('device_name').comment('设备名称');
- table.string('metric_type').comment('监控指标类型');
- table.decimal('metric_value', 10, 2).comment('触发值');
- table.integer('alert_level').comment('告警等级');
- table.string('alert_message').comment('告警消息');
- table.string('status').defaultTo(AlertStatus.PENDING).comment('状态');
- table.integer('is_deleted').defaultTo(DeleteStatus.NOT_DELETED).comment('是否删除 (0否 1是)');
- table.timestamps(true, true);
-
- // 添加索引
- table.index('device_id');
- table.index('metric_type');
- table.index('alert_level');
- table.index('status');
- table.index('is_deleted');
- table.index('created_at');
- });
- },
- down: async (api) => {
- await api.schema.dropTable('device_alerts');
- }
- };
- export default createDeviceAlertsTable
|