Skip to content

Commit 22607e5

Browse files
committed
Prepend table names to the generated enum names
Otherwise we'll get a collision if a column name is shared for an enum table across two tables
1 parent 4cdf5e2 commit 22607e5

File tree

9 files changed

+41
-40
lines changed

9 files changed

+41
-40
lines changed

examples/booktest/mysql/db_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestBooks(t *testing.T) {
4141
AuthorID: int32(authorID),
4242
Isbn: "1",
4343
Title: "my book title",
44-
BookType: BookTypeFICTION,
44+
BookType: BooksBookTypeFICTION,
4545
Yr: 2016,
4646
Available: now,
4747
})
@@ -54,7 +54,7 @@ func TestBooks(t *testing.T) {
5454
AuthorID: int32(authorID),
5555
Isbn: "2",
5656
Title: "the second book",
57-
BookType: BookTypeFICTION,
57+
BookType: BooksBookTypeFICTION ,
5858
Yr: 2016,
5959
Available: now,
6060
Tags: "cool,unique",
@@ -82,7 +82,7 @@ func TestBooks(t *testing.T) {
8282
AuthorID: int32(authorID),
8383
Isbn: "3",
8484
Title: "the third book",
85-
BookType: BookTypeFICTION,
85+
BookType: BooksBookTypeFICTION,
8686
Yr: 2001,
8787
Available: now,
8888
Tags: "cool",
@@ -96,7 +96,7 @@ func TestBooks(t *testing.T) {
9696
AuthorID: int32(authorID),
9797
Isbn: "4",
9898
Title: "4th place finisher",
99-
BookType: BookTypeNONFICTION,
99+
BookType: BooksBookTypeNONFICTION,
100100
Yr: 2011,
101101
Available: now,
102102
Tags: "other",

examples/booktest/mysql/models.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/booktest/mysql/query.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ondeck/mysql/db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func runOnDeckQueries(t *testing.T, q *Queries) {
4444
Name: "The Fillmore",
4545
City: city.Slug,
4646
SpotifyPlaylist: "spotify:uri",
47-
Status: StatusOpen,
47+
Status: VenuesStatusOpen,
4848
Statuses: join(string(StatusOpen), string(StatusClosed)),
4949
Tags: join("rock", "punk"),
5050
})

examples/ondeck/mysql/models.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ondeck/mysql/venue.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/ddl_create_enum/mysql/go/models.go

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/ddl_create_enum/mysql/go/query.sql.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/catalog/table.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package catalog
22

33
import (
44
"errors"
5+
"fmt"
56

67
"github.com/kyleconroy/sqlc/internal/sql/ast"
78
"github.com/kyleconroy/sqlc/internal/sql/sqlerr"
@@ -162,7 +163,7 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error {
162163
}
163164
if col.Vals != nil {
164165
typeName := ast.TypeName{
165-
Name: col.Colname,
166+
Name: fmt.Sprintf("%s_%s", stmt.Name.Name, col.Colname),
166167
}
167168
s := &ast.CreateEnumStmt{TypeName: &typeName, Vals: col.Vals}
168169
if err := c.createEnum(s); err != nil {

0 commit comments

Comments
 (0)