Skip to content

add createdAt field to index orders table#3327

Merged
anmolagrawal345 merged 4 commits intomainfrom
anmol-createdAt
Mar 4, 2026
Merged

add createdAt field to index orders table#3327
anmolagrawal345 merged 4 commits intomainfrom
anmol-createdAt

Conversation

@anmolagrawal345
Copy link
Contributor

@anmolagrawal345 anmolagrawal345 commented Mar 2, 2026

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Orders now include a createdAt timestamp field in API responses, displaying when each order was created.
  • Tests

    • Updated test assertions to validate the new createdAt field.

@anmolagrawal345 anmolagrawal345 requested a review from a team as a code owner March 2, 2026 19:28
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Warning

Rate limit exceeded

@anmolagrawal345 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd436058-98f1-4c94-b0aa-743ff9cbbea0

📥 Commits

Reviewing files that changed from the base of the PR and between e0e326b and 4330c3e.

📒 Files selected for processing (1)
  • indexer/services/comlink/public/api-documentation.md
📝 Walkthrough

Walkthrough

This pull request adds a createdAt timestamp field to orders throughout the indexer system. Changes span database migration, data models, type definitions, API schemas, SQL handlers, and test assertions. The field is populated with block_time when orders are created.

Changes

Cohort / File(s) Summary
Database Schema & Model
indexer/packages/postgres/src/db/migrations/migration_files/20260302120000_add_created_at_to_orders.ts, indexer/packages/postgres/src/models/order-model.ts
New migration adds createdAt nullable timestamp column to orders table. OrderModel updated with createdAt field as IsoString with corresponding JSON schema and SQL-to-JSON conversions.
Type Definitions
indexer/packages/postgres/src/types/db-model-types.ts, indexer/packages/postgres/src/types/order-types.ts
OrderFromDatabase interface and OrderCreateObject type extended with optional createdAt field. OrderColumns enum updated with createdAt member. Comments clarified that both createdAtHeight and createdAt are optional for short-term orders.
API Layer
indexer/services/comlink/public/swagger.json, indexer/services/comlink/src/request-helpers/request-transformer.ts
Swagger schema updated with createdAt field in OrderResponseObject and PerpetualPositionResponseObject. postgresOrderToResponseObject transformer adds createdAt to outgoing responses.
SQL Handlers
indexer/services/ender/src/scripts/handlers/dydx_stateful_order_handler.sql, indexer/services/ender/src/scripts/helpers/dydx_liquidation_fill_handler_per_order.sql, indexer/services/ender/src/scripts/helpers/dydx_order_fill_handler_per_order.sql
All three SQL handlers updated to populate createdAt from block_time and include the column in INSERT statements for order creation.
Tests
indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-placement-handler.test.ts, indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts
Test assertions updated to include createdAt field with defaultDateTime.toISO() values in OrderFromDatabase test objects.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

indexer-postgres-improvement

Suggested reviewers

  • tqin7
  • vincentwschau

Poem

🐰 Hop, hop, hooray! A timestamp now graces the day,
When orders are born, their creation's on display,
From migration to model, through handlers and schemas so bright,
Each order remembers when it came into sight!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only template placeholders with no actual information about changes, testing, or implementation details. Fill in the Changelist section with specific changes made, describe the Test Plan with how testing was performed, and consider applying relevant labels based on the changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'add createdAt field to index orders table' is specific and clearly describes the main change in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch anmol-createdAt

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
indexer/services/ender/src/scripts/handlers/dydx_stateful_order_handler.sql (1)

100-142: ⚠️ Potential issue | 🟡 Minor

Keep createdAt in sync in the ON CONFLICT update branch.

ON CONFLICT currently updates createdAtHeight but not createdAt, which can leave inconsistent creation metadata when a row conflicts.

🛠️ Suggested patch
         ) ON CONFLICT ("id") DO
             UPDATE SET
                        "subaccountId" = order_record."subaccountId",
                        "clientId" = order_record."clientId",
                        "clobPairId" = order_record."clobPairId",
                        "side" = order_record."side",
                        "size" = order_record."size",
                        "totalFilled" = order_record."totalFilled",
                        "price" = order_record."price",
                        "timeInForce" = order_record."timeInForce",
                        "reduceOnly" = order_record."reduceOnly",
                        "orderFlags" = order_record."orderFlags",
                        "goodTilBlockTime" = order_record."goodTilBlockTime",
                        "clientMetadata" = order_record."clientMetadata",
                        "createdAtHeight" = order_record."createdAtHeight",
