-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add createdAt timestamp to email verification and password reset entities #1821
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...rations/1780411916141-AddCreatedAtColumnsIntoPasswordResetAndEmailVerificationEntities.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddCreatedAtColumnsIntoPasswordResetAndEmailVerificationEntities1780411916141 | ||
| implements MigrationInterface | ||
| { | ||
| name = 'AddCreatedAtColumnsIntoPasswordResetAndEmailVerificationEntities1780411916141'; | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(`ALTER TABLE "email_verification" ADD "createdAt" TIMESTAMP NOT NULL DEFAULT now()`); | ||
| await queryRunner.query(`ALTER TABLE "password_reset" ADD "createdAt" TIMESTAMP NOT NULL DEFAULT now()`); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(`ALTER TABLE "password_reset" DROP COLUMN "createdAt"`); | ||
| await queryRunner.query(`ALTER TABLE "email_verification" DROP COLUMN "createdAt"`); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
Does TypeORM@CreateDateColumnsupport the type 'timestamptz' option, and how does it compare to@columnwith default CURRENT_TIMESTAMP?💡 Result:
Yes, TypeORM's
@CreateDateColumndecorator supports the type option, which allows you to specify 'timestamptz' (or 'timestamp with time zone') to ensure the database column is created with timezone awareness [1][2][3]. When you define@CreateDateColumn({ type: 'timestamptz' }), TypeORM configures the underlying database schema to use the appropriate timezone-aware timestamp type [1][2]. This is often preferred over the default behavior, which may create a naive 'timestamp' column that lacks timezone information, potentially leading to inconsistencies when storing and retrieving dates across different server or application timezones [4][2]. Comparison:@CreateDateColumnvs.@Columnwith default CURRENT_TIMESTAMP 1. Functional Purpose@CreateDateColumnis a specialized decorator designed specifically for tracking entity creation [5]. It automatically sets the field to the current date and time upon insertion without requiring manual intervention [5]. In contrast,@Columnis a general-purpose decorator [6]. When combined with default: => 'CURRENT_TIMESTAMP', it functions similarly to@CreateDateColumnbut requires you to manually define the column attributes [7][8][9]. 2. Configuration and Automation@CreateDateColumnhandles metadata and behavior automatically (such as ensuring the value is set on insert) [5]. While you can override the type (e.g., to 'timestamptz'), it is intended to be used as-is [5]. Using@Columnrequires more verbose configuration [7]. You must explicitly provide the type, the default value (often using a SQL expression like => 'CURRENT_TIMESTAMP'), and potentially manage other behaviors manually [7][8][9]. 3. Recommendation If you need a standard "created at" field,@CreateDateColumnis the recommended approach for its simplicity and specialized integration [5]. However, if you require specific database-level configuration (such as custom default expressions, specific timezone handling beyond the default, or database-specific column types that@CreateDateColumndoes not cleanly expose), using@Columnwith a custom default is a viable and flexible alternative [1][7]. If you encounter issues with time offsets or timezone mismatches, explicitly setting type: 'timestamptz' in either decorator is the standard fix to ensure the database preserves timezone information correctly [4][2].Citations:
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 200
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 200
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 3699
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 50380
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 1505
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 1505
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 13261
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 13261
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 5371
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 5319
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 1256
Prefer
@CreateDateColumn()forcreatedAt(keep DB type aligned).@Column(... DEFAULT CURRENT_TIMESTAMP)with@CreateDateColumn()for idiomatic insert-time population.email_verification.createdAtis currentlyTIMESTAMP ... DEFAULT now()(and is used for the 1-day cutoff viacreatedAt >= Constants.ONE_DAY_AGO()), so switch totype: 'timestamp'to match the existing schema; only usetype: 'timestamptz'after adding a migration to alter the column type.♻️ Proposed change
🤖 Prompt for AI Agents