From 87ecc7642baaaee0a64661f054a2ca62b43b1dcf Mon Sep 17 00:00:00 2001 From: Misha Kaletsky <15040698+mmkal@users.noreply.github.com> Date: Fri, 12 Aug 2022 20:03:16 +0200 Subject: [PATCH] refactor(sequelize): move this.model.sync() to an overridable method (#564) Co-authored-by: Misha Kaletsky --- src/storage/sequelize.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/storage/sequelize.ts b/src/storage/sequelize.ts index ae6742f3..7198c264 100644 --- a/src/storage/sequelize.ts +++ b/src/storage/sequelize.ts @@ -148,15 +148,19 @@ export class SequelizeStorage implements UmzugStorage { ) as ModelClassType; } - async logMigration({ name: migrationName }: { name: string }): Promise { + protected async syncModel() { await this.model.sync(); + } + + async logMigration({ name: migrationName }: { name: string }): Promise { + await this.syncModel(); await this.model.create({ [this.columnName]: migrationName, }); } async unlogMigration({ name: migrationName }: { name: string }): Promise { - await this.model.sync(); + await this.syncModel(); await this.model.destroy({ where: { [this.columnName]: migrationName, @@ -165,7 +169,7 @@ export class SequelizeStorage implements UmzugStorage { } async executed(): Promise { - 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];