import type { MigrationLiveDefinition } from '@d8d-appcontainer/types' import { DeleteStatus } from "../../client/share/types.ts"; // 工单相关表迁移 const createWorkOrderTables: MigrationLiveDefinition = { name: 'create_work_order_tables', up: async (api) => { await api.schema.createTable('work_orders', (table) => { table.increments('id').primary(); table.string('title').notNullable().comment('工单标题'); table.text('description').nullable().comment('工单描述'); table.string('status').notNullable().defaultTo('pending').comment('工单状态'); table.string('priority').notNullable().defaultTo('medium').comment('优先级'); table.integer('alert_id').unsigned().nullable().comment('关联的告警ID') .references('id').inTable('device_alerts').onDelete('SET NULL'); table.integer('creator_id').unsigned().notNullable().comment('创建人ID') .references('id').inTable('users').onDelete('CASCADE'); table.integer('assignee_id').unsigned().nullable().comment('当前处理人ID') .references('id').inTable('users').onDelete('SET NULL'); table.integer('previous_assignee_id').unsigned().nullable().comment('上一处理人ID') .references('id').inTable('users').onDelete('SET NULL'); table.timestamps(true, true); table.index('status'); table.index('priority'); table.index('alert_id'); table.index('creator_id'); table.index('assignee_id'); }); await api.schema.createTable('work_order_flows', (table) => { table.increments('id').primary(); table.integer('work_order_id').unsigned().notNullable().comment('关联的工单ID') .references('id').inTable('work_orders').onDelete('CASCADE'); table.string('from_status').notNullable().comment('原状态'); table.string('to_status').notNullable().comment('新状态'); table.integer('operator_id').unsigned().notNullable().comment('操作人ID') .references('id').inTable('users').onDelete('CASCADE'); table.text('comment').nullable().comment('操作备注'); table.timestamps(true, true); table.index('work_order_id'); table.index('operator_id'); table.index(['from_status', 'to_status']); }); await api.schema.createTable('work_order_settings', (table) => { table.increments('id').primary(); table.string('name').notNullable().comment('配置名称'); table.jsonb('flow_config').notNullable().comment('流程配置'); table.timestamps(true, true); table.index('name'); }); }, down: async (api) => { await api.schema.dropTable('work_order_settings'); await api.schema.dropTable('work_order_flows'); await api.schema.dropTable('work_orders'); } }; export default createWorkOrderTables