Commit 9440cc2f authored by Etienne Baqué's avatar Etienne Baqué

Removed id column from milestone_releases

Added migration to remove id column from table.
Removed uniqueness validation on MilestoneRelease
since the index over the two foreign_key plays
the same role.
parent 85332a46
......@@ -4,7 +4,6 @@ class MilestoneRelease < ApplicationRecord
belongs_to :milestone
belongs_to :release
validates :milestone_id, uniqueness: { scope: [:release_id] }
validate :same_project_between_milestone_and_release
private
......
# frozen_string_literal: true
class RemoveIdColumnFromIntermediateReleaseMilestones < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
remove_column :milestone_releases, :id
end
end
......@@ -2196,7 +2196,7 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do
t.index ["user_id"], name: "index_merge_trains_on_user_id"
end
create_table "milestone_releases", force: :cascade do |t|
create_table "milestone_releases", id: false, force: :cascade do |t|
t.bigint "milestone_id", null: false
t.bigint "release_id", null: false
t.index ["milestone_id", "release_id"], name: "index_miletone_releases_on_milestone_and_release", unique: true
......
......@@ -15,7 +15,14 @@ describe MilestoneRelease do
end
describe 'validations' do
it { is_expected.to validate_uniqueness_of(:milestone_id).scoped_to(:release_id) }
context 'when trying to create the same record in milestone_releases twice' do
it 'is not committing on the second time' do
described_class.create!(milestone_id: milestone.id, release_id: release.id)
expect do
described_class.create!(milestone_id: milestone.id, release_id: release.id)
end.to raise_error(ActiveRecord::RecordNotUnique)
end
end
context 'when milestone and release do not have the same project' do
it 'is not valid' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment