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

Add an option to the PostgreSQL helper to not reset sequences #38

Merged
merged 3 commits into from
Nov 4, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type PostgreSQL struct {
// which requires SUPERUSER privileges.
UseAlterConstraint bool

// DontResetSequences prevents the reset of the databases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// DontResetSequences prevents the reset of the databases
// SkipResetSequences prevents the reset of the databases

// sequences after load fixtures time
DontResetSequences bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DontResetSequences bool
SkipResetSequences bool

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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 {
Copy link
Contributor

@andreynering andreynering Oct 27, 2018

Choose a reason for hiding this comment

The 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() {
		// ...
	}()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 Dont to Skip

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
Expand Down