mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Migrate existing OIDC account data
This commit is contained in:
15
db/migrate/20240213044159_copy_oidc_data_to_oidc_accounts.rb
Normal file
15
db/migrate/20240213044159_copy_oidc_data_to_oidc_accounts.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CopyOidcDataToOidcAccounts < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
execute <<~SQL.squish
|
||||
INSERT INTO oidc_accounts (user_id, provider, uid, created_at, updated_at)
|
||||
SELECT id, provider, uid, updated_at, updated_at
|
||||
FROM spree_users WHERE provider IS NOT NULL
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
execute "DELETE FROM oidc_accounts"
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_02_13_042618) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_02_13_044159) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require_relative '../../db/migrate/20240213044159_copy_oidc_data_to_oidc_accounts'
|
||||
|
||||
describe CopyOidcDataToOidcAccounts do
|
||||
describe "up" do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:oidc_user) {
|
||||
create(:user, provider: "openid_connect", uid: "ofn@example.net")
|
||||
}
|
||||
|
||||
it "copies data" do
|
||||
expect { subject.up }.to change {
|
||||
OidcAccount.count
|
||||
}.from(0).to(1)
|
||||
|
||||
account = OidcAccount.first
|
||||
|
||||
expect(account.user).to eq oidc_user
|
||||
expect(account.provider).to eq oidc_user.provider
|
||||
expect(account.uid).to eq oidc_user.uid
|
||||
expect(account.token).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "down" do
|
||||
it "removes data" do
|
||||
user = create(:user)
|
||||
OidcAccount.create!(user:, provider: "oidc", uid: "ofn@exmpl.net")
|
||||
|
||||
expect { subject.down }.to change { OidcAccount.count }.from(1).to(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user