From 6eaebd7ae8494260b77191b72d415027d91cd577 Mon Sep 17 00:00:00 2001 From: David Bariod Date: Fri, 26 Oct 2018 14:43:03 +0200 Subject: [PATCH 1/2] add an option to the postgresql helper to not reset sequences --- postgresql.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/postgresql.go b/postgresql.go index 5386cac..d730b31 100644 --- a/postgresql.go +++ b/postgresql.go @@ -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 + 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 { + return + } if err2 := h.resetSequences(db); err2 != nil && err == nil { err = err2 } From 52079e857463096f3432f2d37091397c2f804834 Mon Sep 17 00:00:00 2001 From: David Bariod Date: Sat, 27 Oct 2018 22:03:33 +0200 Subject: [PATCH 2/2] rename posgresql helper field --- postgresql.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/postgresql.go b/postgresql.go index d730b31..7093835 100644 --- a/postgresql.go +++ b/postgresql.go @@ -18,7 +18,7 @@ type PostgreSQL struct { // DontResetSequences prevents the reset of the databases // sequences after load fixtures time - DontResetSequences bool + SkipResetSequences bool tables []string sequences []string @@ -220,14 +220,13 @@ 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 { - return - } - if err2 := h.resetSequences(db); err2 != nil && err == nil { - err = err2 - } - }() + if !h.SkipResetSequences { + defer func() { + if err2 := h.resetSequences(db); err2 != nil && err == nil { + err = err2 + } + }() + } if h.UseAlterConstraint { return h.makeConstraintsDeferrable(db, loadFn)