mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-25 13:16:40 +00:00
ensure a default value is always set
This commit is contained in:
parent
25a4758557
commit
65335cb4b2
|
@ -146,21 +146,18 @@ func convertEnums[OldType ~string, NewType ~int](
|
||||||
table, column,
|
table, column,
|
||||||
)
|
)
|
||||||
|
|
||||||
var columnExpr string
|
// Ensure a default value.
|
||||||
var columnArgs []any
|
if defaultValue == nil {
|
||||||
|
var zero NewType
|
||||||
// Build new column expr with args.
|
defaultValue = &zero
|
||||||
columnExpr = "? INTEGER NOT NULL"
|
|
||||||
columnArgs = []any{bun.Ident(newColumn)}
|
|
||||||
if defaultValue != nil {
|
|
||||||
columnExpr += " DEFAULT ?"
|
|
||||||
columnArgs = append(columnArgs, *defaultValue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new column to database.
|
// Add new column to database.
|
||||||
if _, err := tx.NewAddColumn().
|
if _, err := tx.NewAddColumn().
|
||||||
Table(table).
|
Table(table).
|
||||||
ColumnExpr(columnExpr, columnArgs...).
|
ColumnExpr("? INTEGER NOT NULL DEFAULT ?",
|
||||||
|
bun.Ident(newColumn),
|
||||||
|
*defaultValue).
|
||||||
Exec(ctx); err != nil {
|
Exec(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue