Skip to content

Commit

Permalink
Add precise_total_amount_cents to Event
Browse files Browse the repository at this point in the history
  • Loading branch information
nudded committed Sep 17, 2024
1 parent 169ce17 commit 423aec4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
30 changes: 16 additions & 14 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,28 @@ def subscription
#
# Table name: events
#
# id :uuid not null, primary key
# code :string not null
# deleted_at :datetime
# metadata :jsonb not null
# properties :jsonb not null
# timestamp :datetime
# created_at :datetime not null
# updated_at :datetime not null
# customer_id :uuid
# external_customer_id :string
# external_subscription_id :string
# organization_id :uuid not null
# subscription_id :uuid
# transaction_id :string not null
# id :uuid not null, primary key
# code :string not null
# deleted_at :datetime
# metadata :jsonb not null
# precise_total_amount_cents :decimal(40, 15)
# properties :jsonb not null
# timestamp :datetime
# created_at :datetime not null
# updated_at :datetime not null
# customer_id :uuid
# external_customer_id :string
# external_subscription_id :string
# organization_id :uuid not null
# subscription_id :uuid
# transaction_id :string not null
#
# Indexes
#
# index_events_on_customer_id (customer_id)
# index_events_on_deleted_at (deleted_at)
# index_events_on_external_subscription_id_and_code_and_timestamp (organization_id,external_subscription_id,code,timestamp) WHERE (deleted_at IS NULL)
# index_events_on_external_subscription_id_precise_amount (external_subscription_id,code,timestamp) WHERE ((deleted_at IS NULL) AND (precise_total_amount_cents IS NOT NULL))
# index_events_on_external_subscription_id_with_included (external_subscription_id,code,timestamp) WHERE (deleted_at IS NULL)
# index_events_on_organization_id (organization_id)
# index_events_on_organization_id_and_code (organization_id,code)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddPreciseTotalAmountCentsToEvent < ActiveRecord::Migration[7.1]
def change
add_column :events, :precise_total_amount_cents, :decimal, precision: 40, scale: 15
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class AddIndexOnPreciseTotalAmountCents < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def change
add_index :events, %i[external_subscription_id code timestamp],
name: 'index_events_on_external_subscription_id_precise_amount',
where: 'deleted_at IS NULL AND precise_total_amount_cents IS NOT NULL',
algorithm: :concurrently,
if_not_exists: true,
include: %i[organization_id precise_total_amount_cents]
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

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

0 comments on commit 423aec4

Please sign in to comment.