diff --git a/db/post_migrate/20240709094545_backfill_require_password_to_reauthentication.rb b/db/post_migrate/20240709094545_backfill_require_password_to_reauthentication.rb new file mode 100644 index 0000000000000000000000000000000000000000..fc03d03219aa1b4c1196bec86bbdfeb0258f9dba --- /dev/null +++ b/db/post_migrate/20240709094545_backfill_require_password_to_reauthentication.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class BackfillRequirePasswordToReauthentication < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '17.2' + restrict_gitlab_migration gitlab_schema: :gitlab_main + + def up + # SELECT "project_settings"."project_id" + # FROM "project_settings" + # WHERE "project_settings"."require_reauthentication_to_approve" IS NULL + # AND "project_settings"."project_id" >= + # ORDER BY "project_settings"."project_id" ASC + # LIMIT 1 + # OFFSET 100 + ProjectSetting.select(:project_id).where(require_reauthentication_to_approve: nil).each_batch(of: 100) do |batch| + batch.each do |setting| + # SELECT "projects"."require_password_to_approve" + # FROM "projects" + # WHERE "projects"."id" = + password_state = Project.where(id: setting.project_id).pick(:require_password_to_approve) + + # no need to update if we would just be overwriting `nil` with `nil` + next if password_state.nil? + + # UPDATE "project_settings" + # SET "require_reauthentication_to_approve" = + # WHERE "project_settings"."project_id" = + setting.update_columns require_reauthentication_to_approve: password_state + end + end + end + + def down + # no-op + + # Once data has been migrated it's unclear how to reverse to the previous state + end +end diff --git a/db/schema_migrations/20240709094545 b/db/schema_migrations/20240709094545 new file mode 100644 index 0000000000000000000000000000000000000000..acb194eafe68a04c69b9d47f2eb516d64aa408bf --- /dev/null +++ b/db/schema_migrations/20240709094545 @@ -0,0 +1 @@ +018a8b59a52e3bf69c77c9cd9b89e75c7b67e26e97adfadf9f7f25bfd03e5698 \ No newline at end of file