-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimental): replace dialect with a richer storage.Factory type
- Loading branch information
1 parent
257b523
commit fbebaf8
Showing
24 changed files
with
328 additions
and
552 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package goose | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pressly/goose/v3/state" | ||
"github.com/pressly/goose/v3/state/storage" | ||
) | ||
|
||
var global = struct { | ||
storageFactory func(string) state.Storage | ||
tableName string | ||
}{ | ||
storageFactory: storage.PostgreSQL, | ||
tableName: "goose_db_version", | ||
} | ||
|
||
func globalStorage() state.Storage { | ||
return global.storageFactory(global.tableName) | ||
} | ||
|
||
// TableName returns goose db version table name | ||
func TableName() string { | ||
return global.tableName | ||
} | ||
|
||
// SetTableName set goose db version table name | ||
func SetTableName(n string) { | ||
global.tableName = n | ||
} | ||
|
||
// Dialect is the type of database dialect. | ||
type Dialect string | ||
|
||
const ( | ||
DialectClickHouse Dialect = "clickhouse" | ||
DialectMSSQL Dialect = "mssql" | ||
DialectMySQL Dialect = "mysql" | ||
DialectPostgres Dialect = "postgres" | ||
DialectRedshift Dialect = "redshift" | ||
DialectSQLite3 Dialect = "sqlite3" | ||
DialectTiDB Dialect = "tidb" | ||
DialectVertica Dialect = "vertica" | ||
) | ||
|
||
// SetDialect sets the dialect to use for the goose package. | ||
func SetDialect(s string) error { | ||
switch s { | ||
case "postgres", "pgx": | ||
global.storageFactory = storage.PostgreSQL | ||
// case "mysql": | ||
// d = dialect.Mysql | ||
case "sqlite3", "sqlite": | ||
global.storageFactory = storage.Sqlite3 | ||
// case "mssql", "azuresql", "sqlserver": | ||
// d = dialect.Sqlserver | ||
// case "redshift": | ||
// d = dialect.Redshift | ||
// case "tidb": | ||
// d = dialect.Tidb | ||
// case "clickhouse": | ||
// d = dialect.Clickhouse | ||
// case "vertica": | ||
// d = dialect.Vertica | ||
default: | ||
return fmt.Errorf("%q: unknown dialect", s) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.