import type { MigrationLiveDefinition } from '@d8d-appcontainer/types' import { DeleteStatus, EnableStatus} from "../../client/share/types.ts"; // 告警通知配置表迁移 const createAlertNotifyConfigsTable: MigrationLiveDefinition = { name: 'create_alert_notify_configs_table', up: async (api) => { await api.schema.createTable('alert_notify_configs', (table) => { table.increments('id').primary(); table.integer('device_id').unsigned().comment('关联的设备ID') .references('id').inTable('device_instances').onDelete('CASCADE'); table.integer('alert_level').comment('告警等级'); table.string('notify_type').comment('通知类型'); table.string('notify_template').nullable().comment('通知模板'); table.jsonb('notify_users').comment('通知用户ID列表'); table.integer('is_enabled').defaultTo(EnableStatus.ENABLED).comment('是否启用 (0否 1是)'); table.integer('is_deleted').defaultTo(DeleteStatus.NOT_DELETED).comment('是否删除 (0否 1是)'); table.timestamps(true, true); // 添加索引 table.index('device_id'); table.index('alert_level'); table.index('notify_type'); table.index('is_enabled'); table.index('is_deleted'); // 同一设备的相同告警级别和通知类型应该是唯一的 // table.unique(['device_id', 'alert_level', 'notify_type', 'is_deleted']); }); }, down: async (api) => { await api.schema.dropTable('alert_notify_configs'); } }; export default createAlertNotifyConfigsTable