diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 21:08:55 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-13 21:08:55 +0000 |
commit | a5650b86b5a809d3b7c754afd5ff5671e9bcc584 (patch) | |
tree | 6a53414f01dae4b5716a94c8d33136616c8b3eb1 /db/post_migrate | |
parent | e689e858ede41a34b1e9132eba6a602632e6885e (diff) | |
download | gitlab-ce-a5650b86b5a809d3b7c754afd5ff5671e9bcc584.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20200506154421_migrate_scim_identities_to_saml_for_new_users.rb | 37 | ||||
-rw-r--r-- | db/post_migrate/20200508091106_remove_bot_type.rb | 29 |
2 files changed, 66 insertions, 0 deletions
diff --git a/db/post_migrate/20200506154421_migrate_scim_identities_to_saml_for_new_users.rb b/db/post_migrate/20200506154421_migrate_scim_identities_to_saml_for_new_users.rb new file mode 100644 index 00000000000..718e788aad7 --- /dev/null +++ b/db/post_migrate/20200506154421_migrate_scim_identities_to_saml_for_new_users.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class MigrateScimIdentitiesToSamlForNewUsers < ActiveRecord::Migration[6.0] + DOWNTIME = false + + class ScimIdentity < ActiveRecord::Base + self.table_name = 'scim_identities' + + belongs_to :user + + include ::EachBatch + end + + class Identity < ActiveRecord::Base + self.table_name = 'identities' + + belongs_to :saml_provider + end + + def up + users_with_saml_provider = Identity.select('user_id').joins(:saml_provider) + + ScimIdentity.each_batch do |relation| + identity_records = relation + .select("scim_identities.extern_uid, 'group_saml', scim_identities.user_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, saml_providers.id") + .joins(:user) + .joins('inner join saml_providers on saml_providers.group_id=scim_identities.group_id') + .where("date_trunc('second',scim_identities.created_at) at time zone 'UTC' = date_trunc('second',users.created_at)") + .where.not(user_id: users_with_saml_provider) + + execute "insert into identities (extern_uid, provider, user_id, created_at, updated_at, saml_provider_id) #{identity_records.to_sql} on conflict do nothing" + end + end + + def down + end +end diff --git a/db/post_migrate/20200508091106_remove_bot_type.rb b/db/post_migrate/20200508091106_remove_bot_type.rb new file mode 100644 index 00000000000..2afcf5308e7 --- /dev/null +++ b/db/post_migrate/20200508091106_remove_bot_type.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class RemoveBotType < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + remove_concurrent_index_by_name :users, 'index_users_on_bot_type' + + with_lock_retries do + remove_column :users, :bot_type + end + end + + def down + unless column_exists?(:users, :bot_type) + with_lock_retries do + add_column :users, :bot_type, :integer, limit: 2 # rubocop:disable Migration/AddColumnsToWideTables + end + end + + execute 'UPDATE users set bot_type = user_type WHERE user_type IN(1,2,3,6)' + + add_concurrent_index :users, :bot_type + end +end |