avelino / awesome-go

A curated list of awesome Go frameworks, libraries and software
https://awesome-go.com
MIT License
128.86k stars 11.79k forks source link

SQLBoiler is not schema-aware. Need qualified table identifiers for FK. #1387

Closed FourSigma closed 7 years ago

FourSigma commented 7 years ago

SQL Boiler Version 2.20 using Postgres 9.6

When referencing a foreign key from another schema, SQLBoiler panics.

CREATE SCHEMA IF NOT EXISTS identity;
CREATE TABLE identity.profile ( 
       id         uuid PRIMARY KEY
)

CREATE SCHEMA IF NOT EXISTS account;
CREATE TABLE account.user(
       profile_id         uuid UNIQUE REFERENCES identity.profile ON DELETE CASCADE
)

Executing the command:

╰─$ sqlboiler -s account postgres
panic: could not find table name: profile

goroutine 1 [running]:
github.com/vattle/sqlboiler/bdb.GetTable(0xc420392000, 0x3, 0x4, 0xc420131680, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /Users/siva/go/src/github.com/vattle/sqlboiler/bdb/table.go:30 +0x22c
github.com/vattle/sqlboiler/bdb.setForeignKeyConstraints(0xc420392090, 0xc420392000, 0x3, 0x4)
    /Users/siva/go/src/github.com/vattle/sqlboiler/bdb/interface.go:115 +0x173
github.com/vattle/sqlboiler/bdb.Tables(0x18d71c0, 0xc420334660, 0x7fff5fbffa2d, 0x7, 0x1927a08, 0x0, 0x0, 0x1927a08, 0x0, 0x0, ...)
    /Users/siva/go/src/github.com/vattle/sqlboiler/bdb/interface.go:78 +0x98d
github.com/vattle/sqlboiler/boilingcore.(*State).initTables(0xc420364000, 0x7fff5fbffa2d, 0x7, 0x1927a08, 0x0, 0x0, 0x1927a08, 0x0, 0x0, 0xc4200f3820, ...)
    /Users/siva/go/src/github.com/vattle/sqlboiler/boilingcore/boilingcore.go:336 +0xb5
github.com/vattle/sqlboiler/boilingcore.New(0xc420354000, 0x0, 0x0, 0x5)
    /Users/siva/go/src/github.com/vattle/sqlboiler/boilingcore/boilingcore.go:66 +0x123
main.preRun(0xc42033c000, 0xc420331380, 0x1, 0x3, 0x0, 0x0)
    /Users/siva/go/src/github.com/vattle/sqlboiler/main.go:296 +0x54e
github.com/spf13/cobra.(*Command).execute(0xc42033c000, 0xc420010250, 0x3, 0x3, 0xc42033c000, 0xc420010250)
    /Users/siva/go/src/github.com/spf13/cobra/command.go:623 +0x487
github.com/spf13/cobra.(*Command).ExecuteC(0xc42033c000, 0xc42033e000, 0x0, 0x0)
    /Users/siva/go/src/github.com/spf13/cobra/command.go:710 +0x339
github.com/spf13/cobra.(*Command).Execute(0xc42033c000, 0x0, 0x0)
    /Users/siva/go/src/github.com/spf13/cobra/command.go:669 +0x2b
main.main()
    /Users/siva/go/src/github.com/vattle/sqlboiler/main.go:104 +0xd1a
dmitshur commented 7 years ago

If your issue is with the https://github.com/vattle/sqlboiler project, you should report it in its issue tracker at https://github.com/vattle/sqlboiler/issues. This is the wrong place.