20240916190140_remove_crypto_scope_values.rb 665 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. class RemoveCryptoScopeValues < ActiveRecord::Migration[7.1]
  3. def up
  4. applications.in_batches do |records|
  5. records.update_all(<<~SQL.squish)
  6. scopes = TRIM(REPLACE(scopes, 'crypto', ''))
  7. SQL
  8. end
  9. tokens.in_batches do |records|
  10. records.update_all(<<~SQL.squish)
  11. scopes = TRIM(REPLACE(scopes, 'crypto', ''))
  12. SQL
  13. end
  14. end
  15. def down
  16. raise ActiveRecord::IrreversibleMigration
  17. end
  18. private
  19. def applications
  20. Doorkeeper::Application
  21. .where("scopes LIKE '%crypto%'")
  22. end
  23. def tokens
  24. Doorkeeper::AccessToken
  25. .where("scopes LIKE '%crypto%'")
  26. end
  27. end