From dbee81480b6a2a88535a0b042012c9fbf287e32b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 5 Apr 2018 10:53:39 +0200 Subject: [PATCH 1/2] Reschedule pipeline stages migration to run it again --- ...12101928_schedule_build_stage_migration.rb | 25 +++----------- ...1928_reschedule_builds_stages_migration.rb | 33 +++++++++++++++++++ db/schema.rb | 2 +- ...eschedule_builds_stages_migration_spec.rb} | 4 +-- 4 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 db/post_migrate/20180405101928_reschedule_builds_stages_migration.rb rename spec/migrations/{schedule_build_stage_migration_spec.rb => reschedule_builds_stages_migration_spec.rb} (88%) diff --git a/db/post_migrate/20180212101928_schedule_build_stage_migration.rb b/db/post_migrate/20180212101928_schedule_build_stage_migration.rb index df15b2cd9d4..0f61fa81832 100644 --- a/db/post_migrate/20180212101928_schedule_build_stage_migration.rb +++ b/db/post_migrate/20180212101928_schedule_build_stage_migration.rb @@ -1,26 +1,11 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'MigrateBuildStage'.freeze - BATCH_SIZE = 500 - - disable_ddl_transaction! - - class Build < ActiveRecord::Base - include EachBatch - self.table_name = 'ci_builds' - end + ## + # This migration has been rescheduled to run again, see + # `20180405101928_reschedule_builds_stages_migration.rb` + # def up - disable_statement_timeout - - Build.where('stage_id IS NULL').tap do |relation| - queue_background_migration_jobs_by_range_at_intervals(relation, - MIGRATION, - 5.minutes, - batch_size: BATCH_SIZE) - end + # noop end def down diff --git a/db/post_migrate/20180405101928_reschedule_builds_stages_migration.rb b/db/post_migrate/20180405101928_reschedule_builds_stages_migration.rb new file mode 100644 index 00000000000..e19387bce1e --- /dev/null +++ b/db/post_migrate/20180405101928_reschedule_builds_stages_migration.rb @@ -0,0 +1,33 @@ +class RescheduleBuildsStagesMigration < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + ## + # Rescheduled `20180212101928_schedule_build_stage_migration.rb` + # + + DOWNTIME = false + MIGRATION = 'MigrateBuildStage'.freeze + BATCH_SIZE = 500 + + disable_ddl_transaction! + + class Build < ActiveRecord::Base + include EachBatch + self.table_name = 'ci_builds' + end + + def up + disable_statement_timeout + + Build.where('stage_id IS NULL').tap do |relation| + queue_background_migration_jobs_by_range_at_intervals(relation, + MIGRATION, + 5.minutes, + batch_size: BATCH_SIZE) + end + end + + def down + # noop + end +end diff --git a/db/schema.rb b/db/schema.rb index 06fc1a9d7e9..1dd87c12144 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180327101207) do +ActiveRecord::Schema.define(version: 20180405101928) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/migrations/schedule_build_stage_migration_spec.rb b/spec/migrations/reschedule_builds_stages_migration_spec.rb similarity index 88% rename from spec/migrations/schedule_build_stage_migration_spec.rb rename to spec/migrations/reschedule_builds_stages_migration_spec.rb index e2ca35447fb..ae432f7338f 100644 --- a/spec/migrations/schedule_build_stage_migration_spec.rb +++ b/spec/migrations/reschedule_builds_stages_migration_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -require Rails.root.join('db', 'post_migrate', '20180212101928_schedule_build_stage_migration') +require Rails.root.join('db', 'post_migrate', '20180405101928_reschedule_builds_stages_migration') -describe ScheduleBuildStageMigration, :sidekiq, :migration do +describe RescheduleBuildsStagesMigration, :sidekiq, :migration do let(:projects) { table(:projects) } let(:pipelines) { table(:ci_pipelines) } let(:stages) { table(:ci_stages) } From 8d012198778fee5b76b777c1a18b60bde62d6f8e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 5 Apr 2018 12:08:04 +0200 Subject: [PATCH 2/2] Update entities in pipeline stages migration test --- spec/migrations/reschedule_builds_stages_migration_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/migrations/reschedule_builds_stages_migration_spec.rb b/spec/migrations/reschedule_builds_stages_migration_spec.rb index ae432f7338f..3bfd9dd9f6b 100644 --- a/spec/migrations/reschedule_builds_stages_migration_spec.rb +++ b/spec/migrations/reschedule_builds_stages_migration_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20180405101928_reschedule_builds_stages_migration') describe RescheduleBuildsStagesMigration, :sidekiq, :migration do + let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:pipelines) { table(:ci_pipelines) } let(:stages) { table(:ci_stages) } @@ -10,7 +11,8 @@ describe RescheduleBuildsStagesMigration, :sidekiq, :migration do before do stub_const("#{described_class}::BATCH_SIZE", 1) - projects.create!(id: 123, name: 'gitlab', path: 'gitlab-ce') + namespaces.create(id: 12, name: 'gitlab-org', path: 'gitlab-org') + projects.create!(id: 123, namespace_id: 12, name: 'gitlab', path: 'gitlab') pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a') stages.create!(id: 1, project_id: 123, pipeline_id: 1, name: 'test')