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

Feat: issue credit note on credit invoice - db change #2676

Merged
merged 5 commits into from
Oct 14, 2024
Merged
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
10 changes: 8 additions & 2 deletions app/models/wallet_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class WalletTransaction < ApplicationRecord
include PaperTrailTraceable

belongs_to :wallet

# these two relationships are populated only for outbound transactions
belongs_to :invoice, optional: true
belongs_to :credit_note, optional: true

STATUSES = [
:pending,
Expand Down Expand Up @@ -53,16 +56,19 @@ class WalletTransaction < ApplicationRecord
# transaction_type :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# credit_note_id :uuid
# invoice_id :uuid
# wallet_id :uuid not null
#
# Indexes
#
# index_wallet_transactions_on_invoice_id (invoice_id)
# index_wallet_transactions_on_wallet_id (wallet_id)
# index_wallet_transactions_on_credit_note_id (credit_note_id)
# index_wallet_transactions_on_invoice_id (invoice_id)
# index_wallet_transactions_on_wallet_id (wallet_id)
#
# Foreign Keys
#
# fk_rails_... (credit_note_id => credit_notes.id)
# fk_rails_... (invoice_id => invoices.id)
# fk_rails_... (wallet_id => wallets.id)
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

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

def change
add_reference :wallet_transactions, :credit_note, type: :uuid, null: true, index: {algorithm: :concurrently}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddForeignKeyConstraintToCreditNoteIdAtWalletTransaction < ActiveRecord::Migration[7.1]
def change
add_foreign_key :wallet_transactions, :credit_notes, validate: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ChangeValidateOnForeignKeyFromWalletTransactionToCreditNote < ActiveRecord::Migration[7.1]
def change
validate_foreign_key :wallet_transactions, :credit_notes
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

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