mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 21:02:45 +08:00
SQLStore: Fix Postgres dialect treating "false" migrator default as true (#69353)
* SQLStore: Fix Postgres dialect treating "false" migrator default as true Previously, when creating a migration you could choose a default value for a new boolean column that looked correct but would be interpreted incorrectly by the Postgres dialect. For example, values such as "false" or "FALSE" would be treated as true by the Postgres dialect. This refactors how migration dialects determine the Default column value for boolean type columns. Each dialect now uses the same base code to parse the Default literal and panics if an unknown value is encountered. So, now AddColumnMigration and AddTableMigration will ensure that across dialects: - The exact same Default literals will be allowed. - The literals are converted to equivalent defaults in their DDL. - An error will be thrown if an invalid literal is provided.
This commit is contained in:
@ -46,16 +46,6 @@ func (db *PostgresDialect) BatchSize() int {
|
||||
return 1000
|
||||
}
|
||||
|
||||
func (db *PostgresDialect) Default(col *Column) string {
|
||||
if col.Type == DB_Bool {
|
||||
if col.Default == "0" {
|
||||
return "FALSE"
|
||||
}
|
||||
return "TRUE"
|
||||
}
|
||||
return col.Default
|
||||
}
|
||||
|
||||
func (db *PostgresDialect) SQLType(c *Column) string {
|
||||
var res string
|
||||
switch t := c.Type; t {
|
||||
|
Reference in New Issue
Block a user