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 e3e233b430..371e22af9d 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 @@ -7,10 +7,10 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -import { Migration } from '@nocobase/server'; import { Model, SyncOptions } from '@nocobase/database'; -import { Transaction } from 'sequelize'; +import { Migration } from '@nocobase/server'; import lodash from 'lodash'; +import { Transaction } from 'sequelize'; export default class extends Migration { on = 'afterLoad'; // 'beforeLoad' or 'afterLoad' @@ -30,6 +30,7 @@ export default class extends Migration { const name = `main_${treeCollection.name}_path`; this.app.db.collection({ name, + schema: treeCollection.options.schema, autoGenId: false, timestamps: false, fields: [ @@ -48,6 +49,7 @@ export default class extends Migration { await this.app.db.getCollection(name).sync({ transaction } as SyncOptions); this.app.db.collection({ name: treeCollection.name, + schema: treeCollection.options.schema, autoGenId: false, timestamps: false, fields: [ diff --git a/packages/plugins/@nocobase/plugin-collection-tree/src/server/plugin.ts b/packages/plugins/@nocobase/plugin-collection-tree/src/server/plugin.ts index 93faf0f44d..7fce8610e4 100644 --- a/packages/plugins/@nocobase/plugin-collection-tree/src/server/plugin.ts +++ b/packages/plugins/@nocobase/plugin-collection-tree/src/server/plugin.ts @@ -7,11 +7,11 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -import { Plugin } from '@nocobase/server'; -import { Collection, Model, SyncOptions, DestroyOptions } from '@nocobase/database'; import { DataSource, SequelizeCollectionManager } from '@nocobase/data-source-manager'; -import { Transaction } from 'sequelize'; +import { Collection, DestroyOptions, Model, SyncOptions } from '@nocobase/database'; +import { Plugin } from '@nocobase/server'; import lodash from 'lodash'; +import { Transaction } from 'sequelize'; import { TreeCollection } from './tree-collection'; const getFilterTargetKey = (model: Model) => { @@ -40,7 +40,11 @@ class PluginCollectionTreeServer extends Plugin { const parentForeignKey = collection.treeParentField?.foreignKey || 'parentId'; //always define tree path collection - this.defineTreePathCollection(name); + const options = {}; + if (collection.options.schema) { + options['schema'] = collection.options.schema; + } + this.defineTreePathCollection(name, options); //afterSync collectionManager.db.on(`${collection.name}.afterSync`, async ({ transaction }) => { @@ -134,7 +138,7 @@ class PluginCollectionTreeServer extends Plugin { }); } - private async defineTreePathCollection(name: string) { + private async defineTreePathCollection(name: string, options: { schema?: string }) { this.db.collection({ name, autoGenId: false, @@ -149,6 +153,7 @@ class PluginCollectionTreeServer extends Plugin { fields: [{ name: 'path', length: 191 }], }, ], + ...options, }); }