-
Notifications
You must be signed in to change notification settings - Fork 118
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
testutils/db: use sequences provided by create data during import #441
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sgotti
requested changes
Oct 2, 2023
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.
- I don't understand why so much converting between types.
- The commit title/description isn't clear.
Doesn't something like this is the same (with also more detailed commit title/description)?
Author: alessandro.pinna <[email protected]>
Date: Mon Oct 2 10:00:59 2023 +0200
testutils/db: use sequences provided by create data during import
When importing, use sequences provided by create data and not the db
struct sequences since they are the latest db version sequences and
could be different.
diff --git a/internal/testutil/db.go b/internal/testutil/db.go
index 8a4eb1a64..217f18019 100644
--- a/internal/testutil/db.go
+++ b/internal/testutil/db.go
@@ -241,7 +241,7 @@ func (c *DBContext) query(tx *sql.Tx, rq sq.Builder) (*stdsql.Rows, error) {
return r, errors.WithStack(err)
}
-func (c *DBContext) Import(ctx context.Context, r io.Reader) error {
+func (c *DBContext) Import(ctx context.Context, r io.Reader, createData *CreateData) error {
br := bufio.NewReader(r)
dec := json.NewDecoder(br)
@@ -381,7 +381,7 @@ func (c *DBContext) Import(ctx context.Context, r io.Reader) error {
}
// Populate sequences
- for _, seq := range c.D.Sequences() {
+ for _, seq := range createData.Sequences {
switch c.D.DBType() {
case sql.Postgres:
q := fmt.Sprintf("SELECT setval('%s', (SELECT COALESCE(MAX(%s), 1) FROM %s));", seq.Name, seq.Column, seq.Table)
@@ -552,7 +552,7 @@ func TestCreate(t *testing.T, lastVersion uint, dataFixtures DataFixtures, setup
err = dc.DBM.Create(ctx, stmts, createVersion)
assert.NilError(t, err)
- err = dc.Import(ctx, bytes.NewBuffer(dataFixture))
+ err = dc.Import(ctx, bytes.NewBuffer(dataFixture), createData)
assert.NilError(t, err)
})
}
@@ -610,7 +610,7 @@ func TestMigrate(t *testing.T, lastVersion uint, dataFixtures DataFixtures, setu
err = createDC.DBM.Create(ctx, createStmts, migrateVersion)
assert.NilError(t, err)
- err = createDC.Import(ctx, bytes.NewBuffer(dataFixtureCreate))
+ err = createDC.Import(ctx, bytes.NewBuffer(dataFixtureCreate), createDataCreate)
assert.NilError(t, err)
// create db at create version to be migrated.
@@ -648,7 +648,7 @@ func TestMigrate(t *testing.T, lastVersion uint, dataFixtures DataFixtures, setu
err = dc.DBM.Create(ctx, stmts, createVersion)
assert.NilError(t, err)
- err = dc.Import(ctx, bytes.NewBuffer(dataFixture))
+ err = dc.Import(ctx, bytes.NewBuffer(dataFixture), createData)
assert.NilError(t, err)
err = dc.DBM.MigrateToVersion(ctx, migrateVersion)
When importing, use sequences provided by create data and not the db struct sequences since they are the latest db version sequences and could be different.
alessandro-sorint
force-pushed
the
fix-dbtest
branch
from
October 2, 2023 12:33
24e67c7
to
7875ea1
Compare
I tested with PR #432 it works |
alessandro-sorint
changed the title
testutils/db: fix import
testutils/db: use sequences provided by create data during import
Oct 2, 2023
sgotti
approved these changes
Oct 2, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When importing, use sequences provided by create data and not the db struct sequences since they are the latest db version sequences and could be different.