chore: make get last transaction backward compatible#1256
Conversation
Time Submission Status
|
WalkthroughThis PR refactors a PostgreSQL migration function to change the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20-30 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (1)📓 Common learnings⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9edf3ed to
fa5e59a
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/migrations/010-get-latest-write-activity.sql (1)
192-202: Optional: Move variable declaration outside the loop for clarity.Line 193 declares
$fee_distributionsinside the loop, which re-initializes it on each iteration. While functionally correct, moving the declaration before the loop (line 192) would improve readability and avoid unnecessary per-iteration allocations.IF $limit_val > 100 { ERROR('Limit size cannot exceed 100'); } + $fee_distributions TEXT := ''; FOR $row IN get_last_transactions_v1($normalized_provider, $limit_val) { - $fee_distributions TEXT := ''; RETURN NEXT NULL::TEXT, $row.created_at, $row.method, NULL::TEXT, NULL::NUMERIC(78, 0), NULL::TEXT, NULL::TEXT, $fee_distributions; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (17)
internal/migrations/000-extensions.sql(0 hunks)internal/migrations/000-initial-data.sql(0 hunks)internal/migrations/010-get-latest-write-activity.sql(1 hunks)internal/migrations/017-normalize-tables.sql(0 hunks)internal/migrations/0_test_only/bootstrap_erc20.sql(0 hunks)internal/migrations/backfill-digest/.gitignore(0 hunks)internal/migrations/backfill-digest/README.md(0 hunks)internal/migrations/backfill-digest/candidates.sql(0 hunks)internal/migrations/backfill-digest/candidates_no_table.sql(0 hunks)internal/migrations/backfill-digest/insert_batches.sh(0 hunks)internal/migrations/backfill-digest/migrate_actions.sh(0 hunks)internal/migrations/backfill-digest/phase_analysis.md(0 hunks)internal/migrations/backfill-digest/process_pending_day.sh(0 hunks)internal/migrations/backfill-digest/split_into_chunks.sh(0 hunks)internal/migrations/erc20-bridge/000-extension.sql(0 hunks)internal/migrations/erc20-bridge/001-actions.sql(0 hunks)internal/migrations/erc20-bridge/002-public-transfer-actions.sql(0 hunks)
💤 Files with no reviewable changes (16)
- internal/migrations/0_test_only/bootstrap_erc20.sql
- internal/migrations/erc20-bridge/002-public-transfer-actions.sql
- internal/migrations/erc20-bridge/000-extension.sql
- internal/migrations/backfill-digest/phase_analysis.md
- internal/migrations/backfill-digest/README.md
- internal/migrations/backfill-digest/.gitignore
- internal/migrations/017-normalize-tables.sql
- internal/migrations/backfill-digest/process_pending_day.sh
- internal/migrations/backfill-digest/insert_batches.sh
- internal/migrations/backfill-digest/migrate_actions.sh
- internal/migrations/backfill-digest/candidates_no_table.sql
- internal/migrations/backfill-digest/split_into_chunks.sh
- internal/migrations/000-extensions.sql
- internal/migrations/erc20-bridge/001-actions.sql
- internal/migrations/000-initial-data.sql
- internal/migrations/backfill-digest/candidates.sql
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: outerlook
Repo: trufnetwork/node PR: 1111
File: internal/migrations/017-normalize-tables.sql:68-77
Timestamp: 2025-08-19T14:32:35.051Z
Learning: In the trufnetwork/node project, schema migrations may be applied to match production state without including backfill steps in the migration files, particularly when bootstrapping fresh environments or when the backfill was already performed on production.
Learnt from: outerlook
Repo: trufnetwork/node PR: 1113
File: internal/migrations/020-digest-init.sql:3-11
Timestamp: 2025-08-20T12:22:14.250Z
Learning: In the trufnetwork/node repository, for the digest_config table in internal/migrations/020-digest-init.sql, the maintainer prefers to leave the table without initial seed rows, allowing the extension to handle the empty state case at runtime rather than seeding default configuration values in the migration.
Learnt from: williamrusdyputra
Repo: trufnetwork/node PR: 1228
File: internal/migrations/erc20-bridge/000-extension.sql:16-19
Timestamp: 2025-10-23T07:00:26.796Z
Learning: In internal/migrations/erc20-bridge/000-extension.sql, the active sepolia_bridge configuration is intentionally for test environments only and does not include the distribution_period parameter. The commented sepolia_bridge and ethereum_bridge blocks with distribution_period are production configurations.
Learnt from: MicBun
Repo: trufnetwork/node PR: 1123
File: internal/migrations/020-digest-actions.sql:379-399
Timestamp: 2025-08-25T15:28:08.459Z
Learning: In the batch_digest action in internal/migrations/020-digest-actions.sql, the cleanup step intentionally removes all valid candidates from pending_prune_days using $valid_stream_refs, including days that were skipped due to insufficient records. This prevents repeatedly considering days that don't need OHLC processing in future auto_digest runs, as confirmed by MicBun.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: acceptance-test
🔇 Additional comments (1)
internal/migrations/010-get-latest-write-activity.sql (1)
192-202: LGTM – set-returning refactor correctly restores backward compatibility.The change from
RETURN SELECTtoFOR...IN+RETURN NEXTproperly resolves the RPC error by iterating overget_last_transactions_v1results as a set within the function body rather than in the return statement itself. Column order and type casting (lines 194–201) correctly match the function signature, with NULL/empty defaults for the v2 fields (tx_id, caller, fee_amount, fee_recipient, metadata, fee_distributions) as expected.Please verify that all callers of
get_last_transactionsexpect NULL values for tx_id, caller, fee_amount, fee_recipient, and metadata fields. If callers previously relied on actual data in these columns (populated from v2), they will now receive NULL and this could break downstream logic.
using return select statement directly will cause error
This change the format into return next, so it works.
already migrated and currently working
resolves: https://github.com/trufnetwork/truf-network/issues/1338
Summary by CodeRabbit