Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set updated_at with created_at when creating Document #977

Merged
merged 3 commits into from
Sep 2, 2024

Conversation

window9u
Copy link
Contributor

@window9u window9u commented Aug 25, 2024

What this PR does / why we need it:

Which issue(s) this PR fixes:

This PR ensures that when a new Document is created and attached, the updated_at field is initialized with the created_at timestamp.

Before the commit b494fa2d, the updated_at field was correctly set during the attachment process through a pushpull operation that included presence. However, after this commit, the updated_at field is no longer updated when the document is attached, leading to inconsistencies.

Fixes #968

Special notes for your reviewer:

The underlying issue stems from the FindDocInfoByKeyAndOwner function, which returned a DocInfo object without setting the "owner", "server_seq", "created_at", and "updated_at" fields, leading to zero values being assigned. While this functionality is acceptable within the specific context where only project_id and id are required, it creates issues when the AttachDocument function relies on these values. It currently works around this issue since server_seq has a zero value of 0.

However, I believe we should return DocInfo with the updated "owner", "server_seq", "created_at", "updated_at" fields to maintain consistency and improve clarity.

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Introduced an UpdatedAt field for improved tracking of document update times.
    • Enhanced document update functionality to return the latest version post-update.
  • Bug Fixes

    • Improved test assertions to ensure document ownership and timestamp accuracy.
  • Documentation

    • Updated comments for improved readability in test cases.

Copy link

coderabbitai bot commented Aug 25, 2024

Walkthrough

The recent changes involve adding an UpdatedAt field to document management functionality within the database, specifically in the FindDocInfoByKeyAndOwner method. This field captures the timestamp of the last update and ensures that it is initialized when new documents are created. Additionally, test cases have been enhanced to verify the correct handling of timestamps and ownership metadata.

Changes

Files Change Summary
server/backend/database/memory/database.go, server/backend/database/mongo/client.go Added UpdatedAt field to document structs and modified database operations to include this field along with the current timestamp. Adjusted return behavior to ensure updated documents are retrieved.
server/backend/database/testcases/testcases.go Enhanced test assertions to validate UpdatedAt and ownership metadata during document creation. Updated comments for consistency.

Assessment against linked issues

Objective Addressed Explanation
Set updatedAt value for newly created documents (#968)

🐇 In fields of code, I hop with glee,
UpdatedAt joins CreatedAt like a bee!
Fetching timestamps, oh what a sight,
Ensuring metadata shines so bright!
With tests to guard, our work is done,
Hooray for features, let’s have some fun! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3f4f5d3 and f6c1e2e.

Files selected for processing (3)
  • server/backend/database/memory/database.go (1 hunks)
  • server/backend/database/mongo/client.go (1 hunks)
  • server/backend/database/testcases/testcases.go (3 hunks)
Additional comments not posted (5)
server/backend/database/memory/database.go (1)

749-749: Ensure correct initialization of UpdatedAt field.

The addition of the UpdatedAt field is correctly implemented to match the CreatedAt timestamp when a new document is created. This aligns with the PR's objective to maintain consistency between these timestamps at creation.

server/backend/database/mongo/client.go (1)

742-744: Proper handling of UpdatedAt during document creation.

The implementation correctly sets the UpdatedAt field when a new document is created, ensuring that it reflects the current time. This change is crucial for maintaining the accuracy of document metadata.

server/backend/database/testcases/testcases.go (3)

951-953: Ensure proper initialization of timestamps and ownership.

The changes correctly assert that the owner matches the client's ID, updated_at is not a default value, and updated_at matches created_at upon document creation. These checks align with the PR objectives and address the issue effectively.


963-963: Verify presence update does not alter updated_at.

The test ensures that updating only the presence of a document does not change the updated_at timestamp, which is expected behavior. This is a good practice to verify that unnecessary updates to updated_at are not made.


974-974: Check that updated_at changes with document modifications.

This test verifies that updated_at is modified when the document's content is changed, which is crucial for tracking modifications accurately. It's important to ensure that updated_at reflects the most recent change.

Copy link

codecov bot commented Aug 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.07%. Comparing base (3f4f5d3) to head (f6c1e2e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #977   +/-   ##
=======================================
  Coverage   51.06%   51.07%           
=======================================
  Files          73       73           
  Lines       10782    10784    +2     
=======================================
+ Hits         5506     5508    +2     
  Misses       4725     4725           
  Partials      551      551           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hackerwins hackerwins self-requested a review August 27, 2024 01:23
Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.

@hackerwins hackerwins changed the title Initialize updated_at with created_at when creating new Document Set updated_at with created_at when creating Document Sep 2, 2024
@hackerwins hackerwins merged commit 800f139 into yorkie-team:main Sep 2, 2024
5 checks passed
@window9u window9u deleted the fix-updatedAt branch September 5, 2024 10:18
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.

Set updatedAt value for newly created documents
2 participants