fix(plugin-file-manager): fix migration for inherited collection (#6310)

This commit is contained in:
Junyi 2025-02-26 20:08:35 +08:00 committed by GitHub
parent 414ec3c817
commit 22869ca184
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 17 deletions

View File

@ -65,6 +65,10 @@ export class InheritedCollection extends Collection {
parentFields() {
const fields = new Map<string, Field>();
if (!this.parents) {
return fields;
}
for (const parent of this.parents) {
if (parent.isInherited()) {
for (const [name, field] of (<InheritedCollection>parent).parentFields()) {

View File

@ -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: {