Skip to content

Conversation

DZakh
Copy link
Member

@DZakh DZakh commented Sep 11, 2025

Summary by CodeRabbit

  • Refactor

    • Removed the automatic write-timestamp field from generated entities and tables.
    • Dropped the related index on write-timestamp in the sample schema.
    • History records now include the write-timestamp as a nullable, non-indexed field.
  • Tests

    • Updated test fixtures and assertions to reflect the removal of the write-timestamp column and index.
    • Ensured column count checks enforce no unexpected extra columns.
  • Chores

    • Synchronized code generation templates and internal schemas to align with the new schema output.

@DZakh DZakh requested a review from JonoPrest September 11, 2025 13:04
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

Walkthrough

Removed generation and indexing of the db_write_timestamp column across codegen templates, internal tables, and schema/test artifacts. EntityHistory no longer explicitly excludes the field, allowing default handling if present. Tests and expected SQL were updated to reflect the absence of the column and its index.

Changes

Cohort / File(s) Summary
History field handling
codegenerator/cli/npm/envio/src/db/EntityHistory.res
Dropped special-case exclusion of "db_write_timestamp" in fromTable; it now falls through to default mapping as a nullable, non-indexed field when present.
Internal/raw table schema
codegenerator/cli/npm/envio/src/db/InternalTable.res
Removed db_write_timestamp column from RawEvents table definition.
Codegen entity template
codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
Removed mkField for db_write_timestamp (TimestampWithoutTimezone, default CURRENT_TIMESTAMP) from generated entities.
GraphQL schema indices
scenarios/test_codegen/schema.graphql
Removed @index(fields: ["db_write_timestamp"]) from type Token.
Tests: DDL and column expectations
scenarios/test_codegen/test/SerDe_Test.res, scenarios/test_codegen/test/lib_tests/PgStorage_test.res, scenarios/test_codegen/test/entity-column-types-test.ts
Updated expected CREATE TABLE/DDL strings to omit db_write_timestamp; tightened column count assertion to exact match (no +1 allowance).

Sequence Diagram(s)

sequenceDiagram
  participant Schema as GraphQL Schema
  participant Codegen as Codegen Template
  participant DB as Internal Tables
  participant Tests as Test Suite

  Schema-->>Codegen: Types without db_write_timestamp index
  Codegen-->>DB: Generated entities without db_write_timestamp column
  DB-->>Tests: DDL without db_write_timestamp
  Tests-->>Tests: Assertions updated to expect exact column set
  Note over Codegen,DB: EntityHistory now defaults any present db_write_timestamp (no special exclusion)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Just clean up, no changes #609 — Modifies EntityHistory.fromTable signature and evaluation; overlaps with this PR’s changes to the same function’s field handling.

Suggested reviewers

  • JonoPrest
  • moose-code

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Remove db_write_timestamp" is a concise, single-sentence summary that accurately reflects the primary change in this PR (removal of the db_write_timestamp column and related references across codegen templates, internal tables, schema, and tests). It is specific and clear enough for a reviewer scanning history to understand the main intent without extraneous detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

A timestamp hops away, light on its feet,
No longer stamped on every beat.
Tables trimmed, indices lean,
Tests align—so crisp, so clean.
A rabbit nods, ears in delight:
Less is more; the schema’s tight. 🐇⏱️

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac325a and 9bf7149.

📒 Files selected for processing (7)
  • codegenerator/cli/npm/envio/src/db/EntityHistory.res (0 hunks)
  • codegenerator/cli/npm/envio/src/db/InternalTable.res (0 hunks)
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs (0 hunks)
  • scenarios/test_codegen/schema.graphql (0 hunks)
  • scenarios/test_codegen/test/SerDe_Test.res (1 hunks)
  • scenarios/test_codegen/test/entity-column-types-test.ts (1 hunks)
  • scenarios/test_codegen/test/lib_tests/PgStorage_test.res (6 hunks)
💤 Files with no reviewable changes (4)
  • codegenerator/cli/npm/envio/src/db/InternalTable.res
  • scenarios/test_codegen/schema.graphql
  • codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs
  • codegenerator/cli/npm/envio/src/db/EntityHistory.res
🧰 Additional context used
📓 Path-based instructions (3)
scenarios/test_codegen/**/*.ts

📄 CodeRabbit inference engine (scenarios/test_codegen/.cursor/rules/hyperindex.mdc)

scenarios/test_codegen/**/*.ts: After changing any TypeScript files, run: pnpm tsc --noEmit to ensure successful compilation
When updating existing entities in handlers, always use the spread operator to create updated objects before persisting
For any external call (e.g., fetch), wrap it in an Effect via experimental_createEffect and consume via context.effect
Use !context.isPreload to skip logic that should not run during preload
In TypeScript, set relationship fields using *_id properties (e.g., token_id) rather than object references
Always cast timestamps from events to BigInt (e.g., BigInt(event.block.timestamp))
When matching addresses in configuration objects within code, ensure keys are lowercase and compare using address.toLowerCase()
Use string | undefined for optional string fields instead of string | null
Always normalize token amounts to a standard decimal (e.g., 18) before addition across tokens; use helpers like normalizeAmountToUSD()

Files:

  • scenarios/test_codegen/test/entity-column-types-test.ts
