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

Do not synchronize by default? #627

Closed
Thooto opened this issue Sep 9, 2021 · 4 comments
Closed

Do not synchronize by default? #627

Thooto opened this issue Sep 9, 2021 · 4 comments

Comments

@Thooto
Copy link

Thooto commented Sep 9, 2021

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Not explicitely providing the synchronize: false option to the module calls the sequelize.sync() method which can alter a database in unexpected ways.

Expected behavior

Not explicitely providing the synchronize option shouldn't call the sequelize.sync() method.

What is the motivation / use case for changing the behavior?

I believe having the synchronize option enabled by default can be quite unforgiving if forgotten or omitted as this isn't a sequelize default behaviour (you have to explicitely call sequelize.sync()) and would be safer for projects relying on another database syncing mechanism (migrations, etc.).

Also the documentation doesn't appear really clear to me (keeping both original sync option and the new synchronize option).

Thanks for the consideration!

@cojack
Copy link

cojack commented May 29, 2024

It's still related?

@aroncal
Copy link

aroncal commented Jun 4, 2024

I think there's something wrong in the following code:

await sequelize.sync(options.sync);

Here:

        if (typeof options.synchronize === 'undefined' || options.synchronize) {
          await sequelize.sync(options.sync);
        }

I think it should be:

        if (typeof options.synchronize === 'undefined' || options.synchronize) {
          await sequelize.sync(options.synchronize);
        }

Following Sequelize's manual here:
https://sequelize.org/docs/v6/core-concepts/model-basics/#model-synchronization

User.sync() - This creates the table if it doesn't exist (and does nothing if it already exists)

So that, if in nestjs/sequelize we find options.synchronize === 'undefined', i.e. missing synchronizeoption, it would be transmitted to Sequelize as a non-destructive syncronization (no DROPS or ALTERS, just CREATE TABLE if it doesn't exist).

I would amend it myself, but it'd feel safer if a contributor checks this supposition of mine.

@aroncal
Copy link

aroncal commented Oct 18, 2024

Hi @kamilmysliwiec, can we see where the commit for this fix is? Thanks!

@kamilmysliwiec
Copy link
Member

I think it should be: options.synchronize

The options.sync property is specifically designed to configure the synchronization process. We intentionally pass it as an argument to the sync() method; there's nothing wrong here.

image

As of now, the code is functioning as intended.

@nestjs nestjs locked and limited conversation to collaborators Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants