mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
fix(collection-tree): migration issue (#6537)
* fix(collection-tree): migration issue * fix: bug
This commit is contained in:
parent
a3c941178f
commit
c985522fa3
@ -31,6 +31,8 @@ export default class extends Migration {
|
|||||||
await this.db.sequelize.transaction(async (transaction) => {
|
await this.db.sequelize.transaction(async (transaction) => {
|
||||||
const treeCollections = await this.getTreeCollections({ transaction });
|
const treeCollections = await this.getTreeCollections({ transaction });
|
||||||
for (const treeCollection of treeCollections) {
|
for (const treeCollection of treeCollections) {
|
||||||
|
await treeCollection.load({ transaction });
|
||||||
|
|
||||||
const name = `main_${treeCollection.name}_path`;
|
const name = `main_${treeCollection.name}_path`;
|
||||||
const collectionOptions = {
|
const collectionOptions = {
|
||||||
name,
|
name,
|
||||||
@ -47,35 +49,16 @@ export default class extends Migration {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const collectionInstance = this.db.getCollection(treeCollection.name);
|
const collectionInstance = this.db.getCollection(treeCollection.name);
|
||||||
const treeCollectionSchema = collectionInstance.collectionSchema();
|
const treeCollectionSchema = collectionInstance.collectionSchema();
|
||||||
|
|
||||||
if (this.app.db.inDialect('postgres') && treeCollectionSchema != this.app.db.options.schema) {
|
if (this.app.db.inDialect('postgres') && treeCollectionSchema != this.app.db.options.schema) {
|
||||||
collectionOptions['schema'] = treeCollectionSchema;
|
collectionOptions['schema'] = treeCollectionSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.db.collection(collectionOptions);
|
this.app.db.collection(collectionOptions);
|
||||||
|
|
||||||
const treeExistsInDb = await this.app.db.getCollection(name).existsInDb({ transaction });
|
const treeExistsInDb = await this.app.db.getCollection(name).existsInDb({ transaction });
|
||||||
|
|
||||||
if (!treeExistsInDb) {
|
if (!treeExistsInDb) {
|
||||||
await this.app.db.getCollection(name).sync({ transaction } as SyncOptions);
|
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;
|
const chunkSize = 1000;
|
||||||
await this.app.db.getRepository(treeCollection.name).chunk({
|
await this.app.db.getRepository(treeCollection.name).chunk({
|
||||||
chunkSize: chunkSize,
|
chunkSize: chunkSize,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user