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 = {}) {
|
||||
const { migrate = true } = options;
|
||||
console.log({migrate})
|
||||
if (migrate) {
|
||||
await model.migrate(options);
|
||||
await model.migrate({...options, isNewRecord: true});
|
||||
}
|
||||
await model.updateAssociations(defaultValues, options);
|
||||
}
|
||||
|
@ -86,7 +86,10 @@ export class CollectionModel extends BaseModel {
|
||||
* 迁移
|
||||
*/
|
||||
async migrate(options: MigrateOptions = {}) {
|
||||
const { isNewRecord } = options;
|
||||
const table = await this.loadTableOptions(options);
|
||||
// 如果不是新增数据,force 必须为 false
|
||||
if (!isNewRecord) {
|
||||
return await table.sync({
|
||||
force: false,
|
||||
alter: {
|
||||
@ -94,6 +97,16 @@ export class CollectionModel extends BaseModel {
|
||||
}
|
||||
});
|
||||
}
|
||||
// TODO: 暂时加了个 collectionSync 解决 collection.create 的数据不清空问题
|
||||
// @ts-ignore
|
||||
const sync = this.sequelize.options.collectionSync;
|
||||
return await table.sync(sync || {
|
||||
force: false,
|
||||
alter: {
|
||||
drop: false,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getFieldsOptions() {
|
||||
const fieldsOptions = [];
|
||||
|
Loading…
Reference in New Issue
Block a user