Skip to content

Commit

Permalink
test: capture bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bevzzz committed Jan 7, 2024
1 parent 1656366 commit f9a44b6
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/dbtest/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,14 @@ func TestQuery(t *testing.T) {
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(&Model{42, ""}).OmitZero()
},
func(db *bun.DB) schema.QueryAppender {
q := db.NewCreateTable().Model(new(Story)).WithForeignKeys()

// Check that building the query with .AppendQuery() multiple times does not add redundant FK constraints:
// https://github.com/uptrace/bun/pull/941#discussion_r1443647857
_ = q.String()
return q
},
}

timeRE := regexp.MustCompile(`'2\d{3}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?(\+\d{2}:\d{2})?'`)
Expand Down
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-163
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `stories` (`id` BIGINT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255), `user_id` BIGINT, PRIMARY KEY (`id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-163
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "stories" ("id" BIGINT NOT NULL IDENTITY, "name" VARCHAR(255), "user_id" BIGINT, PRIMARY KEY ("id"), FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-163
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `stories` (`id` BIGINT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255), `user_id` BIGINT, PRIMARY KEY (`id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-163
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `stories` (`id` BIGINT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255), `user_id` BIGINT, PRIMARY KEY (`id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-163
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "stories" ("id" BIGSERIAL NOT NULL, "name" VARCHAR, "user_id" BIGINT, PRIMARY KEY ("id"), FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-163
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "stories" ("id" BIGSERIAL NOT NULL, "name" VARCHAR, "user_id" BIGINT, PRIMARY KEY ("id"), FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-163
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "stories" ("id" INTEGER NOT NULL, "name" VARCHAR, "user_id" INTEGER, PRIMARY KEY ("id"), FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION)
9 changes: 9 additions & 0 deletions query_table_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,12 @@ func (q *CreateTableQuery) afterCreateTableHook(ctx context.Context) error {
}
return nil
}

func (q *CreateTableQuery) String() string {
buf, err := q.AppendQuery(q.db.Formatter(), nil)
if err != nil {
panic(err)
}

return string(buf)
}

0 comments on commit f9a44b6

Please sign in to comment.