Skip to content

Conversation

@madhugb
Copy link
Contributor

@madhugb madhugb commented Jul 16, 2025

Description of change

After we fixed the @UpdateDateColumn issue with upsert with #10458, we have not updated the documentation

This PR updates the relevant docs for upsert where required.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change

Summary by CodeRabbit

  • Documentation
    • Clarified that special automatic columns (update timestamp and version) are also refreshed when an upsert operation results in an update, not just on explicit save calls.
    • Added notes across EntityManager and Repository guides and updated upsert examples to show these fields being updated during conflict-handling updates, with illustrative SQL-style examples and explanatory text.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The docs were updated to state that @UpdateDateColumn and @VersionColumn are automatically updated not only on save but also during upsert operations when those upserts result in an update; related notes and SQL example SET clauses were added to clarify this behavior.

Changes

Cohort / File(s) Change Summary
Decorator & entity docs
docs/docs/help/3-decorator-reference.md, docs/docs/entity/1-entities.md
Added notes clarifying @UpdateDateColumn and @VersionColumn are also updated automatically during upsert updates (conflict-triggered updates).
EntityManager & Repository API docs
docs/docs/working-with-entity-manager/5-entity-manager-api.md, docs/docs/working-with-entity-manager/6-repository-api.md
Added note to EntityManager.upsert and Repository.upsert; updated example SQL ON CONFLICT DO UPDATE clauses to include updatedDate = CURRENT_TIMESTAMP and version = version + 1.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

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 "docs: fix docs for UpdateDateColumn" is concise and directly relates to the primary change—updating documentation for the UpdateDateColumn behavior; it does not contain noise or unrelated content. The PR also adjusts related notes and examples for @VersionColumn and upsert examples, but the title still accurately reflects the main documentation fix.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

In the burrow of docs I nibble a line,
Upserts now tick when the conflicts align.
Timestamps refreshed, version hops too,
Quiet and tidy — the changelog says true.
🐇📜

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.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • Failed to retrieve linked issues from the platform client.

📜 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 c14acfb and 51b1565.

📒 Files selected for processing (3)
  • docs/docs/help/3-decorator-reference.md (2 hunks)
  • docs/docs/working-with-entity-manager/5-entity-manager-api.md (1 hunks)
  • docs/docs/working-with-entity-manager/6-repository-api.md (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/docs/help/3-decorator-reference.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/docs/working-with-entity-manager/5-entity-manager-api.md
  • docs/docs/working-with-entity-manager/6-repository-api.md
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Actionable comments posted: 0

🧹 Nitpick comments (7)
docs/docs/working-with-entity-manager/5-entity-manager-api.md (1)

199-200: Tighten the note & spell out the implicit behaviour

A quick wording/clarity win: explicitly name what “current values” means, so the reader doesn’t have to infer which values are written.

-**Note:** When an upsert operation results in an update (due to a conflict), special columns like `@UpdateDateColumn` and `@VersionColumn` are automatically updated to their current values.
+**Note:** When an upsert operation performs an update (due to a conflict), TypeORM automatically  
+· sets `@UpdateDateColumn` to the current timestamp, and  
+· increments `@VersionColumn`. 
docs/docs/help/3-decorator-reference.md (2)

283-284: Mirror wording used elsewhere for consistency

Minor stylistic tweak so the phrasing matches the other docs you touched (“performs an update” instead of “when an update occurs”) and keeps the “due to a conflict” qualifier that explains why an update happens.

-**Note:** This column is also automatically updated during `upsert` operations when an update occurs due to a conflict.
+**Note:** This column is also automatically updated during `upsert` operations that perform an update due to a conflict.

315-316: Apply the same phrasing to the VersionColumn section

Keeping the two notes identical helps downstream translators & avoids docs drift.

-**Note:** This column is also automatically updated during `upsert` operations when an update occurs due to a conflict.
+**Note:** This column is also automatically updated during `upsert` operations that perform an update due to a conflict.
docs/docs/entity/1-entities.md (2)

174-176: Small grammar & flow polish

Replace the comma splice with an em-dash and reuse the “performs an update” wording.

-each time you call `save` of entity manager or repository, or during `upsert` operations when an update occurs.
+— each time you call `save` on the entity manager or repository, **or** during `upsert` operations that perform an update.

179-181: Keep wording identical to UpdateDateColumn paragraph

Same reasoning as above; suggest mirroring exact wording.

-each time you call `save` of entity manager or repository, or during `upsert` operations when an update occurs.
+— each time you call `save` on the entity manager or repository, **or** during `upsert` operations that perform an update.
docs/docs/working-with-entity-manager/6-repository-api.md (2)

155-156: Spell out what “current values” means

Same micro-clarification as in the EntityManager docs.

-**Note:** When an upsert operation results in an update (due to a conflict), special columns like `@UpdateDateColumn` and `@VersionColumn` are automatically updated to their current values.
+**Note:** When an upsert operation performs an update (due to a conflict), TypeORM automatically sets `@UpdateDateColumn` to the current timestamp and increments `@VersionColumn`.

170-173: Nit: keep example SQL fully valid

In Postgres CURRENT_TIMESTAMP usually lives outside quotes; since this is a doc comment it’s fine, but adding a comma after the last SET line makes the example invalid SQL. Consider dropping the trailing comma so copy-paste works.

- *  SET firstName = EXCLUDED.firstName,
- *      updatedDate = CURRENT_TIMESTAMP,
- *      version = version + 1
+ *  SET firstName = EXCLUDED.firstName,
+ *      updatedDate = CURRENT_TIMESTAMP,
+ *      version = version + 1

(Only the final line should lack the trailing comma.)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f351757 and c14acfb.

📒 Files selected for processing (4)
  • docs/docs/entity/1-entities.md (1 hunks)
  • docs/docs/help/3-decorator-reference.md (2 hunks)
  • docs/docs/working-with-entity-manager/5-entity-manager-api.md (1 hunks)
  • docs/docs/working-with-entity-manager/6-repository-api.md (2 hunks)

Copy link
Collaborator

@sgarner sgarner left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @madhugb

@sgarner sgarner requested a review from gioboa September 11, 2025 21:27
Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

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

Thanks @madhugb for your amazing help 👏

@gioboa gioboa merged commit f3c8d2f into typeorm:master Sep 12, 2025
1 check passed
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 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.

3 participants