024_createAlertHandleLogsTable.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
  2. import { DeleteStatus, EnableStatus} from "../../client/share/types.ts";
  3. // 告警处理记录表迁移
  4. const createAlertHandleLogsTable: MigrationLiveDefinition = {
  5. name: 'create_alert_handle_logs_table',
  6. up: async (api) => {
  7. await api.schema.createTable('alert_handle_logs', (table) => {
  8. table.increments('id').primary();
  9. table.integer('alert_id').unsigned().comment('关联的告警ID')
  10. .references('id').inTable('device_alerts').onDelete('CASCADE');
  11. table.integer('handler_id').unsigned().comment('处理人ID')
  12. .references('id').inTable('users').onDelete('SET NULL');
  13. table.string('handle_type').comment('处理类型');
  14. table.string('problem_type').comment('问题类型');
  15. table.text('handle_result').nullable().comment('处理结果');
  16. table.jsonb('attachments').nullable().comment('附件列表');
  17. table.integer('notify_disabled').defaultTo(0).comment('是否禁用通知 (0否 1是)');
  18. table.jsonb('notify_items').nullable().comment('禁用的通知项配置');
  19. table.timestamp('handle_time').comment('处理时间');
  20. table.integer('is_deleted').defaultTo(DeleteStatus.NOT_DELETED).comment('是否删除 (0否 1是)');
  21. table.timestamps(true, true);
  22. // 添加索引
  23. table.index('alert_id');
  24. table.index('handler_id');
  25. table.index('handle_type');
  26. table.index('problem_type');
  27. table.index('handle_time');
  28. table.index('is_deleted');
  29. });
  30. },
  31. down: async (api) => {
  32. await api.schema.dropTable('alert_handle_logs');
  33. }
  34. };
  35. export default createAlertHandleLogsTable