mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-29 23:46:32 +08:00
RepositoryTemplate migration and dependant fix [SCI-11708] (#8461)
This commit is contained in:
parent
8f2efe62fc
commit
ad5b43cf5e
3 changed files with 6 additions and 9 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class RepositoryTemplate < ApplicationRecord
|
||||
belongs_to :team, inverse_of: :repository_templates
|
||||
has_many :repositories, inverse_of: :repository_template, dependent: :destroy
|
||||
has_many :repositories, inverse_of: :repository_template, dependent: :nullify
|
||||
|
||||
def self.default
|
||||
RepositoryTemplate.new(
|
||||
|
|
|
|||
|
|
@ -3,17 +3,14 @@
|
|||
class AddRepositoryTemplatesToTeams < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
Team.find_each do |team|
|
||||
RepositoryTemplate.default.update(team: team)
|
||||
RepositoryTemplate.cell_lines.update(team: team)
|
||||
RepositoryTemplate.equipment.update(team: team)
|
||||
RepositoryTemplate.chemicals_and_reagents.update(team: team)
|
||||
RepositoryTemplate.default.update!(team: team)
|
||||
RepositoryTemplate.cell_lines.update!(team: team)
|
||||
RepositoryTemplate.equipment.update!(team: team)
|
||||
RepositoryTemplate.chemicals_and_reagents.update!(team: team)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
Repository.update_all(repository_template_id: nil)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
RepositoryTemplate.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@ describe RepositoryTemplate, type: :model do
|
|||
|
||||
describe 'Relations' do
|
||||
it { should belong_to :team }
|
||||
it { should have_many(:repositories).dependent(:destroy) }
|
||||
it { should have_many(:repositories).dependent(:nullify) }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue