-
Notifications
You must be signed in to change notification settings - Fork 100
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
feat: Add payment type and reference #3003
base: main
Are you sure you want to change the base?
Changes from all commits
eca763d
46df3ff
b989955
e68763c
d4749bc
3ec80e6
794fba0
9b2dcaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddPaymentTypeAndReferenceToPayments < ActiveRecord::Migration[7.1] | ||
disable_ddl_transaction! | ||
|
||
def up | ||
create_enum :payment_type, %w[provider manual] | ||
|
||
safety_assured do | ||
change_table :payments, bulk: true do |t| | ||
t.column :payment_type, :enum, enum_type: 'payment_type', null: true | ||
t.column :reference, :string, default: nil | ||
end | ||
end | ||
|
||
# Backfill existing records | ||
Payment.in_batches(of: 10_000).update_all(payment_type: 'provider') # rubocop:disable Rails/SkipsModelValidations | ||
|
||
safety_assured do | ||
execute <<~SQL | ||
ALTER TABLE payments ALTER COLUMN payment_type SET DEFAULT 'provider'; | ||
SQL | ||
execute <<~SQL | ||
ALTER TABLE payments ALTER COLUMN payment_type SET NOT NULL; | ||
SQL | ||
end | ||
end | ||
|
||
def down | ||
change_table :payments, bulk: true do |t| | ||
t.remove :payment_type | ||
t.remove :reference | ||
end | ||
|
||
drop_enum :payment_type | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddTotalPaidAmountCentsToInvoices < ActiveRecord::Migration[7.1] | ||
disable_ddl_transaction! | ||
|
||
def up | ||
add_column :invoices, :total_paid_amount_cents, :bigint, null: true, default: 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will in the future we update the existing paid invoices with real values? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I will do a migration to fill the values i was thinking on another pr but can be on this one |
||
# Backfill | ||
Invoice.in_batches(of: 10_000).each do |batch| | ||
batch.update_all(total_paid_amount_cents: 0) # rubocop:disable Rails/SkipsModelValidations | ||
end | ||
|
||
safety_assured do | ||
execute <<~SQL | ||
ALTER TABLE invoices ALTER COLUMN total_paid_amount_cents SET DEFAULT 0; | ||
SQL | ||
execute <<~SQL | ||
ALTER TABLE invoices ALTER COLUMN total_paid_amount_cents SET NOT NULL; | ||
SQL | ||
end | ||
end | ||
|
||
def down | ||
# Remove the column | ||
remove_column :invoices, :total_paid_amount_cents | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will we need index on this column?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good catch I will add it