**/*.{res,resi}

📄 CodeRabbit inference engine (.cursor/rules/rescript.mdc)

**/*.{res,resi}: Never use [| item |] to create an array. Use [ item ] instead.
Must always use = for setting value to a field. Use := only for ref values created using ref function.
ReScript has record types which require a type definition before hand. You can access record fields by dot like foo.myField.
It's also possible to define an inline object, it'll have quoted fields in this case.
Use records when working with structured data, and objects to conveniently pass payload data between functions.
Never use %raw to access object fields if you know the type.

Files:

  • scenarios/test_codegen/test/lib_tests/PgStorage_test.res
  • scenarios/test_codegen/test/SerDe_Test.res
**/*.res

📄 CodeRabbit inference engine (.cursor/rules/navigation.mdc)

Prefer reading ReScript .res modules directly; compiled .js artifacts can be ignored

Files:

  • scenarios/test_codegen/test/lib_tests/PgStorage_test.res
  • scenarios/test_codegen/test/SerDe_Test.res
🧠 Learnings (6)
📚 Learning: 2025-08-11T08:49:57.399Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:49:57.399Z
Learning: Applies to scenarios/test_codegen/**/*.ts : When updating existing entities in handlers, always use the spread operator to create updated objects before persisting

Applied to files:

  • scenarios/test_codegen/test/entity-column-types-test.ts
📚 Learning: 2025-09-04T14:42:53.500Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: .cursor/rules/subgraph-migration.mdc:0-0
Timestamp: 2025-09-04T14:42:53.500Z
Learning: Applies to src/**/*.ts : Match entity field types exactly with schema: use bigint for BigInt fields, BigDecimal for BigDecimal fields, and correct scalar types

Applied to files:

  • scenarios/test_codegen/test/entity-column-types-test.ts
📚 Learning: 2025-08-11T08:49:57.399Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:49:57.399Z
Learning: Applies to scenarios/test_codegen/**/*.ts : In TypeScript, set relationship fields using *_id properties (e.g., token_id) rather than object references

Applied to files:

  • scenarios/test_codegen/test/entity-column-types-test.ts
📚 Learning: 2025-08-11T08:49:57.399Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/test_codegen/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:49:57.399Z
Learning: Applies to scenarios/test_codegen/**/*.ts : Always cast timestamps from events to BigInt (e.g., BigInt(event.block.timestamp))

Applied to files:

  • scenarios/test_codegen/test/entity-column-types-test.ts
📚 Learning: 2025-08-11T08:47:04.346Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/fuel_test/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:47:04.346Z
Learning: Applies to scenarios/fuel_test/**/*.ts : In TypeScript code, set relationship fields using the `_id` form expected by generated types (e.g., `{ token_id: tokenId }`, not `{ token: tokenObject }`)

Applied to files:

  • scenarios/test_codegen/test/entity-column-types-test.ts
📚 Learning: 2025-08-11T08:47:04.346Z
Learnt from: CR
PR: enviodev/hyperindex#0
File: scenarios/fuel_test/.cursor/rules/hyperindex.mdc:0-0
Timestamp: 2025-08-11T08:47:04.346Z
Learning: Applies to scenarios/fuel_test/**/*.ts : When updating existing entities in handlers, always use the spread operator to clone immutable returned objects before modifying and saving

Applied to files:

  • scenarios/test_codegen/test/entity-column-types-test.ts
⏰ 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: build_and_test
🔇 Additional comments (8)
scenarios/test_codegen/test/SerDe_Test.res (1)

129-129: Expectation update matches removal of db_write_timestamp.

DDL string looks consistent with the rest of the schema; no stray column left behind.

scenarios/test_codegen/test/entity-column-types-test.ts (1)

161-161: Tightened assertion is correct; TypeScript check couldn't be executed

  • Tightened assertion is correct now that no extra column is expected — will catch regressions reintroducing db_write_timestamp.
  • Verification attempted by running pnpm tsc --noEmit in scenarios/test_codegen (nearest package.json) failed: pnpm reported Command "tsc" not found. Install TypeScript (or add it to devDependencies) and re-run pnpm tsc --noEmit to complete verification.
scenarios/test_codegen/test/lib_tests/PgStorage_test.res (6)

68-69: Updated A table DDL: db_write_timestamp correctly removed.


78-79: Updated B table DDL: db_write_timestamp correctly removed.


88-93: Default-values DDL for A aligns with removal.


150-154: Main init DDL (test_schema): raw_events/A/B definitions updated to omit db_write_timestamp.

Serial PK on raw_events retained; looks good.


235-235: Minimal-config init DDL: raw_events no longer has db_write_timestamp.


317-319: Public schema init DDL: raw_events and A updated as intended — verification inconclusive

rg reported "No files were searched", so the sweep was inconclusive. Re-run the check with these adjusted commands:

#!/bin/bash
set -euo pipefail
rg -n --hidden -S -uu '\bdb_write_timestamp\b' || echo "No occurrences found"
rg -nP -C2 '\.length\)\s*\+\s*1\b' scenarios/test_codegen || echo "No len+1 allowances found"
# If rg still reports no files, run:
# rg --debug -uu '\bdb_write_timestamp\b'
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dz/remove-db_write_timestamp

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.

@DZakh
Copy link
Member Author

DZakh commented Sep 18, 2025

Merged as a part of another PR

@DZakh DZakh closed this Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant