Commit b465c62f authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add DesignManagement::Version model

The DesignManagement::Version will keep track of different versions of
a design that were uploaded. Every time a new version gets uploaded we
create a new version so we know the last commit that touched the file.

It will also make it easy to track which version was commented on.
parent 3fdfd27c
......@@ -1044,6 +1044,13 @@ ActiveRecord::Schema.define(version: 20190305162221) do
t.index ["project_id"], name: "index_design_management_designs_on_project_id", using: :btree
end
create_table "design_management_versions", id: :bigserial, force: :cascade do |t|
t.bigint "design_management_design_id", null: false
t.binary "sha", null: false
t.index ["design_management_design_id"], name: "index_design_management_versions_on_design_management_design_id", using: :btree
t.index ["sha"], name: "index_design_management_versions_on_sha", unique: true, using: :btree
end
create_table "draft_notes", id: :bigserial, force: :cascade do |t|
t.integer "merge_request_id", null: false
t.integer "author_id", null: false
......@@ -3416,6 +3423,7 @@ ActiveRecord::Schema.define(version: 20190305162221) do
add_foreign_key "deployments", "projects", name: "fk_b9a3851b82", on_delete: :cascade
add_foreign_key "design_management_designs", "issues", on_delete: :cascade
add_foreign_key "design_management_designs", "projects", on_delete: :cascade
add_foreign_key "design_management_versions", "design_management_designs", on_delete: :cascade
add_foreign_key "draft_notes", "merge_requests", on_delete: :cascade
add_foreign_key "draft_notes", "users", column: "author_id", on_delete: :cascade
add_foreign_key "environments", "projects", name: "fk_d1c8c1da6a", on_delete: :cascade
......
# frozen_string_literal: true
module DesignManagement
class Version < ApplicationRecord
include ShaAttribute
belongs_to :design, class_name: "DesignManagement::Design", foreign_key: 'design_management_design_id'
has_one :project, through: :design
has_one :issue, through: :design
# This is a polymorphic association, so we can't count on FK's to delete the
# data
has_many :notes, as: :noteable, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
validates :sha, :design, presence: true
validates :sha, uniqueness: { case_sensitive: false }
sha_attribute :sha
end
end
class CreateDesignVersions < ActiveRecord::Migration[5.0]
def change
create_table :design_management_versions, id: :bigserial do |t|
t.references :design_management_design, foreign_key: { on_delete: :cascade }, type: :bigint, null: false, index: true
t.binary :sha, null: false, index: { unique: true }, limit: 20
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :design_version, class: DesignManagement::Version do
design
sequence(:sha) { |n| Digest::SHA1.hexdigest("commit-like-#{n}") }
end
end
# frozen_string_literal: true
require 'rails_helper'
describe DesignManagement::Version do
describe 'relations' do
it { is_expected.to belong_to(:design) }
it { is_expected.to have_one(:issue) }
it { is_expected.to have_one(:project) }
it { is_expected.to have_many(:notes).dependent(:delete_all) }
end
describe 'validations' do
subject(:design_version) { build(:design_version) }
it { is_expected.to be_valid }
it { is_expected.to validate_presence_of(:design) }
it { is_expected.to validate_presence_of(:sha) }
it { is_expected.to validate_uniqueness_of(:sha).case_insensitive }
end
end
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