-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add an option to the PostgreSQL helper to not reset sequences #38
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,10 @@ type PostgreSQL struct { | |||||
// which requires SUPERUSER privileges. | ||||||
UseAlterConstraint bool | ||||||
|
||||||
// DontResetSequences prevents the reset of the databases | ||||||
// sequences after load fixtures time | ||||||
DontResetSequences bool | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I choose this negative logic so that the default value keep a compatible backward behaviour. But in the end its your call. |
||||||
|
||||||
tables []string | ||||||
sequences []string | ||||||
nonDeferrableConstraints []pgConstraint | ||||||
|
@@ -217,6 +221,9 @@ func (h *PostgreSQL) makeConstraintsDeferrable(db *sql.DB, loadFn loadFunction) | |||||
func (h *PostgreSQL) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) (err error) { | ||||||
// ensure sequences being reset after load | ||||||
defer func() { | ||||||
if h.DontResetSequences { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should actually avoid deferring this whole function if sequences resetting is being skipped: if !h.SkipResetSequences {
defer func() {
// ...
}()
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see my previous comment. I think its better to keep the behaviour backward compatible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dgsb Sorry, there was a typo in the snippet above. It should be: if !h.SkipResetSequences { Instead of: if h.SkipResetSequences { The value is still negated (and backwards compatible). I just suggested renaming it from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I read to fast your answer |
||||||
return | ||||||
} | ||||||
if err2 := h.resetSequences(db); err2 != nil && err == nil { | ||||||
err = err2 | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.