A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
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.
 
 
 
 
 

47 lines
1.1 KiB

  1. /*
  2. * Copyright © 2020-2021 Musing Studio LLC.
  3. *
  4. * This file is part of WriteFreely.
  5. *
  6. * WriteFreely is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License, included
  8. * in the LICENSE file in this source code package.
  9. */
  10. package migrations
  11. import (
  12. "context"
  13. "database/sql"
  14. wf_db "github.com/writefreely/writefreely/db"
  15. )
  16. func oauthAttach(db *datastore) error {
  17. dialect := wf_db.DialectMySQL
  18. if db.driverName == driverSQLite {
  19. dialect = wf_db.DialectSQLite
  20. }
  21. return wf_db.RunTransactionWithOptions(context.Background(), db.DB, &sql.TxOptions{}, func(ctx context.Context, tx *sql.Tx) error {
  22. builders := []wf_db.SQLBuilder{
  23. dialect.
  24. AlterTable("oauth_client_states").
  25. AddColumn(dialect.
  26. Column(
  27. "attach_user_id",
  28. wf_db.ColumnTypeInteger,
  29. wf_db.OptionalInt{Set: true, Value: 24}).SetNullable(true)),
  30. }
  31. for _, builder := range builders {
  32. query, err := builder.ToSQL()
  33. if err != nil {
  34. return err
  35. }
  36. if _, err := tx.ExecContext(ctx, query); err != nil {
  37. return err
  38. }
  39. }
  40. return nil
  41. })
  42. }