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