Skip to content
Snippets Groups Projects

Migrate data to system_access_group_microsoft_applications

Merged Andrew Evans requested to merge 495499-split-microsoft-applications into master
All threads resolved!
Files
16
# frozen_string_literal: true
class SplitMicrosoftApplicationsData < Gitlab::Database::Migration[2.2]
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
# Add dependent 'batched_background_migrations.queued_migration_version' values.
# DEPENDENT_BATCHED_BACKGROUND_MIGRATIONS = []
milestone '17.8'
restrict_gitlab_migration gitlab_schema: :gitlab_main_cell
def up
connection.execute <<~SQL
INSERT INTO system_access_group_microsoft_applications
(temp_source_id, group_id, enabled, tenant_xid, client_xid, login_endpoint,
graph_endpoint, encrypted_client_secret, encrypted_client_secret_iv, created_at, updated_at)
SELECT
id,
namespace_id,
enabled,
tenant_xid,
client_xid,
login_endpoint,
graph_endpoint,
encrypted_client_secret,
encrypted_client_secret_iv,
created_at,
updated_at
FROM
system_access_microsoft_applications
WHERE
namespace_id IS NOT NULL
ON CONFLICT DO NOTHING
SQL
connection.execute <<~SQL
INSERT INTO system_access_group_microsoft_graph_access_tokens
(temp_source_id, system_access_group_microsoft_application_id, group_id,
expires_in, encrypted_token, encrypted_token_iv, created_at, updated_at)
SELECT
mgat.id,
gma.id,
gma.group_id,
mgat.expires_in,
mgat.encrypted_token,
mgat.encrypted_token_iv,
mgat.created_at,
mgat.updated_at
FROM
system_access_microsoft_graph_access_tokens mgat
LEFT JOIN
system_access_group_microsoft_applications gma
ON gma.temp_source_id = mgat.system_access_microsoft_application_id
WHERE
gma.id IS NOT NULL
ON CONFLICT DO NOTHING
SQL
end
def down
connection.execute <<~SQL
DELETE FROM system_access_group_microsoft_applications
SQL
connection.execute <<~SQL
DELETE FROM system_access_group_microsoft_graph_access_tokens
SQL
end
end
Loading