2020-04-21 00:18:23 +02:00
|
|
|
/*
|
2021-04-06 23:24:07 +02:00
|
|
|
* Copyright © 2020-2021 A Bunch Tell LLC.
|
2020-04-21 00:18:23 +02:00
|
|
|
*
|
|
|
|
* This file is part of WriteFreely.
|
|
|
|
*
|
|
|
|
* WriteFreely is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, included
|
|
|
|
* in the LICENSE file in this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
|
2021-04-06 23:24:07 +02:00
|
|
|
wf_db "github.com/writefreely/writefreely/db"
|
2020-04-21 00:18:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func oauthInvites(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("invite_code", wf_db.ColumnTypeChar, wf_db.OptionalInt{
|
|
|
|
Set: true,
|
|
|
|
Value: 6,
|
|
|
|
}).SetNullable(true)),
|
|
|
|
}
|
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|