mirror of https://github.com/writeas/writefreely
A focused writing and publishing space.
https://write.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
852 B
37 lines
852 B
5 years ago
|
package migrations
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql"
|
||
|
|
||
|
wf_db "github.com/writeas/writefreely/db"
|
||
|
)
|
||
|
|
||
|
func oauthAttach(db *datastore) error {
|
||
|
dialect := wf_db.DialectMySQL
|
||
|
if db.driverName == driverSQLite {
|
||
|
dialect = wf_db.DialectSQLite
|
||
|
}
|
||
|
return wf_db.RunTransactionWithOptions(context.Background(), db.DB, &sql.TxOptions{}, func(ctx context.Context, tx *sql.Tx) error {
|
||
|
builders := []wf_db.SQLBuilder{
|
||
|
dialect.
|
||
|
AlterTable("oauth_client_states").
|
||
|
AddColumn(dialect.
|
||
|
Column(
|
||
|
"attach_user_id",
|
||
|
wf_db.ColumnTypeInteger,
|
||
|
wf_db.OptionalInt{Set: true, Value: 24,}).SetNullable(false).SetDefault("0")),
|
||
|
}
|
||
|
for _, builder := range builders {
|
||
|
query, err := builder.ToSQL()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if _, err := tx.ExecContext(ctx, query); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
})
|
||
|
}
|