mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
chore: remove collection schema options (#6129)
* chore: remove schema options in collections * chore: test * chore: unset schema option * chore: test * chore: test * fix: test --------- Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
554cad3353
commit
3a568b87c1
@ -0,0 +1,41 @@
|
|||||||
|
import { Database, MigrationContext } from '@nocobase/database';
|
||||||
|
|
||||||
|
import { MockServer } from '@nocobase/test';
|
||||||
|
import { createApp } from '../index';
|
||||||
|
|
||||||
|
import Migrator from '../../migrations/20250123000001-remove-schema-options';
|
||||||
|
describe.runIf(process.env.DB_DIALECT === 'postgres')('remove schema options', () => {
|
||||||
|
let app: MockServer;
|
||||||
|
let db: Database;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
app = await createApp({});
|
||||||
|
db = app.db;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await app.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove schema options', async () => {
|
||||||
|
await db.getRepository('collections').create({
|
||||||
|
values: {
|
||||||
|
name: 'test',
|
||||||
|
from: 'db2cm',
|
||||||
|
schema: db.options.schema || 'public',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const migration = new Migrator({ db } as MigrationContext);
|
||||||
|
migration.context.app = app;
|
||||||
|
await migration.up();
|
||||||
|
|
||||||
|
const collection = await db.getRepository('collections').findOne({
|
||||||
|
filter: {
|
||||||
|
'options.from': 'db2cm',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(collection?.get('schema')).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* This file is part of the NocoBase (R) project.
|
||||||
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||||
|
* Authors: NocoBase Team.
|
||||||
|
*
|
||||||
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||||
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* istanbul ignore file -- @preserve */
|
||||||
|
|
||||||
|
import { Migration } from '@nocobase/server';
|
||||||
|
|
||||||
|
export default class extends Migration {
|
||||||
|
on = 'afterLoad';
|
||||||
|
|
||||||
|
async up() {
|
||||||
|
const CollectionRepository = this.context.db.getRepository('collections');
|
||||||
|
const collections = await CollectionRepository.find({
|
||||||
|
filter: {
|
||||||
|
'options.from': 'db2cm',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const collection of collections) {
|
||||||
|
const collectionSchema = collection.get('schema');
|
||||||
|
const dbSchema = this.context.db.options.schema || 'public';
|
||||||
|
if (collectionSchema && collectionSchema == dbSchema) {
|
||||||
|
collection.set('schema', undefined);
|
||||||
|
await collection.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -186,9 +186,15 @@ export class CollectionRepository extends Repository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const collectionOptions = options;
|
||||||
|
|
||||||
|
if (collectionOptions.schema && collectionOptions.schema == (this.database.options.schema || 'public')) {
|
||||||
|
delete collectionOptions.schema;
|
||||||
|
}
|
||||||
|
|
||||||
await this.create({
|
await this.create({
|
||||||
values: {
|
values: {
|
||||||
...options,
|
...collectionOptions,
|
||||||
fields,
|
fields,
|
||||||
from: 'db2cm',
|
from: 'db2cm',
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user