Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sequelize.sync({ force: 'if-mismatch' }) #15187

Open
2 of 6 tasks
ephys opened this issue Oct 26, 2022 · 5 comments
Open
2 of 6 tasks

sequelize.sync({ force: 'if-mismatch' }) #15187

ephys opened this issue Oct 26, 2022 · 5 comments
Labels
type: feature For issues and PRs. For new features. Never breaking changes.

Comments

@ephys
Copy link
Member

ephys commented Oct 26, 2022

Feature Description

Describe the feature you'd like to see implemented

Having the possibility of setting the force option in sequelize.sync to if-mismatch (or if-needed?):

sequelize.sync({ force: 'if-mismatch' }): Promise<boolean>

Describe why you would like this feature to be added to Sequelize

When modifying an existing model during development, none of the existing solutions work very well:

  • sequelize.sync() does not update an existing table at all
  • sequelize.sync({ alter: true }) will never be able to perfectly update an existing table, so we usually just don't use it at all. (for instance, it's impossible for alter to add a non-null column that doesn't have a default value).
  • sequelize.sync({ force: true }) + seeding with dev data works, but it resets the database on every app restart which makes it inconvenient.

So far I've always used sequelize.sync({ force: true }), but I comment it out when I don't need it.

With something like sequelize.sync({ force: 'if-mismatch' }), we could fully reset the database, but only when one of the tables is outdated.

In this design, I'm making that method return true when a synchronization happened. This boolean can then be used by user code to run dev data seeding accordingly.

This would be a non-trivial feature. We'd need to rely on describeTable, which has many quirks. But in time we should be able to implement something like this

Is this feature dialect-specific?

  • No. This feature is relevant to Sequelize as a whole.
  • Yes. This feature only applies to the following dialect(s):

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.

Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.

@fzn0x
Copy link
Member

fzn0x commented Oct 26, 2022

Is it also possible to add new column updated_at into SequelizeMeta for this feature whenever the feature implemented a change to the 'outdated' tables?

@ephys
Copy link
Member Author

ephys commented Oct 26, 2022

What would be the use case for such a column?

@fzn0x
Copy link
Member

fzn0x commented Oct 26, 2022

What would be the use case for such a column?

No specific use case, just did track when the tables is getting updated.

@ephys
Copy link
Member Author

ephys commented Oct 26, 2022

Well SequelizeMeta is managed by sequelize-cli and is about migrations so we'd need a new table for sync. I don't really want to add extra tables unless we have a very good reason to

@fzn0x
Copy link
Member

fzn0x commented Oct 26, 2022

Well SequelizeMeta is managed by sequelize-cli and is about migrations so we'd need a new table for sync. I don't really want to add extra tables unless we have a very good reason to

I see, lets skip that I guess :D

@WikiRik WikiRik added the type: feature For issues and PRs. For new features. Never breaking changes. label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature For issues and PRs. For new features. Never breaking changes.
Projects
None yet
Development

No branches or pull requests

3 participants