diff --git a/bdb/drivers/mysql.go b/bdb/drivers/mysql.go index d5aaab6af..1a3d55e54 100644 --- a/bdb/drivers/mysql.go +++ b/bdb/drivers/mysql.go @@ -148,7 +148,7 @@ func (m *MySQLDriver) Columns(schema, tableName string) ([]bdb.Column, error) { (select count(*) from information_schema.key_column_usage where table_schema = kcu.table_schema and table_name = tc.table_name and constraint_name = tc.constraint_name) = 1 ) as is_unique from information_schema.columns as c - where table_name = ? and table_schema = ?; + where table_name = ? and table_schema = ? and c.extra not like '%VIRTUAL%'; `, tableName, schema) if err != nil { diff --git a/bdb/drivers/postgres.go b/bdb/drivers/postgres.go index d08d93f6b..611eefcf3 100644 --- a/bdb/drivers/postgres.go +++ b/bdb/drivers/postgres.go @@ -348,10 +348,13 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column { // Make DBType something like ARRAYinteger for parsing with randomize.Struct c.DBType = c.DBType + *c.ArrType case "USER-DEFINED": - if c.UDTName == "hstore" { + switch c.UDTName { + case "hstore": c.Type = "types.HStore" c.DBType = "hstore" - } else { + case "citext": + c.Type = "null.String" + default: c.Type = "string" fmt.Fprintf(os.Stderr, "Warning: Incompatible data type detected: %s\n", c.UDTName) } @@ -387,10 +390,13 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column { // Make DBType something like ARRAYinteger for parsing with randomize.Struct c.DBType = c.DBType + *c.ArrType case "USER-DEFINED": - if c.UDTName == "hstore" { + switch c.UDTName { + case "hstore": c.Type = "types.HStore" c.DBType = "hstore" - } else { + case "citext": + c.Type = "string" + default: c.Type = "string" fmt.Printf("Warning: Incompatible data type detected: %s\n", c.UDTName) } diff --git a/main.go b/main.go index bc29a6c8e..68f2c6048 100644 --- a/main.go +++ b/main.go @@ -14,25 +14,25 @@ import ( "github.com/volatiletech/sqlboiler/boilingcore" ) -const sqlBoilerVersion = "2.6.0" +const sqlBoilerVersion = "2.7.0" var ( - cmdState *boilingcore.State - cmdConfig *boilingcore.Config + flagConfigFile string + cmdState *boilingcore.State + cmdConfig *boilingcore.Config ) -func main() { - var err error - - // Too much happens between here and cobra's argument handling, for - // something so simple just do it immediately. - for _, arg := range os.Args { - if arg == "--version" { - fmt.Println("SQLBoiler v" + sqlBoilerVersion) - return +func initConfig() { + if len(flagConfigFile) != 0 { + viper.SetConfigFile(flagConfigFile) + if err := viper.ReadInConfig(); err != nil { + fmt.Println("Can't read config:", err) + os.Exit(1) } + return } + var err error viper.SetConfigName("sqlboiler") configHome := os.Getenv("XDG_CONFIG_HOME") @@ -56,6 +56,17 @@ func main() { // Ignore errors here, fallback to other validation methods. // Users can use environment variables if a config is not found. _ = viper.ReadInConfig() +} + +func main() { + // Too much happens between here and cobra's argument handling, for + // something so simple just do it immediately. + for _, arg := range os.Args { + if arg == "--version" { + fmt.Println("SQLBoiler v" + sqlBoilerVersion) + return + } + } // Set up the cobra root command var rootCmd = &cobra.Command{ @@ -71,7 +82,10 @@ func main() { SilenceUsage: true, } + cobra.OnInitialize(initConfig) + // Set up the cobra root command flags + rootCmd.PersistentFlags().StringVarP(&flagConfigFile, "config", "c", "", "Supply the name of the config file to override the default lookup") rootCmd.PersistentFlags().StringP("output", "o", "models", "The name of the folder to output to") rootCmd.PersistentFlags().StringP("schema", "s", "", "schema name for drivers that support it (default psql: public, mssql: dbo)") rootCmd.PersistentFlags().StringP("pkgname", "p", "models", "The name you wish to assign to your generated package") diff --git a/strmangle/strmangle_test.go b/strmangle/strmangle_test.go index 0d67cd5b7..b1d07743d 100644 --- a/strmangle/strmangle_test.go +++ b/strmangle/strmangle_test.go @@ -596,9 +596,9 @@ func TestReplaceReservedWords(t *testing.T) { for i, test := range tests { got := ReplaceReservedWords(test.Word) if test.Replace && !strings.HasSuffix(got, "_") { - t.Errorf("%i) want suffixed (%s), got: %s", i, test.Word, got) + t.Errorf("%d) want suffixed (%s), got: %s", i, test.Word, got) } else if !test.Replace && strings.HasSuffix(got, "_") { - t.Errorf("%i) want normal (%s), got: %s", i, test.Word, got) + t.Errorf("%d) want normal (%s), got: %s", i, test.Word, got) } } } diff --git a/templates_test/singleton/boil_main_test.tpl b/templates_test/singleton/boil_main_test.tpl index ebb4758a1..805fe40eb 100644 --- a/templates_test/singleton/boil_main_test.tpl +++ b/templates_test/singleton/boil_main_test.tpl @@ -1,4 +1,5 @@ var flagDebugMode = flag.Bool("test.sqldebug", false, "Turns on debug mode for SQL statements") +var flagConfigFile = flag.String("test.config", "", "Overrides the default config") var ( dbMain tester @@ -17,6 +18,9 @@ func TestMain(m *testing.M) { } rand.Seed(time.Now().UnixNano()) + + flag.Parse() + var err error // Load configuration @@ -33,7 +37,6 @@ func TestMain(m *testing.M) { } // Set DebugMode so we can see generated sql statements - flag.Parse() boil.DebugMode = *flagDebugMode if err = dbMain.setup(); err != nil { @@ -59,6 +62,14 @@ func TestMain(m *testing.M) { } func initViper() error { + if flagConfigFile != nil && *flagConfigFile != "" { + viper.SetConfigFile(*flagConfigFile) + if err := viper.ReadInConfig(); err != nil { + return err + } + return nil + } + var err error viper.SetConfigName("sqlboiler") diff --git a/testdata/Dockerfile b/testdata/Dockerfile index 034cedce7..05d3029f5 100644 --- a/testdata/Dockerfile +++ b/testdata/Dockerfile @@ -2,19 +2,19 @@ FROM ubuntu:16.04 ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/opt/mssql-tools/bin -ENV GODIST go1.8.linux-amd64.tar.gz - -# Set up locales for sqlcmd (otherwise it breaks) -RUN locale-gen en_US.UTF-8 \ - && echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \ - && echo "LANG=en_US.UTF-8" >> /etc/default/locale +ENV GODIST go1.10.2.linux-amd64.tar.gz # Install bootstrap-y tools RUN apt-get update \ && apt-get install -y apt-transport-https software-properties-common python3-software-properties \ && apt-add-repository ppa:git-core/ppa \ && apt-get update \ - && apt-get install -y curl git + && apt-get install -y curl git locales + +# Set up locales for sqlcmd (otherwise it breaks) +RUN locale-gen en_US.UTF-8 \ + && echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \ + && echo "LANG=en_US.UTF-8" >> /etc/default/locale # Install database clients # MySQL 8.0 is still in development, so we're using 5.7 which is already diff --git a/testdata/postgres_test_schema.sql b/testdata/postgres_test_schema.sql index 3e29c7433..350ffb1b2 100644 --- a/testdata/postgres_test_schema.sql +++ b/testdata/postgres_test_schema.sql @@ -1,3 +1,5 @@ +CREATE EXTENSION IF NOT EXISTS citext; + CREATE TYPE workday AS ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday'); CREATE TYPE faceyface AS ENUM('angry', 'hungry', 'bitter'); @@ -179,7 +181,9 @@ CREATE TABLE magic ( iii txid_snapshot NULL, jjj txid_snapshot NOT NULL, kkk xml NULL, - lll xml NOT NULL + lll xml NOT NULL, + mmm citext NULL, + nnn citext NOT NULL ); create table owner (