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

Support for upserts? #61

Open
Lemmmy opened this issue Jan 31, 2019 · 5 comments
Open

Support for upserts? #61

Lemmmy opened this issue Jan 31, 2019 · 5 comments
Labels

Comments

@Lemmmy
Copy link

Lemmmy commented Jan 31, 2019

Currently, it does not look like sequelize-paper-trail supports revisions for upserts (and possibly bulkCreate too?). Would it be possible/feasible to support this, or should I manually do findOne + insert/update? I'm using MySQL.

@ksfreitas
Copy link
Contributor

Paper trail uses sequelize hooks. This is possible setting { individualHooks: true } at bulk operation.

http://docs.sequelizejs.com/manual/tutorial/hooks.html

@Lemmmy
Copy link
Author

Lemmmy commented Feb 1, 2019

From what I can see, sequelize-paper-trail does not use the before/afterUpsert hooks:

this.addHook("beforeCreate", createBeforeHook('create'));
this.addHook("beforeUpdate", createBeforeHook('update'));
this.addHook("beforeDestroy", createBeforeHook('destroy'));
this.addHook("afterCreate", createAfterHook('create'));
this.addHook("afterUpdate", createAfterHook('update'));
this.addHook("afterDestroy", createAfterHook('destroy'));

@Lemmmy
Copy link
Author

Lemmmy commented Feb 21, 2019

One problem with using { individualHooks: true } is when creating a lot of records in bulk (like you're supposed to). sequelize-paper-trail will try to insert tens of thousands of create revisions one-by-one, which can lead to a large number of inserts failing/timing out due to pool inavailability, etc.

Executing (default): INSERT INTO `Revisions` (...)
Executing (default): INSERT INTO `Revisions` (...)
Executing (default): INSERT INTO `Revisions` (...)
Executing (default): INSERT INTO `Revisions` (...)
Executing (default): INSERT INTO `Revisions` (...)
Revision save error
{ TimeoutError: ResourceRequest timed out
    at ResourceRequest._fireTimeout (node_modules/generic-pool/lib/ResourceRequest.js:62:17)
    at Timeout.bound (node_modules/generic-pool/lib/ResourceRequest.js:8:15)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5) name: 'TimeoutError' }
Revision save error
{ TimeoutError: ResourceRequest timed out
    at ResourceRequest._fireTimeout (node_modules/generic-pool/lib/ResourceRequest.js:62:17)
    at Timeout.bound (node_modules/generic-pool/lib/ResourceRequest.js:8:15)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5) name: 'TimeoutError' }
Revision save error
{ TimeoutError: ResourceRequest timed out
    at ResourceRequest._fireTimeout (node_modules/generic-pool/lib/ResourceRequest.js:62:17)
    at Timeout.bound (node_modules/generic-pool/lib/ResourceRequest.js:8:15)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5) name: 'TimeoutError' }
Revision save error
{ TimeoutError: ResourceRequest timed out
    at ResourceRequest._fireTimeout (node_modules/generic-pool/lib/ResourceRequest.js:62:17)
    at Timeout.bound (node_modules/generic-pool/lib/ResourceRequest.js:8:15)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5) name: 'TimeoutError' }

@nielsgl
Copy link
Owner

nielsgl commented Mar 14, 2019

@Lemmmy @ksfreitas any ideas on how to implement it / whether it's worth to implement it?

@mihajul
Copy link

mihajul commented Aug 9, 2022

Support for upsert opperation PR: #123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants