Fix "NOT NULL column with NULL" error in v5 SQLite migration
Previously, this migration would cause the error: "Cannot add a NOT NULL column with default value NULL". This fixes that by setting the default value for new columns to '' (empty string). It updates the query builder to support this, too.
This commit is contained in:
parent
bb5da1d3f5
commit
471ef4d403
|
@ -177,7 +177,11 @@ func (c *Column) String() (string, error) {
|
||||||
|
|
||||||
if c.Default.Set {
|
if c.Default.Set {
|
||||||
str.WriteString(" DEFAULT ")
|
str.WriteString(" DEFAULT ")
|
||||||
str.WriteString(c.Default.Value)
|
val := c.Default.Value
|
||||||
|
if val == "" {
|
||||||
|
val = "''"
|
||||||
|
}
|
||||||
|
str.WriteString(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.PrimaryKey {
|
if c.PrimaryKey {
|
||||||
|
@ -250,4 +254,3 @@ func (b *CreateTableSqlBuilder) ToSQL() (string, error) {
|
||||||
|
|
||||||
return str.String(), nil
|
return str.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,35 +20,35 @@ func oauthSlack(db *datastore) error {
|
||||||
Column(
|
Column(
|
||||||
"provider",
|
"provider",
|
||||||
wf_db.ColumnTypeVarChar,
|
wf_db.ColumnTypeVarChar,
|
||||||
wf_db.OptionalInt{Set: true, Value: 24})),
|
wf_db.OptionalInt{Set: true, Value: 24}).SetDefault("")),
|
||||||
dialect.
|
dialect.
|
||||||
AlterTable("oauth_client_states").
|
AlterTable("oauth_client_states").
|
||||||
AddColumn(dialect.
|
AddColumn(dialect.
|
||||||
Column(
|
Column(
|
||||||
"client_id",
|
"client_id",
|
||||||
wf_db.ColumnTypeVarChar,
|
wf_db.ColumnTypeVarChar,
|
||||||
wf_db.OptionalInt{Set: true, Value: 128})),
|
wf_db.OptionalInt{Set: true, Value: 128}).SetDefault("")),
|
||||||
dialect.
|
dialect.
|
||||||
AlterTable("oauth_users").
|
AlterTable("oauth_users").
|
||||||
AddColumn(dialect.
|
AddColumn(dialect.
|
||||||
Column(
|
Column(
|
||||||
"provider",
|
"provider",
|
||||||
wf_db.ColumnTypeVarChar,
|
wf_db.ColumnTypeVarChar,
|
||||||
wf_db.OptionalInt{Set: true, Value: 24})),
|
wf_db.OptionalInt{Set: true, Value: 24}).SetDefault("")),
|
||||||
dialect.
|
dialect.
|
||||||
AlterTable("oauth_users").
|
AlterTable("oauth_users").
|
||||||
AddColumn(dialect.
|
AddColumn(dialect.
|
||||||
Column(
|
Column(
|
||||||
"client_id",
|
"client_id",
|
||||||
wf_db.ColumnTypeVarChar,
|
wf_db.ColumnTypeVarChar,
|
||||||
wf_db.OptionalInt{Set: true, Value: 128})),
|
wf_db.OptionalInt{Set: true, Value: 128}).SetDefault("")),
|
||||||
dialect.
|
dialect.
|
||||||
AlterTable("oauth_users").
|
AlterTable("oauth_users").
|
||||||
AddColumn(dialect.
|
AddColumn(dialect.
|
||||||
Column(
|
Column(
|
||||||
"access_token",
|
"access_token",
|
||||||
wf_db.ColumnTypeVarChar,
|
wf_db.ColumnTypeVarChar,
|
||||||
wf_db.OptionalInt{Set: true, Value: 512,})),
|
wf_db.OptionalInt{Set: true, Value: 512}).SetDefault("")),
|
||||||
dialect.CreateUniqueIndex("oauth_users", "oauth_users", "user_id", "provider", "client_id"),
|
dialect.CreateUniqueIndex("oauth_users", "oauth_users", "user_id", "provider", "client_id"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ func oauthSlack(db *datastore) error {
|
||||||
wf_db.ColumnTypeVarChar,
|
wf_db.ColumnTypeVarChar,
|
||||||
wf_db.OptionalInt{Set: true, Value: 128})))
|
wf_db.OptionalInt{Set: true, Value: 128})))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, builder := range builders {
|
for _, builder := range builders {
|
||||||
query, err := builder.ToSQL()
|
query, err := builder.ToSQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue