Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-08-26 10:06:21 +00:00
commit 7327aa347b
2 changed files with 14 additions and 7 deletions

View File

@ -7,10 +7,10 @@
* For more information, please refer to: https://www.nocobase.com/agreement. * For more information, please refer to: https://www.nocobase.com/agreement.
*/ */
import { Migration } from '@nocobase/server';
import { Model, SyncOptions } from '@nocobase/database'; import { Model, SyncOptions } from '@nocobase/database';
import { Transaction } from 'sequelize'; import { Migration } from '@nocobase/server';
import lodash from 'lodash'; import lodash from 'lodash';
import { Transaction } from 'sequelize';
export default class extends Migration { export default class extends Migration {
on = 'afterLoad'; // 'beforeLoad' or 'afterLoad' on = 'afterLoad'; // 'beforeLoad' or 'afterLoad'
@ -30,6 +30,7 @@ export default class extends Migration {
const name = `main_${treeCollection.name}_path`; const name = `main_${treeCollection.name}_path`;
this.app.db.collection({ this.app.db.collection({
name, name,
schema: treeCollection.options.schema,
autoGenId: false, autoGenId: false,
timestamps: false, timestamps: false,
fields: [ fields: [
@ -48,6 +49,7 @@ export default class extends Migration {
await this.app.db.getCollection(name).sync({ transaction } as SyncOptions); await this.app.db.getCollection(name).sync({ transaction } as SyncOptions);
this.app.db.collection({ this.app.db.collection({
name: treeCollection.name, name: treeCollection.name,
schema: treeCollection.options.schema,
autoGenId: false, autoGenId: false,
timestamps: false, timestamps: false,
fields: [ fields: [

View File

@ -7,11 +7,11 @@
* For more information, please refer to: https://www.nocobase.com/agreement. * 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 { 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 lodash from 'lodash';
import { Transaction } from 'sequelize';
import { TreeCollection } from './tree-collection'; import { TreeCollection } from './tree-collection';
const getFilterTargetKey = (model: Model) => { const getFilterTargetKey = (model: Model) => {
@ -40,7 +40,11 @@ class PluginCollectionTreeServer extends Plugin {
const parentForeignKey = collection.treeParentField?.foreignKey || 'parentId'; const parentForeignKey = collection.treeParentField?.foreignKey || 'parentId';
//always define tree path collection //always define tree path collection
this.defineTreePathCollection(name); const options = {};
if (collection.options.schema) {
options['schema'] = collection.options.schema;
}
this.defineTreePathCollection(name, options);
//afterSync //afterSync
collectionManager.db.on(`${collection.name}.afterSync`, async ({ transaction }) => { 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({ this.db.collection({
name, name,
autoGenId: false, autoGenId: false,
@ -149,6 +153,7 @@ class PluginCollectionTreeServer extends Plugin {
fields: [{ name: 'path', length: 191 }], fields: [{ name: 'path', length: 191 }],
}, },
], ],
...options,
}); });
} }