fix(plugin-workflow-manual): fix migration (#6487)

* fix(plugin-workflow-manual): fix migration

* fix(plugin-workflow-manual): fix test cases
This commit is contained in:
Junyi 2025-03-17 16:00:48 +08:00 committed by GitHub
parent 26d858ae18
commit dbb079ba18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 5 deletions

View File

@ -10,7 +10,7 @@
import { createMockServer } from '@nocobase/test'; import { createMockServer } from '@nocobase/test';
import { describe, test } from 'vitest'; import { describe, test } from 'vitest';
import workflowManualTasks from '../../collections/workflowManualTasks'; 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; const skipSqlite = process.env.DB_DIALECT === 'sqlite' ? test.skip : test;

View File

@ -11,7 +11,7 @@ import { createMockServer } from '@nocobase/test';
import { describe, test } from 'vitest'; import { describe, test } from 'vitest';
import workflowManualTasks from '../../collections/workflowManualTasks'; 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', () => { describe('20250225175712-change-table-name.test', () => {
test(`old table and fields should not exist after migrated with fields removed`, async () => { 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({ const oldCollection = app.db.collection({
...workflowManualTasks,
name: 'users_jobs', name: 'users_jobs',
fields: [
{
name: 'jobs',
type: 'belongsTo',
},
{
name: 'users',
type: 'belongsTo',
},
],
}); });
await app.db.sync(); await app.db.sync();

View File

@ -57,7 +57,16 @@ export default class extends Migration {
}); });
if (oldTableExists) { 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.');
}
} }
}); });