summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-04-24 14:53:46 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-04-24 15:48:10 +0200
commitc9dc51111d53aba4e456afaade4bf9ad82c4b28c (patch)
treede742fbd8de072005fef8a55f96c8092aca52ce1
parentd7e8bfac48e5b142348cd503f39387e9d88a3b85 (diff)
downloadgitlab-ce-c9dc51111d53aba4e456afaade4bf9ad82c4b28c.tar.gz
Rename stage index column name to priority column
-rw-r--r--app/models/ci/stage.rb6
-rw-r--r--app/services/ci/ensure_stage_service.rb2
-rw-r--r--db/migrate/20180417101940_add_index_to_ci_stage.rb2
-rw-r--r--db/schema.rb2
-rw-r--r--lib/gitlab/background_migration/migrate_stage_index.rb8
-rw-r--r--lib/gitlab/ci/pipeline/seed/stage.rb2
-rw-r--r--spec/factories/ci/stages.rb2
-rw-r--r--spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/create_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb2
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml2
-rw-r--r--spec/migrations/schedule_stages_index_migration_spec.rb2
-rw-r--r--spec/models/ci/stage_spec.rb12
13 files changed, 24 insertions, 24 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
index 5a77a909b9d..9a913213bb9 100644
--- a/app/models/ci/stage.rb
+++ b/app/models/ci/stage.rb
@@ -17,7 +17,7 @@ module Ci
validates :project, presence: true
validates :pipeline, presence: true
validates :name, presence: true
- validates :index, presence: true
+ validates :priority, presence: true
end
after_initialize do
@@ -25,9 +25,9 @@ module Ci
end
before_validation unless: :importing? do
- next if index.present?
+ next if priority.present?
- self.index = statuses.select(:stage_idx)
+ self.priority = statuses.select(:stage_idx)
.where('stage_idx IS NOT NULL')
.group(:stage_idx)
.order('COUNT(*) DESC')
diff --git a/app/services/ci/ensure_stage_service.rb b/app/services/ci/ensure_stage_service.rb
index 447cbfd73f5..e3e3e2d03c1 100644
--- a/app/services/ci/ensure_stage_service.rb
+++ b/app/services/ci/ensure_stage_service.rb
@@ -42,7 +42,7 @@ module Ci
def create_stage
Ci::Stage.create!(name: @build.stage,
- index: @build.stage_idx,
+ priority: @build.stage_idx,
pipeline: @build.pipeline,
project: @build.project)
end
diff --git a/db/migrate/20180417101940_add_index_to_ci_stage.rb b/db/migrate/20180417101940_add_index_to_ci_stage.rb
index f14bbe458ae..ec21431b2a5 100644
--- a/db/migrate/20180417101940_add_index_to_ci_stage.rb
+++ b/db/migrate/20180417101940_add_index_to_ci_stage.rb
@@ -4,6 +4,6 @@ class AddIndexToCiStage < ActiveRecord::Migration
DOWNTIME = false
def change
- add_column :ci_stages, :index, :integer
+ add_column :ci_stages, :priority, :integer
end
end
diff --git a/db/schema.rb b/db/schema.rb
index bc9a1892b5c..9f371cdcb41 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -486,7 +486,7 @@ ActiveRecord::Schema.define(version: 20180420080616) do
t.string "name"
t.integer "status"
t.integer "lock_version"
- t.integer "index"
+ t.integer "priority"
end
add_index "ci_stages", ["pipeline_id", "name"], name: "index_ci_stages_on_pipeline_id_and_name", unique: true, using: :btree
diff --git a/lib/gitlab/background_migration/migrate_stage_index.rb b/lib/gitlab/background_migration/migrate_stage_index.rb
index 9ba3d7eb455..140c75054df 100644
--- a/lib/gitlab/background_migration/migrate_stage_index.rb
+++ b/lib/gitlab/background_migration/migrate_stage_index.rb
@@ -26,19 +26,19 @@ module Gitlab
FROM freqs
)
- UPDATE ci_stages SET index = indexes.index
+ UPDATE ci_stages SET priority = indexes.index
FROM indexes WHERE indexes.stage_id = ci_stages.id
- AND ci_stages.index IS NULL;
+ AND ci_stages.priority IS NULL;
SQL
else
<<~SQL
UPDATE ci_stages
- SET index =
+ SET priority =
(SELECT stage_idx FROM ci_builds
WHERE ci_builds.stage_id = ci_stages.id
GROUP BY ci_builds.stage_idx ORDER BY COUNT(*) DESC LIMIT 1)
WHERE ci_stages.id BETWEEN #{start_id} AND #{stop_id}
- AND ci_stages.index IS NULL
+ AND ci_stages.priority IS NULL
SQL
end
end
diff --git a/lib/gitlab/ci/pipeline/seed/stage.rb b/lib/gitlab/ci/pipeline/seed/stage.rb
index 75ab20a52ef..2ff80bdf3b9 100644
--- a/lib/gitlab/ci/pipeline/seed/stage.rb
+++ b/lib/gitlab/ci/pipeline/seed/stage.rb
@@ -19,7 +19,7 @@ module Gitlab
def attributes
{ name: @attributes.fetch(:name),
- index: @attributes.fetch(:index),
+ priority: @attributes.fetch(:index),
pipeline: @pipeline,
project: @pipeline.project }
end
diff --git a/spec/factories/ci/stages.rb b/spec/factories/ci/stages.rb
index 3711d3c7c49..f4f73a67e9a 100644
--- a/spec/factories/ci/stages.rb
+++ b/spec/factories/ci/stages.rb
@@ -21,7 +21,7 @@ FactoryBot.define do
pipeline factory: :ci_empty_pipeline
name 'test'
- index 1
+ priority 1
status 'pending'
end
end
diff --git a/spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb b/spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
index 0bd27d3004c..d20d3ebad31 100644
--- a/spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
+++ b/spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
@@ -26,10 +26,10 @@ describe Gitlab::BackgroundMigration::MigrateStageIndex, :migration, schema: 201
end
it 'correctly migrates stages indices' do
- expect(stages.all.pluck(:index)).to all(be_nil)
+ expect(stages.all.pluck(:priority)).to all(be_nil)
described_class.new.perform(100, 101)
- expect(stages.all.pluck(:index)).to eq [2, 3]
+ expect(stages.all.pluck(:priority)).to eq [2, 3]
end
end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/create_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
index f03ed0f508a..7513ba15811 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
@@ -17,7 +17,7 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
context 'when pipeline is ready to be saved' do
before do
- pipeline.stages.build(name: 'test', index: 0, project: project)
+ pipeline.stages.build(name: 'test', priority: 0, project: project)
step.perform!
end
diff --git a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
index 70c9985f5df..b4bd0976268 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
@@ -25,7 +25,7 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
it 'returns hash attributes of a stage' do
expect(subject.attributes).to be_a Hash
expect(subject.attributes)
- .to include(:name, :index, :pipeline, :project)
+ .to include(:name, :priority, :pipeline, :project)
end
end
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index 512e778743f..2a23db5e666 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -231,8 +231,8 @@ Ci::Pipeline:
Ci::Stage:
- id
- name
-- index
- status
+- priority
- lock_version
- project_id
- pipeline_id
diff --git a/spec/migrations/schedule_stages_index_migration_spec.rb b/spec/migrations/schedule_stages_index_migration_spec.rb
index e47a43ff325..b8d0f711a25 100644
--- a/spec/migrations/schedule_stages_index_migration_spec.rb
+++ b/spec/migrations/schedule_stages_index_migration_spec.rb
@@ -21,7 +21,7 @@ describe ScheduleStagesIndexMigration, :sidekiq, :migration do
it 'schedules delayed background migrations in batches' do
Sidekiq::Testing.fake! do
Timecop.freeze do
- expect(stages.all).to all(have_attributes(index: be_nil))
+ expect(stages.all).to all(have_attributes(priority: be_nil))
migrate!
diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb
index 20db6394e51..f6cc61b3e9e 100644
--- a/spec/models/ci/stage_spec.rb
+++ b/spec/models/ci/stage_spec.rb
@@ -89,9 +89,9 @@ describe Ci::Stage, :models do
end
describe '#index' do
- context 'when stage has been imported and does not have index set' do
+ context 'when stage has been imported and does not have priority index set' do
before do
- stage.update_column(:index, nil)
+ stage.update_column(:priority, nil)
end
context 'when stage has statuses' do
@@ -100,21 +100,21 @@ describe Ci::Stage, :models do
end
it 'recalculates index before updating status' do
- expect(stage.reload.index).to be_nil
+ expect(stage.reload.priority).to be_nil
stage.update_status
- expect(stage.reload.index).to eq 10
+ expect(stage.reload.priority).to eq 10
end
end
context 'when stage does not have statuses' do
it 'fallbacks to zero' do
- expect(stage.reload.index).to be_nil
+ expect(stage.reload.priority).to be_nil
stage.update_status
- expect(stage.reload.index).to eq 0
+ expect(stage.reload.priority).to eq 0
end
end
end