Skip to content

Commit

Permalink
chore: add tx_template_id to transactions table (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit authored Jun 14, 2024
1 parent add2775 commit eae5dc5
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 45 deletions.

This file was deleted.

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

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

4 changes: 3 additions & 1 deletion cala-ledger/migrations/20231208110808_cala_ledger_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ CREATE TABLE cala_transactions (
data_source_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
id UUID NOT NULL,
journal_id UUID NOT NULL,
tx_template_id UUID NOT NULL,
external_id VARCHAR DEFAULT NULL,
correlation_id VARCHAR NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(data_source_id, id),
FOREIGN KEY (data_source_id, journal_id) REFERENCES cala_journals(data_source_id, id)
FOREIGN KEY (data_source_id, journal_id) REFERENCES cala_journals(data_source_id, id),
FOREIGN KEY (data_source_id, tx_template_id) REFERENCES cala_tx_templates(data_source_id, id)
);
CREATE INDEX idx_cala_transactions_data_source_id_correlation_id ON cala_transactions (data_source_id, correlation_id);
CREATE UNIQUE INDEX idx_cala_transactions_data_source_id_external_id ON cala_transactions (data_source_id, external_id) WHERE external_id IS NOT NULL;
Expand Down
14 changes: 8 additions & 6 deletions cala-ledger/src/transaction/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::HashMap;
use crate::primitives::DataSourceId;
use crate::{
entity::*,
primitives::{JournalId, TransactionId},
primitives::{JournalId, TransactionId, TxTemplateId},
};

use super::{entity::*, error::*};
Expand All @@ -29,10 +29,11 @@ impl TransactionRepo {
new_transaction: NewTransaction,
) -> Result<Transaction, TransactionError> {
sqlx::query!(
r#"INSERT INTO cala_transactions (id, journal_id, correlation_id, external_id)
VALUES ($1, $2, $3, $4)"#,
r#"INSERT INTO cala_transactions (id, journal_id, tx_template_id, correlation_id, external_id)
VALUES ($1, $2, $3, $4, $5)"#,
new_transaction.id as TransactionId,
new_transaction.journal_id as JournalId,
new_transaction.tx_template_id as TxTemplateId,
new_transaction.correlation_id,
new_transaction.external_id
)
Expand Down Expand Up @@ -132,13 +133,14 @@ impl TransactionRepo {
transaction: &mut Transaction,
) -> Result<(), TransactionError> {
sqlx::query!(
r#"INSERT INTO cala_transactions (data_source_id, id, journal_id, external_id, correlation_id, created_at)
VALUES ($1, $2, $3, $4, $5, $6)"#,
r#"INSERT INTO cala_transactions (data_source_id, id, journal_id, tx_template_id, external_id, correlation_id, created_at)
VALUES ($1, $2, $3, $4, $5, $6, $7)"#,
origin as DataSourceId,
transaction.values().id as TransactionId,
transaction.values().journal_id as JournalId,
transaction.values().correlation_id,
transaction.values().tx_template_id as TxTemplateId,
transaction.values().external_id,
transaction.values().correlation_id,
recorded_at
)
.execute(&mut **db)
Expand Down

This file was deleted.

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

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

0 comments on commit eae5dc5

Please sign in to comment.