mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-05 05:38:23 +08:00
chore(collection-manager): migration - 20221104151410-update-collections-hidden (#1039)
This commit is contained in:
parent
b425ac0413
commit
dd20951323
@ -0,0 +1,47 @@
|
||||
import { Database, MigrationContext, mockDatabase } from '@nocobase/database';
|
||||
import UpdateCollectionsHiddenMigration from '../../migrations/20221104151410-update-collections-hidden';
|
||||
|
||||
import { createApp } from '../index';
|
||||
import { MockServer } from '@nocobase/test';
|
||||
|
||||
describe('migration 20221104151410-update-collections-hidden test', () => {
|
||||
let app: MockServer;
|
||||
let db: Database;
|
||||
|
||||
beforeEach(async () => {
|
||||
app = await createApp();
|
||||
db = app.db;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await app.destroy();
|
||||
});
|
||||
it('20221104151410-update-collections-hidden up method test', async () => {
|
||||
await db.getCollection('collections').model.create({
|
||||
name: 'test',
|
||||
options: {
|
||||
autoCreate: true,
|
||||
isThrough: true,
|
||||
},
|
||||
hidden: false,
|
||||
});
|
||||
|
||||
const result = await db.getRepository('collections').findOne({
|
||||
filter: {
|
||||
name: 'test',
|
||||
},
|
||||
});
|
||||
expect(result.get('hidden')).toBeFalsy();
|
||||
|
||||
const migration = new UpdateCollectionsHiddenMigration({ db } as MigrationContext);
|
||||
migration.context.app = app;
|
||||
await migration.up();
|
||||
|
||||
const upResult = await db.getRepository('collections').findOne({
|
||||
filter: {
|
||||
name: 'test',
|
||||
},
|
||||
});
|
||||
expect(upResult.get('hidden')).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,31 @@
|
||||
import { Migration } from '@nocobase/server';
|
||||
|
||||
export default class UpdateCollectionsHiddenMigration extends Migration {
|
||||
async up() {
|
||||
const result = await this.app.version.satisfies('<=0.8.0-alpha.9');
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
const db = this.app.db;
|
||||
const transaction = await db.sequelize.transaction();
|
||||
try {
|
||||
await db.getRepository('collections').update({
|
||||
filter: {
|
||||
options: {
|
||||
autoCreate: true,
|
||||
isThrough: true,
|
||||
},
|
||||
},
|
||||
values: {
|
||||
hidden: true,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
|
||||
await transaction.commit();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
await transaction.rollback();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user