Skip to content

Commit

Permalink
refactor(sequelize): move this.model.sync() to an overridable method (#…
Browse files Browse the repository at this point in the history
…564)

Co-authored-by: Misha Kaletsky <[email protected]>
  • Loading branch information
mmkal and mmkal authored Aug 12, 2022
1 parent 1dc7723 commit 87ecc76
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/storage/sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,19 @@ export class SequelizeStorage implements UmzugStorage {
) as ModelClassType;
}

async logMigration({ name: migrationName }: { name: string }): Promise<void> {
protected async syncModel() {
await this.model.sync();
}

async logMigration({ name: migrationName }: { name: string }): Promise<void> {
await this.syncModel();
await this.model.create({
[this.columnName]: migrationName,
});
}

async unlogMigration({ name: migrationName }: { name: string }): Promise<void> {
await this.model.sync();
await this.syncModel();
await this.model.destroy({
where: {
[this.columnName]: migrationName,
Expand All @@ -165,7 +169,7 @@ export class SequelizeStorage implements UmzugStorage {
}

async executed(): Promise<string[]> {
await this.model.sync();
await this.syncModel();
const migrations: any[] = await this.model.findAll({ order: [[this.columnName, 'ASC']] });
return migrations.map(migration => {
const name = migration[this.columnName];
Expand Down

0 comments on commit 87ecc76

Please sign in to comment.