-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feat: Add created_at, created_at to workspace_schedule and workspaces… #709
Conversation
WalkthroughThis pull request introduces timestamp tracking for the Changes
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
apps/workspaces/migrations/0049_auto_20241223_1039.py (1)
23-32
: Consider adding an updated_at column to workspaces_user for consistency.
Only created_at is added to the workspaces_user table. If you also need to track modifications on user-workspace relationships, you might want to add an updated_at field for completeness. Otherwise, this is fine as-is if you only need creation timestamps.apps/workspaces/models.py (1)
78-79
: Align null constraints with the Workspace model for consistency.
In the Workspace model, created_at and updated_at do not allow null values. However, here, you’re allowing null=True. If there’s no need for these fields to be nullable, consider removing null=True for consistent data integrity:- created_at = models.DateTimeField(auto_now_add=True, null=True, help_text='Created at datetime') - updated_at = models.DateTimeField(auto_now=True, null=True, help_text='Updated at datetime') + created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime') + updated_at = models.DateTimeField(auto_now=True, help_text='Updated at datetime')tests/sql_fixtures/reset_db_fixtures/reset_db.sql (1)
33950-33955
: Consider varying timestamps in test dataAll
workspaces_user
records have identicalcreated_at
timestamps. Consider adding variety to better test sorting, filtering, and time-based features.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/workspaces/migrations/0049_auto_20241223_1039.py
(1 hunks)apps/workspaces/models.py
(1 hunks)tests/sql_fixtures/reset_db_fixtures/reset_db.sql
(7 hunks)
🔇 Additional comments (7)
apps/workspaces/migrations/0049_auto_20241223_1039.py (2)
1-2
: No issues with auto-generated migration header.
This header is typically generated by Django and requires no adjustments.
13-22
: Ensure defaults for created rows.
The added fields (created_at, updated_at) use null=True, which is a common approach when introducing new timestamps to avoid migration failures on existing rows. However, consider setting sensible defaults if you want existing records to have creation timestamps, or confirm the correctness of null values within your application’s logic.
✅ Verification successful
Let me gather information about how these timestamp fields are used in the codebase.
Let me try a different search strategy to understand the model and its usage.
Based on the search results, I can now provide a final response:
Null timestamps are safe to use in this context
The WorkspaceSchedule model is used for managing sync schedules and email notifications. The code shows that records are created using get_or_create()
in the schedule_sync
task, and existing records are queried with filters that don't depend on these timestamp fields. Since the timestamps are purely for auditing purposes and don't affect the core functionality, having null values for existing records is acceptable.
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash
# Search for references to workspaceschedule model and its timestamp fields
rg -i "workspaceschedule.*created_at|created_at.*workspaceschedule" -A 3 -B 3
# Search for any filters or queries using these fields
rg -i "filter.*created_at.*null|created_at.*isnull" -A 2
# Look for model definition
ast-grep --pattern 'class WorkspaceSchedule($$$)'
# Check for any data migrations that might handle these fields
fd -e py -x grep -l "workspaceschedule" {} \; | xargs grep -l "data_migration"
Length of output: 190
Script:
#!/bin/bash
# Find the model definition file
fd -e py -x grep -l "class WorkspaceSchedule" {}
# Look for any references to WorkspaceSchedule in views or serializers
rg "WorkspaceSchedule" -t py -A 3 -B 3
# Check for any existing migrations related to WorkspaceSchedule
fd "workspaceschedule" -e py --full-path | grep "migrations"
Length of output: 11421
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (5)
1992-1993
: LGTM! Proper timestamp implementation
The created_at
column is correctly defined with DEFAULT now()
and NOT NULL
constraint.
4088-4090
: LGTM! Migration sequence is properly ordered
The migration history is consistent and properly sequenced.
34019-34019
: LGTM! Sequence value matches migration count
The sequence value correctly reflects the number of migrations.
33925-33929
: Verify the identical timestamps in test data
All records have the same created_at
and updated_at
timestamps. While this might be acceptable for test fixtures, consider:
- Using varied timestamps to better reflect real-world scenarios
- Adding test cases for different timestamp scenarios
34456-34463
: Verify existing data before applying unique constraint
Adding a unique constraint on source_employee_id
is good for data integrity, but please ensure:
- Existing data complies with the uniqueness requirement
- Application code handles potential constraint violations
error_count integer, | ||
created_at timestamp with time zone, | ||
updated_at timestamp with time zone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add default values and NOT NULL constraints for timestamp columns
The timestamp columns should have appropriate defaults and constraints to ensure data integrity:
created_at
should default tonow()
and beNOT NULL
updated_at
should default tonow()
and have a trigger to update it automatically
- created_at timestamp with time zone,
- updated_at timestamp with time zone
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
Also, consider adding an update trigger:
CREATE TRIGGER update_workspace_schedules_updated_at
BEFORE UPDATE ON public.workspace_schedules
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
…_user
Description
Please add PR description here, add screenshots if needed
Clickup
Please add link here
https://app.clickup.com/1864988/v/l/li/901605343641
Summary by CodeRabbit
New Features
created_at
andupdated_at
fields to the Workspace Schedule model for better tracking of record creation and updates.created_at
column in the Workspaces User table to enhance timestamp management.Bug Fixes
Chores