mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 10:14:17 +08:00
Improve repository models and migration [SCI-1267]
This commit is contained in:
parent
0dc0c7d096
commit
85e81e9ea2
4 changed files with 4 additions and 8 deletions
|
@ -7,6 +7,7 @@ class Repository < ActiveRecord::Base
|
||||||
auto_strip_attributes :name, nullify: false
|
auto_strip_attributes :name, nullify: false
|
||||||
validates :name,
|
validates :name,
|
||||||
presence: true,
|
presence: true,
|
||||||
|
uniqueness: { scope: :team },
|
||||||
length: { maximum: Constants::NAME_MAX_LENGTH }
|
length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||||
validates :team, presence: true
|
validates :team, presence: true
|
||||||
validates :created_by, presence: true
|
validates :created_by, presence: true
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
class RepositoryColumn < ActiveRecord::Base
|
class RepositoryColumn < ActiveRecord::Base
|
||||||
belongs_to :repository
|
belongs_to :repository
|
||||||
belongs_to :team
|
|
||||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
has_many :repository_cells, dependent: :destroy
|
has_many :repository_cells, dependent: :destroy
|
||||||
has_many :repository_rows, through: :repository_cells
|
has_many :repository_rows, through: :repository_cells
|
||||||
|
@ -11,8 +10,8 @@ class RepositoryColumn < ActiveRecord::Base
|
||||||
validates :name,
|
validates :name,
|
||||||
presence: true,
|
presence: true,
|
||||||
length: { maximum: Constants::NAME_MAX_LENGTH },
|
length: { maximum: Constants::NAME_MAX_LENGTH },
|
||||||
uniqueness: { scope: :team, case_sensitive: true }
|
uniqueness: { scope: :repository, case_sensitive: true }
|
||||||
validates :team, :data_type, presence: true
|
|
||||||
validates :created_by, presence: true
|
validates :created_by, presence: true
|
||||||
validates :repository, presence: true
|
validates :repository, presence: true
|
||||||
|
validates :data_type, presence: true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
class RepositoryRow < ActiveRecord::Base
|
class RepositoryRow < ActiveRecord::Base
|
||||||
belongs_to :repository
|
belongs_to :repository
|
||||||
belongs_to :team
|
|
||||||
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
|
||||||
has_many :repository_cells, dependent: :destroy
|
has_many :repository_cells, dependent: :destroy
|
||||||
has_many :repository_columns, through: :repository_cells
|
has_many :repository_columns, through: :repository_cells
|
||||||
|
@ -9,6 +8,5 @@ class RepositoryRow < ActiveRecord::Base
|
||||||
validates :name,
|
validates :name,
|
||||||
presence: true,
|
presence: true,
|
||||||
length: { maximum: Constants::NAME_MAX_LENGTH }
|
length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||||
validates :team, presence: true
|
|
||||||
validates :created_by, presence: true
|
validates :created_by, presence: true
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,6 @@ class AddCustomRepositories < ActiveRecord::Migration
|
||||||
|
|
||||||
create_table :repository_columns do |t|
|
create_table :repository_columns do |t|
|
||||||
t.belongs_to :repository, index: true
|
t.belongs_to :repository, index: true
|
||||||
t.belongs_to :team, index: true
|
|
||||||
t.integer :created_by_id, null: false
|
t.integer :created_by_id, null: false
|
||||||
t.string :name
|
t.string :name
|
||||||
t.integer :data_type, null: false
|
t.integer :data_type, null: false
|
||||||
|
@ -22,9 +21,8 @@ class AddCustomRepositories < ActiveRecord::Migration
|
||||||
|
|
||||||
create_table :repository_rows do |t|
|
create_table :repository_rows do |t|
|
||||||
t.belongs_to :repository, index: true
|
t.belongs_to :repository, index: true
|
||||||
t.belongs_to :team, index: true
|
|
||||||
t.integer :created_by_id, null: false
|
t.integer :created_by_id, null: false
|
||||||
t.string :name
|
t.string :name, index: true
|
||||||
t.timestamps null: true
|
t.timestamps null: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue