diff options
Diffstat (limited to 'db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb')
-rw-r--r-- | db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb b/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb new file mode 100644 index 00000000000..f47ff244d7a --- /dev/null +++ b/db/post_migrate/20210610102413_migrate_protected_attribute_to_pending_builds.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class MigrateProtectedAttributeToPendingBuilds < ActiveRecord::Migration[6.1] + include ::Gitlab::Database::DynamicModelHelpers + + disable_ddl_transaction! + + def up + return unless Gitlab.dev_or_test_env? || Gitlab.com? + + each_batch_range('ci_pending_builds', of: 1000) do |min, max| + execute <<~SQL + UPDATE ci_pending_builds + SET protected = true + FROM ci_builds + WHERE ci_pending_builds.build_id = ci_builds.id + AND ci_builds.protected = true + AND ci_pending_builds.id BETWEEN #{min} AND #{max} + SQL + end + end + + def down + # no op + end +end |