mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:15:36 +00:00
add collectionSync parameter for database options
This commit is contained in:
parent
8289f96dd5
commit
b878b214d4
@ -77,8 +77,9 @@ 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;
|
||||||
|
console.log({migrate})
|
||||||
if (migrate) {
|
if (migrate) {
|
||||||
await model.migrate(options);
|
await model.migrate({...options, isNewRecord: true});
|
||||||
}
|
}
|
||||||
await model.updateAssociations(defaultValues, options);
|
await model.updateAssociations(defaultValues, options);
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,21 @@ export class CollectionModel extends BaseModel {
|
|||||||
* 迁移
|
* 迁移
|
||||||
*/
|
*/
|
||||||
async migrate(options: MigrateOptions = {}) {
|
async migrate(options: MigrateOptions = {}) {
|
||||||
|
const { isNewRecord } = options;
|
||||||
const table = await this.loadTableOptions(options);
|
const table = await this.loadTableOptions(options);
|
||||||
return await table.sync({
|
// 如果不是新增数据,force 必须为 false
|
||||||
|
if (!isNewRecord) {
|
||||||
|
return await table.sync({
|
||||||
|
force: false,
|
||||||
|
alter: {
|
||||||
|
drop: false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// TODO: 暂时加了个 collectionSync 解决 collection.create 的数据不清空问题
|
||||||
|
// @ts-ignore
|
||||||
|
const sync = this.sequelize.options.collectionSync;
|
||||||
|
return await table.sync(sync || {
|
||||||
force: false,
|
force: false,
|
||||||
alter: {
|
alter: {
|
||||||
drop: false,
|
drop: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user