030_add_workflow_process_fields.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import type { MigrationLiveDefinition } from '@d8d-appcontainer/types'
  2. const addWorkflowProcessFields: MigrationLiveDefinition = {
  3. name: 'add_workflow_process_fields',
  4. up: async (api) => {
  5. await api.schema.alterTable('work_orders', (table) => {
  6. table.integer('assignee_id').unsigned().nullable()
  7. .references('id').inTable('users').onDelete('SET NULL')
  8. .comment('派工人ID');
  9. table.timestamp('assign_time').nullable().comment('派工时间');
  10. table.integer('reassignee_id').unsigned().nullable()
  11. .references('id').inTable('users').onDelete('SET NULL')
  12. .comment('改派人ID');
  13. table.timestamp('reassign_time').nullable().comment('改派时间');
  14. table.integer('closer_id').unsigned().nullable()
  15. .references('id').inTable('users').onDelete('SET NULL')
  16. .comment('关闭人ID');
  17. table.timestamp('close_time').nullable().comment('关闭时间');
  18. table.timestamp('complete_time').nullable().comment('完成时间');
  19. });
  20. await api.schema.createTable('work_order_process_history', (table) => {
  21. table.increments('id').primary();
  22. table.integer('work_order_id').unsigned().notNullable()
  23. .references('id').inTable('work_orders').onDelete('CASCADE');
  24. table.string('action_type').notNullable().comment('操作类型: assign/reassign/close');
  25. table.integer('operator_id').unsigned().notNullable()
  26. .references('id').inTable('users');
  27. table.timestamp('operate_time').notNullable();
  28. table.text('comment').nullable();
  29. });
  30. },
  31. down: async (api) => {
  32. await api.schema.alterTable('work_orders', (table) => {
  33. table.dropColumn('assignee_id');
  34. table.dropColumn('assign_time');
  35. table.dropColumn('reassignee_id');
  36. table.dropColumn('reassign_time');
  37. table.dropColumn('closer_id');
  38. table.dropColumn('close_time');
  39. table.dropColumn('complete_time');
  40. });
  41. await api.schema.dropTable('work_order_process_history');
  42. }
  43. };
  44. export default addWorkflowProcessFields;