mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
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:
parent
26d858ae18
commit
dbb079ba18
@ -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;
|
||||||
|
|
@ -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();
|
||||||
|
|
@ -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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user