umzug icon indicating copy to clipboard operation
umzug copied to clipboard

Need to make this.model.sync() before every operation optional for sequelize storage.

Open rusekr opened this issue 2 years ago • 2 comments

Hello!

In my project I'm using umzug in two states - structure migrations and data migrations. Data migrations not requires DB user with ALTER, CREATE TABLE and other structural permissions. But when I'm checking migrations or applying migrations with umzug it starts this.model.sync() method before almost every action and sequelize converts it in "CREATE TABLE IF NOT EXISTS" which errors on DB user without CREATE TABLE permission.

Suggestion to make this "sync" method optional with config option (can't understand why that made by default because syncing table can be used only when initialize in consctructor).

Examples of excess usage of model.sync() method:

https://github.com/sequelize/umzug/blob/30bde8b3f57868f3cfe207cd858c367238d7ca82/src/storage/sequelize.ts#L152 https://github.com/sequelize/umzug/blob/30bde8b3f57868f3cfe207cd858c367238d7ca82/src/storage/sequelize.ts#L159 https://github.com/sequelize/umzug/blob/30bde8b3f57868f3cfe207cd858c367238d7ca82/src/storage/sequelize.ts#L168

rusekr avatar Jul 26 '22 13:07 rusekr

Hi there. Did you try extending the SequelizeStorage to do this? Would that work for your use case?

mmkal avatar Jul 26 '22 23:07 mmkal

Hi there. Did you try extending the SequelizeStorage to do this? Would that work for your use case?

I did monkey patch that removed this sync() methods from SequelizeStorage class and it did the thing. By extending I need to rewrite all methods without sync() that I think too many work for that case.

rusekr avatar Aug 05 '22 13:08 rusekr

Release v3.2.0 addresses this.

github-actions[bot] avatar Aug 12 '22 18:08 github-actions[bot]

@rusekr the above release should make it easy for you to create an extended storage for your use-case:

export class NonSyncingSequelizeStorage extends SequelizeStorage {
	protected async syncModel() {}
}

Use exactly like SequelizeStorage - your subclass will just no-op instead of calling this.model.sync().

Edit: I don't know who depends on the existing this.model.sync() behaviour so I'm reluctant to change the default. I also don't want to add a ton of options, so thought letting you just override seemed like a reasonable compromise.

mmkal avatar Aug 12 '22 18:08 mmkal