Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Config struct {
DisableForeignKeys bool `json:"disable_foreign_keys"`
UseSoftDeletes bool `json:"use_soft_deletes"`
Hooks func() *Hooks `json:"-"`
// SSLMode is only applicable for pgx (Postgres) driver.
// Valid values: disable, allow, prefer, require (verify-ca, verify-full not supported). Defaults to prefer.
SSLMode string `json:"ssl_mode"`
}

func (c *Config) Clone() *Config {
Expand All @@ -164,6 +167,7 @@ func (c *Config) Clone() *Config {
MigrationDir: c.MigrationDir,
IgnoreMigration: c.IgnoreMigration,
DisableForeignKeys: c.DisableForeignKeys,
SSLMode: c.SSLMode,
Hooks: c.Hooks,
}
}
Expand Down
1 change: 1 addition & 0 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (dc *DiskConfig) Clone() *DiskConfig {
Name: dc.Name,
Driver: dc.Driver,
Root: dc.Root,
PublicPath: dc.PublicPath,
BaseURL: dc.BaseURL,
GetBaseURL: dc.GetBaseURL,
Provider: dc.Provider,
Expand Down
5 changes: 5 additions & 0 deletions fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestDiskConfigClone(t *testing.T) {
Name: "test",
Driver: "test",
Root: "test",
PublicPath: "test",
BaseURL: "test",
GetBaseURL: func() string { return "test" },
Provider: "test",
Expand All @@ -28,6 +29,7 @@ func TestDiskConfigClone(t *testing.T) {
assert.Equal(t, dc.Name, clone.Name)
assert.Equal(t, dc.Driver, clone.Driver)
assert.Equal(t, dc.Root, clone.Root)
assert.Equal(t, dc.PublicPath, clone.PublicPath)
assert.Equal(t, dc.BaseURL, clone.BaseURL)
assert.Equal(t, dc.GetBaseURL(), clone.GetBaseURL())
assert.Equal(t, dc.Provider, clone.Provider)
Expand Down Expand Up @@ -55,6 +57,7 @@ func TestStorageConfigClone(t *testing.T) {
Name: "test1",
Driver: "test1",
Root: "test1",
PublicPath: "test1",
BaseURL: "test1",
GetBaseURL: func() string { return "test1" },
Provider: "test1",
Expand All @@ -69,6 +72,7 @@ func TestStorageConfigClone(t *testing.T) {
Name: "test2",
Driver: "test2",
Root: "test2",
PublicPath: "test2",
BaseURL: "test2",
GetBaseURL: func() string { return "test2" },
Provider: "test2",
Expand All @@ -90,6 +94,7 @@ func TestStorageConfigClone(t *testing.T) {
assert.Equal(t, sc.Disks[i].Name, clone.Disks[i].Name)
assert.Equal(t, sc.Disks[i].Driver, clone.Disks[i].Driver)
assert.Equal(t, sc.Disks[i].Root, clone.Disks[i].Root)
assert.Equal(t, sc.Disks[i].PublicPath, clone.Disks[i].PublicPath)
assert.Equal(t, sc.Disks[i].BaseURL, clone.Disks[i].BaseURL)
assert.Equal(t, sc.Disks[i].GetBaseURL(), clone.Disks[i].GetBaseURL())
assert.Equal(t, sc.Disks[i].Provider, clone.Disks[i].Provider)
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/fastschema/fastschema
module github.com/GeoNet/fastschema

go 1.24

toolchain go1.24.7

replace github.com/fastschema/fastschema => ./

require (
ariga.io/atlas v0.36.1
cloud.google.com/go/auth v0.16.2
Expand All @@ -15,6 +17,7 @@ require (
github.com/emersion/go-smtp v0.23.0
github.com/expr-lang/expr v1.17.5
github.com/fasthttp/websocket v1.5.12
github.com/fastschema/fastschema v0.9.6
github.com/fastschema/qjs v0.0.6
github.com/fatih/color v1.18.0
github.com/go-sql-driver/mysql v1.9.3
Expand Down Expand Up @@ -117,7 +120,6 @@ require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-sqlite3 v1.14.24 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
Expand Down
6 changes: 6 additions & 0 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func (a *App) createDBClient() (err error) {
LogQueries: utils.Env("DB_LOGGING", "false") == "true",
DisableForeignKeys: utils.Env("DB_DISABLE_FOREIGN_KEYS", "false") == "true",
UseSoftDeletes: utils.Env("DB_USE_SOFT_DELETES", "false") == "true",
SSLMode: utils.Env("DB_SSLMODE"),
}
}

Expand All @@ -453,6 +454,11 @@ func (a *App) createDBClient() (err error) {
a.config.DBConfig.MigrationDir = a.migrationDir
}

pgxValidSSLModes := []string{"disable", "allow", "prefer", "require"}
if a.config.DBConfig.Driver == "pgx" && a.config.DBConfig.SSLMode != "" && !utils.Contains(pgxValidSSLModes, a.config.DBConfig.SSLMode) {
return fmt.Errorf("invalid ssl_mode %q: must be one of %v", a.config.DBConfig.SSLMode, pgxValidSSLModes)
}

// If driver is sqlite and the DB_NAME (file path) is not set,
// Set the DB_NAME to the default sqlite db file path.
if a.config.DBConfig.Driver == "sqlite" && a.config.DBConfig.Name == "" {
Expand Down
7 changes: 6 additions & 1 deletion pkg/entdbadapter/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,18 @@ func CreateDBDSN(config *db.Config) string {
}

if config.Driver == "pgx" {
sslMode := config.SSLMode
if sslMode == "" {
sslMode = "prefer"
}
dsn = fmt.Sprintf(
"host=%s port=%s user=%s dbname=%s password=%s sslmode=disable",
"host=%s port=%s user=%s dbname=%s password=%s sslmode=%s",
config.Host,
config.Port,
config.User,
config.Name,
config.Pass,
sslMode,
)
}

Expand Down