It's not straightforward to remove these constraints in SQLite, so this just skips it entirely. Since both of these migrations are part of the same WF release, this should have minimal impact on admins.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
wf_db "github.com/writeas/writefreely/db"
|
|
)
|
|
|
|
func oauth(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 {
|
|
createTableUsersOauth, err := dialect.
|
|
Table("oauth_users").
|
|
SetIfNotExists(true).
|
|
Column(dialect.Column("user_id", wf_db.ColumnTypeInteger, wf_db.UnsetSize)).
|
|
Column(dialect.Column("remote_user_id", wf_db.ColumnTypeInteger, wf_db.UnsetSize)).
|
|
ToSQL()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
createTableOauthClientState, err := dialect.
|
|
Table("oauth_client_states").
|
|
SetIfNotExists(true).
|
|
Column(dialect.Column("state", wf_db.ColumnTypeVarChar, wf_db.OptionalInt{Set: true, Value: 255})).
|
|
Column(dialect.Column("used", wf_db.ColumnTypeBool, wf_db.UnsetSize)).
|
|
Column(dialect.Column("created_at", wf_db.ColumnTypeDateTime, wf_db.UnsetSize).SetDefaultCurrentTimestamp()).
|
|
UniqueConstraint("state").
|
|
ToSQL()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, table := range []string{createTableUsersOauth, createTableOauthClientState} {
|
|
if _, err := tx.ExecContext(ctx, table); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|