From 85e81e9ea24a1f0d4c86d0f84116a7849185bf45 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 17 May 2017 10:04:07 +0200 Subject: [PATCH] Improve repository models and migration [SCI-1267] --- app/models/repository.rb | 1 + app/models/repository_column.rb | 5 ++--- app/models/repository_row.rb | 2 -- db/migrate/20170515141252_add_custom_repositories.rb | 4 +--- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 21b6bd044..9427611a6 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -7,6 +7,7 @@ class Repository < ActiveRecord::Base auto_strip_attributes :name, nullify: false validates :name, presence: true, + uniqueness: { scope: :team }, length: { maximum: Constants::NAME_MAX_LENGTH } validates :team, presence: true validates :created_by, presence: true diff --git a/app/models/repository_column.rb b/app/models/repository_column.rb index 68b2967df..8c00b2f28 100644 --- a/app/models/repository_column.rb +++ b/app/models/repository_column.rb @@ -1,6 +1,5 @@ class RepositoryColumn < ActiveRecord::Base belongs_to :repository - belongs_to :team belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User' has_many :repository_cells, dependent: :destroy has_many :repository_rows, through: :repository_cells @@ -11,8 +10,8 @@ class RepositoryColumn < ActiveRecord::Base validates :name, presence: true, length: { maximum: Constants::NAME_MAX_LENGTH }, - uniqueness: { scope: :team, case_sensitive: true } - validates :team, :data_type, presence: true + uniqueness: { scope: :repository, case_sensitive: true } validates :created_by, presence: true validates :repository, presence: true + validates :data_type, presence: true end diff --git a/app/models/repository_row.rb b/app/models/repository_row.rb index 3765b24d8..0a80724f6 100644 --- a/app/models/repository_row.rb +++ b/app/models/repository_row.rb @@ -1,6 +1,5 @@ class RepositoryRow < ActiveRecord::Base belongs_to :repository - belongs_to :team belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User' has_many :repository_cells, dependent: :destroy has_many :repository_columns, through: :repository_cells @@ -9,6 +8,5 @@ class RepositoryRow < ActiveRecord::Base validates :name, presence: true, length: { maximum: Constants::NAME_MAX_LENGTH } - validates :team, presence: true validates :created_by, presence: true end diff --git a/db/migrate/20170515141252_add_custom_repositories.rb b/db/migrate/20170515141252_add_custom_repositories.rb index 28813deb0..5a4c0aa72 100644 --- a/db/migrate/20170515141252_add_custom_repositories.rb +++ b/db/migrate/20170515141252_add_custom_repositories.rb @@ -11,7 +11,6 @@ class AddCustomRepositories < ActiveRecord::Migration create_table :repository_columns do |t| t.belongs_to :repository, index: true - t.belongs_to :team, index: true t.integer :created_by_id, null: false t.string :name t.integer :data_type, null: false @@ -22,9 +21,8 @@ class AddCustomRepositories < ActiveRecord::Migration create_table :repository_rows do |t| t.belongs_to :repository, index: true - t.belongs_to :team, index: true t.integer :created_by_id, null: false - t.string :name + t.string :name, index: true t.timestamps null: true end