Skip to content

Commit d2c38af

Browse files
committed
Publish 2.7.1 from dev to master
2 parents 7e0eca6 + d542cea commit d2c38af

File tree

7 files changed

+63
-28
lines changed

7 files changed

+63
-28
lines changed

bdb/drivers/mysql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (m *MySQLDriver) Columns(schema, tableName string) ([]bdb.Column, error) {
148148
(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
149149
) as is_unique
150150
from information_schema.columns as c
151-
where table_name = ? and table_schema = ?;
151+
where table_name = ? and table_schema = ? and c.extra not like '%VIRTUAL%';
152152
`, tableName, schema)
153153

154154
if err != nil {

bdb/drivers/postgres.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,13 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
348348
// Make DBType something like ARRAYinteger for parsing with randomize.Struct
349349
c.DBType = c.DBType + *c.ArrType
350350
case "USER-DEFINED":
351-
if c.UDTName == "hstore" {
351+
switch c.UDTName {
352+
case "hstore":
352353
c.Type = "types.HStore"
353354
c.DBType = "hstore"
354-
} else {
355+
case "citext":
356+
c.Type = "null.String"
357+
default:
355358
c.Type = "string"
356359
fmt.Fprintf(os.Stderr, "Warning: Incompatible data type detected: %s\n", c.UDTName)
357360
}
@@ -387,10 +390,13 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
387390
// Make DBType something like ARRAYinteger for parsing with randomize.Struct
388391
c.DBType = c.DBType + *c.ArrType
389392
case "USER-DEFINED":
390-
if c.UDTName == "hstore" {
393+
switch c.UDTName {
394+
case "hstore":
391395
c.Type = "types.HStore"
392396
c.DBType = "hstore"
393-
} else {
397+
case "citext":
398+
c.Type = "string"
399+
default:
394400
c.Type = "string"
395401
fmt.Printf("Warning: Incompatible data type detected: %s\n", c.UDTName)
396402
}

main.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ import (
1414
"github.com/volatiletech/sqlboiler/boilingcore"
1515
)
1616

17-
const sqlBoilerVersion = "2.6.0"
17+
const sqlBoilerVersion = "2.7.0"
1818

1919
var (
20-
cmdState *boilingcore.State
21-
cmdConfig *boilingcore.Config
20+
flagConfigFile string
21+
cmdState *boilingcore.State
22+
cmdConfig *boilingcore.Config
2223
)
2324

24-
func main() {
25-
var err error
26-
27-
// Too much happens between here and cobra's argument handling, for
28-
// something so simple just do it immediately.
29-
for _, arg := range os.Args {
30-
if arg == "--version" {
31-
fmt.Println("SQLBoiler v" + sqlBoilerVersion)
32-
return
25+
func initConfig() {
26+
if len(flagConfigFile) != 0 {
27+
viper.SetConfigFile(flagConfigFile)
28+
if err := viper.ReadInConfig(); err != nil {
29+
fmt.Println("Can't read config:", err)
30+
os.Exit(1)
3331
}
32+
return
3433
}
3534

35+
var err error
3636
viper.SetConfigName("sqlboiler")
3737

3838
configHome := os.Getenv("XDG_CONFIG_HOME")
@@ -56,6 +56,17 @@ func main() {
5656
// Ignore errors here, fallback to other validation methods.
5757
// Users can use environment variables if a config is not found.
5858
_ = viper.ReadInConfig()
59+
}
60+
61+
func main() {
62+
// Too much happens between here and cobra's argument handling, for
63+
// something so simple just do it immediately.
64+
for _, arg := range os.Args {
65+
if arg == "--version" {
66+
fmt.Println("SQLBoiler v" + sqlBoilerVersion)
67+
return
68+
}
69+
}
5970

6071
// Set up the cobra root command
6172
var rootCmd = &cobra.Command{
@@ -71,7 +82,10 @@ func main() {
7182
SilenceUsage: true,
7283
}
7384

85+
cobra.OnInitialize(initConfig)
86+
7487
// Set up the cobra root command flags
88+
rootCmd.PersistentFlags().StringVarP(&flagConfigFile, "config", "c", "", "Supply the name of the config file to override the default lookup")
7589
rootCmd.PersistentFlags().StringP("output", "o", "models", "The name of the folder to output to")
7690
rootCmd.PersistentFlags().StringP("schema", "s", "", "schema name for drivers that support it (default psql: public, mssql: dbo)")
7791
rootCmd.PersistentFlags().StringP("pkgname", "p", "models", "The name you wish to assign to your generated package")

strmangle/strmangle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,9 @@ func TestReplaceReservedWords(t *testing.T) {
596596
for i, test := range tests {
597597
got := ReplaceReservedWords(test.Word)
598598
if test.Replace && !strings.HasSuffix(got, "_") {
599-
t.Errorf("%i) want suffixed (%s), got: %s", i, test.Word, got)
599+
t.Errorf("%d) want suffixed (%s), got: %s", i, test.Word, got)
600600
} else if !test.Replace && strings.HasSuffix(got, "_") {
601-
t.Errorf("%i) want normal (%s), got: %s", i, test.Word, got)
601+
t.Errorf("%d) want normal (%s), got: %s", i, test.Word, got)
602602
}
603603
}
604604
}

templates_test/singleton/boil_main_test.tpl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var flagDebugMode = flag.Bool("test.sqldebug", false, "Turns on debug mode for SQL statements")
2+
var flagConfigFile = flag.String("test.config", "", "Overrides the default config")
23

34
var (
45
dbMain tester
@@ -17,6 +18,9 @@ func TestMain(m *testing.M) {
1718
}
1819

1920
rand.Seed(time.Now().UnixNano())
21+
22+
flag.Parse()
23+
2024
var err error
2125

2226
// Load configuration
@@ -33,7 +37,6 @@ func TestMain(m *testing.M) {
3337
}
3438

3539
// Set DebugMode so we can see generated sql statements
36-
flag.Parse()
3740
boil.DebugMode = *flagDebugMode
3841

3942
if err = dbMain.setup(); err != nil {
@@ -59,6 +62,14 @@ func TestMain(m *testing.M) {
5962
}
6063

6164
func initViper() error {
65+
if flagConfigFile != nil && *flagConfigFile != "" {
66+
viper.SetConfigFile(*flagConfigFile)
67+
if err := viper.ReadInConfig(); err != nil {
68+
return err
69+
}
70+
return nil
71+
}
72+
6273
var err error
6374

6475
viper.SetConfigName("sqlboiler")

testdata/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
FROM ubuntu:16.04
33

44
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/opt/mssql-tools/bin
5-
ENV GODIST go1.8.linux-amd64.tar.gz
6-
7-
# Set up locales for sqlcmd (otherwise it breaks)
8-
RUN locale-gen en_US.UTF-8 \
9-
&& echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \
10-
&& echo "LANG=en_US.UTF-8" >> /etc/default/locale
5+
ENV GODIST go1.10.2.linux-amd64.tar.gz
116

127
# Install bootstrap-y tools
138
RUN apt-get update \
149
&& apt-get install -y apt-transport-https software-properties-common python3-software-properties \
1510
&& apt-add-repository ppa:git-core/ppa \
1611
&& apt-get update \
17-
&& apt-get install -y curl git
12+
&& apt-get install -y curl git locales
13+
14+
# Set up locales for sqlcmd (otherwise it breaks)
15+
RUN locale-gen en_US.UTF-8 \
16+
&& echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \
17+
&& echo "LANG=en_US.UTF-8" >> /etc/default/locale
1818

1919
# Install database clients
2020
# MySQL 8.0 is still in development, so we're using 5.7 which is already

testdata/postgres_test_schema.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
CREATE EXTENSION IF NOT EXISTS citext;
2+
13
CREATE TYPE workday AS ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday');
24
CREATE TYPE faceyface AS ENUM('angry', 'hungry', 'bitter');
35

@@ -179,7 +181,9 @@ CREATE TABLE magic (
179181
iii txid_snapshot NULL,
180182
jjj txid_snapshot NOT NULL,
181183
kkk xml NULL,
182-
lll xml NOT NULL
184+
lll xml NOT NULL,
185+
mmm citext NULL,
186+
nnn citext NOT NULL
183187
);
184188

185189
create table owner (

0 commit comments

Comments
 (0)