import type { MigrationLiveDefinition } from '@d8d-appcontainer/types' const addWorkflowProcessFields: MigrationLiveDefinition = { name: 'add_workflow_process_fields', up: async (api) => { await api.schema.alterTable('work_orders', (table) => { table.integer('assignee_id').unsigned().nullable() .references('id').inTable('users').onDelete('SET NULL') .comment('派工人ID'); table.timestamp('assign_time').nullable().comment('派工时间'); table.integer('reassignee_id').unsigned().nullable() .references('id').inTable('users').onDelete('SET NULL') .comment('改派人ID'); table.timestamp('reassign_time').nullable().comment('改派时间'); table.integer('closer_id').unsigned().nullable() .references('id').inTable('users').onDelete('SET NULL') .comment('关闭人ID'); table.timestamp('close_time').nullable().comment('关闭时间'); table.timestamp('complete_time').nullable().comment('完成时间'); }); await api.schema.createTable('work_order_process_history', (table) => { table.increments('id').primary(); table.integer('work_order_id').unsigned().notNullable() .references('id').inTable('work_orders').onDelete('CASCADE'); table.string('action_type').notNullable().comment('操作类型: assign/reassign/close'); table.integer('operator_id').unsigned().notNullable() .references('id').inTable('users'); table.timestamp('operate_time').notNullable(); table.text('comment').nullable(); }); }, down: async (api) => { await api.schema.alterTable('work_orders', (table) => { table.dropColumn('assignee_id'); table.dropColumn('assign_time'); table.dropColumn('reassignee_id'); table.dropColumn('reassign_time'); table.dropColumn('closer_id'); table.dropColumn('close_time'); table.dropColumn('complete_time'); }); await api.schema.dropTable('work_order_process_history'); } }; export default addWorkflowProcessFields;