From 6f836c45aa5862cdfd65877c99252fcb28ab4da1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 18 Sep 2024 05:27:50 -0400 Subject: [PATCH] Remove `crypto` values from doorkeeper application/token `scopes` (#31945) --- ...240916190140_remove_crypto_scope_values.rb | 33 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240916190140_remove_crypto_scope_values.rb diff --git a/db/migrate/20240916190140_remove_crypto_scope_values.rb b/db/migrate/20240916190140_remove_crypto_scope_values.rb new file mode 100644 index 0000000000..8caf5b801d --- /dev/null +++ b/db/migrate/20240916190140_remove_crypto_scope_values.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class RemoveCryptoScopeValues < ActiveRecord::Migration[7.1] + def up + applications.in_batches do |records| + records.update_all(<<~SQL.squish) + scopes = TRIM(REPLACE(scopes, 'crypto', '')) + SQL + end + + tokens.in_batches do |records| + records.update_all(<<~SQL.squish) + scopes = TRIM(REPLACE(scopes, 'crypto', '')) + SQL + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end + + private + + def applications + Doorkeeper::Application + .where("scopes LIKE '%crypto%'") + end + + def tokens + Doorkeeper::AccessToken + .where("scopes LIKE '%crypto%'") + end +end diff --git a/db/schema.rb b/db/schema.rb index e9aa78c205..f9f2d97395 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_09_09_014637) do +ActiveRecord::Schema[7.1].define(version: 2024_09_16_190140) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"