diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-05-09 17:09:25 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-05-09 17:09:25 +0000 |
commit | c4957ea958bbc9fcf30d59c8319ef5bf71d01219 (patch) | |
tree | 4a64ef11c29e74924e931142029060a3822dddc9 /spec/migrations | |
parent | 0135ea6db4c1cc3968691343c6b7cac191502cb8 (diff) | |
parent | 96b9c070ad102ec1004921ff318e2a0a591a5a9c (diff) | |
download | gitlab-ce-c4957ea958bbc9fcf30d59c8319ef5bf71d01219.tar.gz |
Merge branch 'master' into 'fix-project-mirror-data-schema'
# Conflicts:
# db/schema.rb
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/add_pipeline_build_foreign_key_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/migrations/add_pipeline_build_foreign_key_spec.rb b/spec/migrations/add_pipeline_build_foreign_key_spec.rb new file mode 100644 index 00000000000..e9413f52f19 --- /dev/null +++ b/spec/migrations/add_pipeline_build_foreign_key_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20180420010016_add_pipeline_build_foreign_key.rb') + +describe AddPipelineBuildForeignKey, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:pipelines) { table(:ci_pipelines) } + let(:builds) { table(:ci_builds) } + + before do + namespaces.create(id: 10, name: 'gitlab-org', path: 'gitlab-org') + projects.create!(id: 11, namespace_id: 10, name: 'gitlab', path: 'gitlab') + pipelines.create!(id: 12, project_id: 11, ref: 'master', sha: 'adf43c3a') + + builds.create!(id: 101, commit_id: 12, project_id: 11) + builds.create!(id: 102, commit_id: 222, project_id: 11) + builds.create!(id: 103, commit_id: 333, project_id: 11) + builds.create!(id: 104, commit_id: 12, project_id: 11) + builds.create!(id: 106, commit_id: nil, project_id: 11) + builds.create!(id: 107, commit_id: 12, project_id: nil) + end + + it 'adds foreign key after removing orphans' do + expect(builds.all.count).to eq 6 + expect(foreign_key_exists?(:ci_builds, :ci_pipelines, column: :commit_id)).to be_falsey + + migrate! + + expect(builds.all.pluck(:id)).to eq [101, 104] + expect(foreign_key_exists?(:ci_builds, :ci_pipelines, column: :commit_id)).to be_truthy + end +end |