mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:36:05 +00:00
fix: add transaction to migrate options
This commit is contained in:
parent
276d218357
commit
a44bab62fc
@ -2,6 +2,11 @@ import CollectionModel from '../models/collection';
|
||||
|
||||
const defaultValues = {
|
||||
actions: [
|
||||
{
|
||||
type: 'filter',
|
||||
name: 'filter',
|
||||
title: '筛选',
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'list',
|
||||
@ -55,7 +60,7 @@ const defaultValues = {
|
||||
name: 'table',
|
||||
title: '列表',
|
||||
template: 'Table',
|
||||
actionNames: ['create', 'destroy'],
|
||||
actionNames: ['filter', 'create', 'destroy'],
|
||||
default: true,
|
||||
},
|
||||
],
|
||||
@ -73,7 +78,7 @@ const defaultValues = {
|
||||
export default async function (model: CollectionModel, options: any = {}) {
|
||||
const { migrate = true } = options;
|
||||
if (migrate) {
|
||||
await model.migrate();
|
||||
await model.migrate(options);
|
||||
}
|
||||
await model.updateAssociations(defaultValues, options);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export default async function (options: any = {}) {
|
||||
transaction,
|
||||
});
|
||||
for (const field of fields) {
|
||||
await field.migrate();
|
||||
await field.migrate(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,6 @@ import FieldModel from '../models/field';
|
||||
export default async function (model: FieldModel, options: any = {}) {
|
||||
const { migrate = true } = options;
|
||||
if (migrate) {
|
||||
await model.migrate();
|
||||
await model.migrate(options);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ export const string = {
|
||||
options: {
|
||||
interface: 'string',
|
||||
type: 'string',
|
||||
filterable: true,
|
||||
component: {
|
||||
type: 'string',
|
||||
},
|
||||
|
@ -74,6 +74,7 @@ export class CollectionModel extends BaseModel {
|
||||
}
|
||||
if (associationTableNames.length) {
|
||||
await CollectionModel.load({
|
||||
...opts,
|
||||
where: {
|
||||
name: {
|
||||
[Op.in]: associationTableNames,
|
||||
@ -88,7 +89,7 @@ export class CollectionModel extends BaseModel {
|
||||
* 迁移
|
||||
*/
|
||||
async migrate(options: MigrateOptions = {}) {
|
||||
const table = await this.loadTableOptions();
|
||||
const table = await this.loadTableOptions(options);
|
||||
return await table.sync({
|
||||
force: false,
|
||||
alter: {
|
||||
@ -121,12 +122,14 @@ export class CollectionModel extends BaseModel {
|
||||
* @param options
|
||||
*/
|
||||
static async load(options: LoadOptions = {}) {
|
||||
const { reset = false, where = {} } = options;
|
||||
const { reset = false, where = {}, transaction } = options;
|
||||
const collections = await this.findAll({
|
||||
transaction,
|
||||
where,
|
||||
});
|
||||
for (const collection of collections) {
|
||||
await collection.loadTableOptions({
|
||||
transaction,
|
||||
reset,
|
||||
});
|
||||
}
|
||||
|
@ -35,11 +35,12 @@ export class FieldModel extends BaseModel {
|
||||
};
|
||||
}
|
||||
|
||||
async migrate() {
|
||||
if (!this.get('collection_name')) {
|
||||
async migrate(options: any = {}) {
|
||||
const collectionName = this.get('collection_name');
|
||||
if (!collectionName) {
|
||||
return false;
|
||||
}
|
||||
const table = this.database.getTable(this.get('collection_name'));
|
||||
const table = this.database.getTable(collectionName);
|
||||
table.addField(await this.getOptions());
|
||||
await table.sync({
|
||||
force: false,
|
||||
|
Loading…
Reference in New Issue
Block a user