fix(database): refresh indexes (#1127)
This commit is contained in:
parent
3556ddc730
commit
7bffc94b80
@ -7,7 +7,7 @@ import {
|
||||
QueryInterfaceDropTableOptions,
|
||||
SyncOptions,
|
||||
Transactionable,
|
||||
Utils,
|
||||
Utils
|
||||
} from 'sequelize';
|
||||
import { Database } from './database';
|
||||
import { Field, FieldOptions } from './fields';
|
||||
@ -379,6 +379,7 @@ export class Collection<
|
||||
}
|
||||
return item;
|
||||
});
|
||||
this.refreshIndexes();
|
||||
}
|
||||
|
||||
removeIndex(fields: any) {
|
||||
@ -391,6 +392,21 @@ export class Collection<
|
||||
this.model._indexes = indexes.filter((item) => {
|
||||
return !lodash.isEqual(item.fields, fields);
|
||||
});
|
||||
this.refreshIndexes();
|
||||
}
|
||||
|
||||
refreshIndexes() {
|
||||
// @ts-ignore
|
||||
const indexes: any[] = this.model._indexes;
|
||||
// @ts-ignore
|
||||
this.model._indexes = indexes.filter((item) => {
|
||||
for (const field of item.fields) {
|
||||
if (!this.model.rawAttributes[field]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
async sync(syncOptions?: SyncOptions) {
|
||||
|
Loading…
Reference in New Issue
Block a user