diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250312100513-change-table-name.test.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250316100513-change-table-name.test.ts similarity index 99% rename from packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250312100513-change-table-name.test.ts rename to packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250316100513-change-table-name.test.ts index d13adf718b..3b86ad4c17 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250312100513-change-table-name.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250316100513-change-table-name.test.ts @@ -10,7 +10,7 @@ import { createMockServer } from '@nocobase/test'; import { describe, test } from 'vitest'; import workflowManualTasks from '../../collections/workflowManualTasks'; -import Migration from '../../migrations/20250312100513-change-table-name'; +import Migration from '../../migrations/20250316100513-change-table-name'; const skipSqlite = process.env.DB_DIALECT === 'sqlite' ? test.skip : test; diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250316181621-remove-m2m-fields.test.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250317121621-remove-m2m-fields.test.ts similarity index 70% rename from packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250316181621-remove-m2m-fields.test.ts rename to packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250317121621-remove-m2m-fields.test.ts index 3a4ade23f3..971ccb46fe 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250316181621-remove-m2m-fields.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/migrations/20250317121621-remove-m2m-fields.test.ts @@ -11,7 +11,7 @@ import { createMockServer } from '@nocobase/test'; import { describe, test } from 'vitest'; import workflowManualTasks from '../../collections/workflowManualTasks'; -import Migration from '../../migrations/20250316181621-remove-m2m-fields'; +import Migration from '../../migrations/20250317121621-remove-m2m-fields'; describe('20250225175712-change-table-name.test', () => { test(`old table and fields should not exist after migrated with fields removed`, async () => { @@ -30,10 +30,44 @@ describe('20250225175712-change-table-name.test', () => { }, ], }); - + const usersCollection = app.db.collection({ + name: 'users', + fields: [ + { + name: 'jobs', + type: 'belongsToMany', + }, + { + name: 'usersJobs', + type: 'hasMany', + }, + ], + }); + const jobsCollection = app.db.collection({ + name: 'jobs', + fields: [ + { + name: 'users', + type: 'belongsToMany', + }, + { + name: 'usersJobs', + type: 'hasMany', + }, + ], + }); const oldCollection = app.db.collection({ - ...workflowManualTasks, name: 'users_jobs', + fields: [ + { + name: 'jobs', + type: 'belongsTo', + }, + { + name: 'users', + type: 'belongsTo', + }, + ], }); await app.db.sync(); diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250312100513-change-table-name.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250316100513-change-table-name.ts similarity index 100% rename from packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250312100513-change-table-name.ts rename to packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250316100513-change-table-name.ts diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250316181621-remove-m2m-fields.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250317121621-remove-m2m-fields.ts similarity index 78% rename from packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250316181621-remove-m2m-fields.ts rename to packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250317121621-remove-m2m-fields.ts index 37120b5241..532e9dfa5f 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250316181621-remove-m2m-fields.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/migrations/20250317121621-remove-m2m-fields.ts @@ -57,7 +57,16 @@ export default class extends Migration { }); if (oldTableExists) { - await db.sequelize.getQueryInterface().dropTable(usersJobsCollection.getTableNameWithSchema(), { transaction }); + const oldColumns = await db.sequelize + .getQueryInterface() + .describeTable(usersJobsCollection.getTableNameWithSchema()); + if (!oldColumns.status) { + await db.sequelize + .getQueryInterface() + .dropTable(usersJobsCollection.getTableNameWithSchema(), { transaction }); + } else { + throw new Error('users_jobs table is not migrated properly, please contact support.'); + } } });