mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Move UserApiKey scopes to dedicated table (#10704)
This has no functional impact yet, but it is the first step in adding more granular scopes to UserApiKeys
This commit is contained in:
46
db/migrate/20200918095554_add_user_api_key_scopes.rb
Normal file
46
db/migrate/20200918095554_add_user_api_key_scopes.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddUserApiKeyScopes < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :user_api_key_scopes do |t|
|
||||
t.integer :user_api_key_id, null: false
|
||||
t.string :name, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :user_api_key_scopes, :user_api_key_id
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
execute <<~SQL
|
||||
INSERT INTO user_api_key_scopes
|
||||
(
|
||||
user_api_key_id,
|
||||
name,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
SELECT
|
||||
user_api_keys.id,
|
||||
unnest(user_api_keys.scopes),
|
||||
created_at,
|
||||
updated_at
|
||||
FROM user_api_keys
|
||||
SQL
|
||||
|
||||
Migration::SafeMigrate.disable!
|
||||
change_column_null :user_api_keys, :scopes, true
|
||||
change_column_default :user_api_keys, :scopes, nil
|
||||
Migration::SafeMigrate.enable!
|
||||
|
||||
Migration::ColumnDropper.mark_readonly(:user_api_keys, :scopes)
|
||||
end
|
||||
|
||||
dir.down do
|
||||
change_column_null :user_api_keys, :scopes, false
|
||||
change_column_default :user_api_keys, :scopes, []
|
||||
Migration::ColumnDropper.drop_readonly(:user_api_keys, :scopes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user