+                       "createdAt" = order_record."createdAt",
                        "updatedAt" = order_record."updatedAt",
                        "updatedAtHeight" = order_record."updatedAtHeight",
                        "type" = order_record."type",
                        "status" = order_record."status",
                        "triggerPrice" = order_record."triggerPrice",
                        "builderAddress" = order_record."builderAddress",
                        "feePpm" = order_record."feePpm",
                        "duration" = order_record."duration",
                        "interval" = order_record."interval",
                        "priceTolerance" = order_record."priceTolerance",
                        "orderRouterAddress" = order_record."orderRouterAddress"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@indexer/services/ender/src/scripts/handlers/dydx_stateful_order_handler.sql`
around lines 100 - 142, The ON CONFLICT UPDATE is missing assignment for
"createdAt", causing creation timestamp drift; update the conflict branch in
this statement so the UPDATE SET includes "createdAt" = order_record."createdAt"
(alongside "createdAtHeight" = order_record."createdAtHeight") to keep createdAt
in sync for the orders record (refer to the INSERT INTO orders ... VALUES (...)
... ON CONFLICT ... UPDATE SET block and the order_record fields).
🧹 Nitpick comments (1)
indexer/packages/postgres/src/db/migrations/migration_files/20260302120000_add_created_at_to_orders.ts (1)

3-7: Consider a one-time backfill plan for historical rows.

This migration adds createdAt as nullable but leaves existing orders rows null. If consumers are expected to rely on this field broadly, a follow-up backfill (or explicit contract note) would reduce response heterogeneity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@indexer/packages/postgres/src/db/migrations/migration_files/20260302120000_add_created_at_to_orders.ts`
around lines 3 - 7, The migration adds a nullable createdAt column on the orders
table which leaves historical rows null; create a follow-up one-time backfill
migration (or extend this migration) that sets orders.createdAt for existing
rows using the best available source (for example an existing timestamp column
like created_at or inserted_at, or fallback to a deterministic value such as the
row's id-derived time or NOW() if nothing else exists), and ensure you update or
document the contract for consumers; reference the current migration function up
and the orders table / createdAt column when implementing the backfill so
reviewers can locate and verify the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@indexer/services/ender/src/scripts/handlers/dydx_stateful_order_handler.sql`:
- Around line 100-142: The ON CONFLICT UPDATE is missing assignment for
"createdAt", causing creation timestamp drift; update the conflict branch in
this statement so the UPDATE SET includes "createdAt" = order_record."createdAt"
(alongside "createdAtHeight" = order_record."createdAtHeight") to keep createdAt
in sync for the orders record (refer to the INSERT INTO orders ... VALUES (...)
... ON CONFLICT ... UPDATE SET block and the order_record fields).

---

Nitpick comments:
In
`@indexer/packages/postgres/src/db/migrations/migration_files/20260302120000_add_created_at_to_orders.ts`:
- Around line 3-7: The migration adds a nullable createdAt column on the orders
table which leaves historical rows null; create a follow-up one-time backfill
migration (or extend this migration) that sets orders.createdAt for existing
rows using the best available source (for example an existing timestamp column
like created_at or inserted_at, or fallback to a deterministic value such as the
row's id-derived time or NOW() if nothing else exists), and ensure you update or
document the contract for consumers; reference the current migration function up
and the orders table / createdAt column when implementing the backfill so
reviewers can locate and verify the change.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07b2c96 and 9d74a06.

📒 Files selected for processing (9)
  • indexer/packages/postgres/src/db/migrations/migration_files/20260302120000_add_created_at_to_orders.ts
  • indexer/packages/postgres/src/models/order-model.ts
  • indexer/packages/postgres/src/types/db-model-types.ts
  • indexer/packages/postgres/src/types/order-types.ts
  • indexer/services/comlink/public/swagger.json
  • indexer/services/comlink/src/request-helpers/request-transformer.ts
  • indexer/services/ender/src/scripts/handlers/dydx_stateful_order_handler.sql
  • indexer/services/ender/src/scripts/helpers/dydx_liquidation_fill_handler_per_order.sql
  • indexer/services/ender/src/scripts/helpers/dydx_order_fill_handler_per_order.sql

@anmolagrawal345
Copy link
Contributor Author

@Mergifyio backport release/indexer/v9.x

@mergify
Copy link
Contributor

mergify bot commented Mar 10, 2026

backport release/indexer/v9.x

✅ Backports have been created

Details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants