Skip to content

Commit

Permalink
fix migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbourdeau committed Jul 4, 2024
1 parent 9cf1706 commit dd680ea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
class UpdatePropertiesOnPercentageCharges < ActiveRecord::Migration[7.0]
def change
LagoApi::Application.load_tasks
Rake::Task['charges:update_properties_for_free_units'].invoke
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

class AddRateToPercentageAmountDetails < ActiveRecord::Migration[7.0]
class Fee < ApplicationRecord
belongs_to :charge, -> { with_discarded }, optional: true
belongs_to :charge, optional: true
end

class Charge < ApplicationRecord
enum charge_model: %i[percentage graduated_percentage].freeze
end

def up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

class Charge
attribute :regroup_paid_fees, :integer, default: nil
end

class AddCustomAggregationToOrganizations < ActiveRecord::Migration[7.0]
def change
add_column :organizations, :custom_aggregation, :boolean, default: false
Expand Down
14 changes: 0 additions & 14 deletions lib/tasks/charges.rake
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
# frozen_string_literal: true

namespace :charges do
desc 'Update Properties for Fixed Fee and Free Units'
task update_properties_for_free_units: :environment do
# Notes: We consider that we don’t have any clients with a percentage charge
# created containing a fixed_amount. All existing charges have fixed_amount
# and fixed_amount_target with a null value.

Charge.unscoped.percentage.where("properties -> 'fixed_amount_target' IS NOT NULL").find_each do |charge|
charge.properties.delete('fixed_amount_target')
charge.properties['free_units_per_events'] = nil
charge.properties['free_units_per_total_aggregation'] = nil
charge.save!
end
end

desc 'Set graduated properties to hash and rename volume ranges'
task update_graduated_properties_to_hash: :environment do
# Rename existing volume ranges from `ranges: []` to `volume_ranges: []`
Expand Down

0 comments on commit dd680ea

Please sign in to comment.