From 22869ca18440f42bd9cc9b9bd3a4b3239beafa54 Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 26 Feb 2025 20:08:35 +0800 Subject: [PATCH] fix(plugin-file-manager): fix migration for inherited collection (#6310) --- .../core/database/src/inherited-collection.ts | 4 ++ .../20250225225034-increase-url-length.ts | 37 ++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/core/database/src/inherited-collection.ts b/packages/core/database/src/inherited-collection.ts index 7726dc8086..4705b2b32b 100644 --- a/packages/core/database/src/inherited-collection.ts +++ b/packages/core/database/src/inherited-collection.ts @@ -65,6 +65,10 @@ export class InheritedCollection extends Collection { parentFields() { const fields = new Map(); + if (!this.parents) { + return fields; + } + for (const parent of this.parents) { if (parent.isInherited()) { for (const [name, field] of (parent).parentFields()) { diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/server/migrations/20250225225034-increase-url-length.ts b/packages/plugins/@nocobase/plugin-file-manager/src/server/migrations/20250225225034-increase-url-length.ts index a8b4671c7d..1d76edeaa2 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/server/migrations/20250225225034-increase-url-length.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/server/migrations/20250225225034-increase-url-length.ts @@ -10,6 +10,7 @@ import { DataTypes } from 'sequelize'; import { Migration } from '@nocobase/server'; import { CollectionRepository } from '@nocobase/plugin-data-source-main'; +import { InheritedCollection } from '@nocobase/database'; export default class extends Migration { on = 'afterLoad'; // 'beforeLoad' or 'afterLoad' @@ -31,23 +32,25 @@ export default class extends Migration { await this.db.sequelize.transaction(async (transaction) => { for (const collection of collections) { - const tableName = collection.getTableNameWithSchema(); - await queryInterface.changeColumn( - tableName, - 'url', - { - type: DataTypes.TEXT, - }, - { transaction }, - ); - await queryInterface.changeColumn( - tableName, - 'path', - { - type: DataTypes.TEXT, - }, - { transaction }, - ); + if (!(collection instanceof InheritedCollection)) { + const tableName = collection.getTableNameWithSchema(); + await queryInterface.changeColumn( + tableName, + 'url', + { + type: DataTypes.TEXT, + }, + { transaction }, + ); + await queryInterface.changeColumn( + tableName, + 'path', + { + type: DataTypes.TEXT, + }, + { transaction }, + ); + } await FieldRepo.update({ filter: {