From c985522fa35ccc402a063bc2b679d3bed4b30e74 Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Mon, 24 Mar 2025 16:46:40 +0800 Subject: [PATCH] fix(collection-tree): migration issue (#6537) * fix(collection-tree): migration issue * fix: bug --- .../20240802141435-collection-tree.ts | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-collection-tree/src/server/migrations/20240802141435-collection-tree.ts b/packages/plugins/@nocobase/plugin-collection-tree/src/server/migrations/20240802141435-collection-tree.ts index 61772f45ab..27def98812 100644 --- a/packages/plugins/@nocobase/plugin-collection-tree/src/server/migrations/20240802141435-collection-tree.ts +++ b/packages/plugins/@nocobase/plugin-collection-tree/src/server/migrations/20240802141435-collection-tree.ts @@ -31,6 +31,8 @@ export default class extends Migration { await this.db.sequelize.transaction(async (transaction) => { const treeCollections = await this.getTreeCollections({ transaction }); for (const treeCollection of treeCollections) { + await treeCollection.load({ transaction }); + const name = `main_${treeCollection.name}_path`; const collectionOptions = { name, @@ -47,35 +49,16 @@ export default class extends Migration { }, ], }; - const collectionInstance = this.db.getCollection(treeCollection.name); const treeCollectionSchema = collectionInstance.collectionSchema(); - if (this.app.db.inDialect('postgres') && treeCollectionSchema != this.app.db.options.schema) { collectionOptions['schema'] = treeCollectionSchema; } - this.app.db.collection(collectionOptions); const treeExistsInDb = await this.app.db.getCollection(name).existsInDb({ transaction }); - if (!treeExistsInDb) { await this.app.db.getCollection(name).sync({ transaction } as SyncOptions); - const opts = { - name: treeCollection.name, - autoGenId: false, - timestamps: false, - fields: [ - { type: 'integer', name: 'id' }, - { type: 'integer', name: 'parentId' }, - ], - }; - - if (treeCollectionSchema != this.app.db.options.schema) { - opts['schema'] = treeCollectionSchema; - } - - this.app.db.collection(opts); const chunkSize = 1000; await this.app.db.getRepository(treeCollection.name).chunk({ chunkSize: chunkSize,