diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-29 18:06:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-29 18:06:24 +0000 |
commit | 8263f6ee3131cdea3c6041785c32771a6af0b24f (patch) | |
tree | 3dde0ed2466b10fa223eacbd51c78beb32009fbd /db | |
parent | eac0da9a47f0c7b8b970833d7d5b96cfee057bf7 (diff) | |
download | gitlab-ce-8263f6ee3131cdea3c6041785c32771a6af0b24f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20191125024005_cleanup_deploy_access_levels_for_removed_groups.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/db/post_migrate/20191125024005_cleanup_deploy_access_levels_for_removed_groups.rb b/db/post_migrate/20191125024005_cleanup_deploy_access_levels_for_removed_groups.rb new file mode 100644 index 00000000000..29592612a02 --- /dev/null +++ b/db/post_migrate/20191125024005_cleanup_deploy_access_levels_for_removed_groups.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class CleanupDeployAccessLevelsForRemovedGroups < ActiveRecord::Migration[5.2] + DOWNTIME = false + + def up + return unless Gitlab.ee? + + delete = <<~SQL + DELETE FROM protected_environment_deploy_access_levels d + USING protected_environments p + WHERE d.protected_environment_id=p.id + AND d.group_id IS NOT NULL + AND NOT EXISTS (SELECT 1 FROM project_group_links WHERE project_id=p.project_id AND group_id=d.group_id) + RETURNING * + SQL + + # At the time of writing there are 4 such records on GitLab.com, + # execution time is expected to be around 15ms. + records = execute(delete) + + logger = Gitlab::BackgroundMigration::Logger.build + records.to_a.each do |record| + logger.info record.as_json.merge(message: "protected_environments_deploy_access_levels was deleted") + end + end + + def down + # There is no pragmatic way to restore + # the records deleted in the `#up` method above. + end +end |