-
Couldn't load subscription status.
- Fork 287
Enforce NOT NULL and Remove Default Value for mail_attachments.created_at Column #11943
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
Enforce NOT NULL and Remove Default Value for mail_attachments.created_at Column #11943
Conversation
|
Thanks for opening your first pull request in this repository! ✌️ |
…eated_at This migration updates the mail_attachments table to require a non-null created_at timestamp for all attachments and removes any default value. This ensures that every attachment record must have an explicit creation time set by the application, preventing issues with zero or missing timestamps and enabling reliable cleanup of old data. Signed-off-by: dhairyasquad73 <dhairya.jangir.s73@kalvium.community>
b8be40e to
804f18c
Compare
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.
Looks good
|
Thanks a lot for the fix @dhairyajangir. If I understand correctly you are targeting #5901, right? Out of curiosity, what tools did you use for the task? |
|
The commit message says |
|
There are minor linting issues due to the wrong whitespace character used. Run |
Thanks @ChristophWurst,
|
Signed-off-by: dhairyasquad73 <dhairya.jangir.s73@kalvium.community>
|
Linter issues: Test failure: |
I'll fix this asap! |
|
Take your time |
- Inject ITimeFactory into AttachmentService constructor - Set createdAt using timeFactory.getTime() when creating attachments - Update unit tests to mock ITimeFactory and expect createdAt value - Update integration tests to pass ITimeFactory dependency Fixes nextcloud#5901 Signed-off-by: dhairyasquad73 <dhairya.jangir.s73@kalvium.community>
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.
Thank you 🙏
| @@ -0,0 +1,45 @@ | |||
| <?php | |||
|
|
|||
| declare(strict_types=1); | |||
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.
Please increase the version in appinfo/info.xml to 5.6.0-alpha.4 (otherwise the migration will not run).
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.
sure :)
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.
my pleasure |
Co-authored-by: Daniel <mail@danielkesselberg.de> Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
Co-authored-by: Daniel <mail@danielkesselberg.de> Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
Co-authored-by: Daniel <mail@danielkesselberg.de> Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
Co-authored-by: Daniel <mail@danielkesselberg.de> Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
|
Open for more tasks! |
Co-authored-by: Daniel <mail@danielkesselberg.de> Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
line 7 updated `AGPL-3.0-only` set to `AGPL-3.0-or-later` Co-authored-by: Daniel <mail@danielkesselberg.de> Signed-off-by: dhairya <dhairya.jangir.s73@kalvium.community>
Version bump to trigger migration Version5007Date20251019000000 which enforces NOT NULL and removes default on mail_attachments.created_at Signed-off-by: dhairyasquad73 <dhairya.jangir.s73@kalvium.community>
a003bbe
into
nextcloud:bug/5901/set-created-at-on-insert
Fixes #5901
PR: Enforce NOT NULL and Remove Default Value for
mail_attachments.created_atOverview
This pull request addresses an important data integrity issue in the Nextcloud Mail app: previously, attachments could be created with a
created_attimestamp of0orNULLdue to a default value on the database column and missing assignment in the application logic. This made it difficult to reliably clean up old attachments and could lead to inconsistent data.What Has Changed
1. Database Migration
lib/Migration/Version5007Date20251019000000.phpmail_attachmentstable to ensure thecreated_atcolumn is always set.created_atcolumn toNOT NULLand removes any default value.2. How the Migration Works
mail_attachmentstable exists.created_atcolumn exists.NOT NULL)default => null)3. Why This Is Important
Prevents the creation of attachments with missing or invalid timestamps.
Accurate
created_atvalues are essential for reliably cleaning up old attachments and managing storage.This change would have prevented the original bug by making it impossible to insert attachments with a default or missing timestamp.
4. How to Test
created_atfield is set to the current timestamp and is never0orNULL.created_atvalue:5. Additional Notes
created_atof0orNULLshould be reviewed separately if present.