Skip to content

Commit

Permalink
fix: don't regenerate contracts during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosteiner committed Nov 29, 2024
1 parent 6779758 commit c38e19a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
9 changes: 3 additions & 6 deletions app/models/booking_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
#
# Table name: booking_validations
#
# id :bigint not null, primary key
# id :integer not null, primary key
# organisation_id :integer not null
# error_message_i18n :jsonb
# ordinal :integer
# created_at :datetime not null
# updated_at :datetime not null
# organisation_id :bigint not null
#
# Indexes
#
# index_booking_validations_on_organisation_id (organisation_id)
#
# Foreign Keys
#
# fk_rails_... (organisation_id => organisations.id)
#

class BookingValidation < ApplicationRecord
extend Mobility
include RankedModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
class SetLocaleForExistingContracts < ActiveRecord::Migration[8.0]
def up
Booking.where(concluded: false).find_each do |booking|
next if booking.contract.blank?

Booking.where(concluded: false).joins(:contracts).includes(:contracts)
.where.not(contracts: { id: nil }).find_each do |booking|
booking.contract.skip_generate_pdf = true
booking.contract.update(locale: booking.locale)
booking.contract.update_columns(locale: booking.locale)
end
end
end
9 changes: 3 additions & 6 deletions spec/factories/booking_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
#
# Table name: booking_validations
#
# id :bigint not null, primary key
# id :integer not null, primary key
# organisation_id :integer not null
# error_message_i18n :jsonb
# ordinal :integer
# created_at :datetime not null
# updated_at :datetime not null
# organisation_id :bigint not null
#
# Indexes
#
# index_booking_validations_on_organisation_id (organisation_id)
#
# Foreign Keys
#
# fk_rails_... (organisation_id => organisations.id)
#

FactoryBot.define do
factory :booking_validation do
organisation { nil }
Expand Down
9 changes: 3 additions & 6 deletions spec/models/booking_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
#
# Table name: booking_validations
#
# id :bigint not null, primary key
# id :integer not null, primary key
# organisation_id :integer not null
# error_message_i18n :jsonb
# ordinal :integer
# created_at :datetime not null
# updated_at :datetime not null
# organisation_id :bigint not null
#
# Indexes
#
# index_booking_validations_on_organisation_id (organisation_id)
#
# Foreign Keys
#
# fk_rails_... (organisation_id => organisations.id)
#

require 'rails_helper'

RSpec.describe BookingValidation, type: :model do
Expand Down

0 comments on commit c38e19a

Please sign in to comment.