Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(fees): Add unique index on event transaction id #3079

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions app/models/fee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,20 @@ def has_charge_filters?
#
# Indexes
#
# index_fees_on_add_on_id (add_on_id)
# index_fees_on_applied_add_on_id (applied_add_on_id)
# index_fees_on_charge_filter_id (charge_filter_id)
# index_fees_on_charge_id (charge_id)
# index_fees_on_charge_id_and_invoice_id (charge_id,invoice_id) WHERE (deleted_at IS NULL)
# index_fees_on_deleted_at (deleted_at)
# index_fees_on_group_id (group_id)
# index_fees_on_invoice_id (invoice_id)
# index_fees_on_invoiceable (invoiceable_type,invoiceable_id)
# index_fees_on_organization_id (organization_id)
# index_fees_on_pay_in_advance_event_transaction_id (pay_in_advance_event_transaction_id) WHERE (deleted_at IS NULL)
# index_fees_on_subscription_id (subscription_id)
# index_fees_on_true_up_parent_fee_id (true_up_parent_fee_id)
# idx_on_pay_in_advance_event_transaction_id_charge_i_16302ca167 (pay_in_advance_event_transaction_id,charge_id,charge_filter_id) UNIQUE WHERE (created_at > '2025-01-20 15:26:22'::timestamp without time zone)
# index_fees_on_add_on_id (add_on_id)
# index_fees_on_applied_add_on_id (applied_add_on_id)
# index_fees_on_charge_filter_id (charge_filter_id)
# index_fees_on_charge_id (charge_id)
# index_fees_on_charge_id_and_invoice_id (charge_id,invoice_id) WHERE (deleted_at IS NULL)
# index_fees_on_deleted_at (deleted_at)
# index_fees_on_group_id (group_id)
# index_fees_on_invoice_id (invoice_id)
# index_fees_on_invoiceable (invoiceable_type,invoiceable_id)
# index_fees_on_organization_id (organization_id)
# index_fees_on_pay_in_advance_event_transaction_id (pay_in_advance_event_transaction_id) WHERE (deleted_at IS NULL)
# index_fees_on_subscription_id (subscription_id)
# index_fees_on_true_up_parent_fee_id (true_up_parent_fee_id)
#
# Foreign Keys
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def change
provider_class = provider_type.constantize

payments = Payment.joins(:payment_provider)
.where(payment_providers: {type: provider_type}, status: provider_class::PENDING_STATUSES)
.where(payment_providers: {type: provider_type}, status: provider_class::PROCESSING_STATUSES)
payments.update_all(payable_payment_status: :pending) # rubocop:disable Rails/SkipsModelValidations

payments = Payment.joins(:payment_provider)
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20250120151959_add_unique_event_index_on_fees.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddUniqueEventIndexOnFees < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
add_index :fees, %i[pay_in_advance_event_transaction_id charge_id charge_filter_id], unique: true,
where: "created_at > '#{Time.current}'", algorithm: :concurrently
nudded marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to add pay_in_advance = 't' and pay_in_advance_event_transaction_id is not null as well I guess

end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading