RepositoryTemplate migration and dependant fix [SCI-11708] (#8461)

This commit is contained in:
Martin Artnik 2025-05-05 10:42:24 +02:00 committed by GitHub
parent 8f2efe62fc
commit ad5b43cf5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 9 deletions

View file

@ -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(

View file

@ -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

View file

@ -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