fix(media): store uploaded_at in milliseconds#892
Open
PlusA2M wants to merge 1 commit into
Open
Conversation
Media uploads stored `uploaded_at` as epoch seconds (Math.floor(Date.now()/1000)) while every admin renderer reads it as epoch milliseconds (new Date(uploaded_at)), so new uploads displayed as 1/1970 and sorted below everything else. The rest of core (content tables) uses Date.now() (ms). Standardize on milliseconds: the three upload write sites now store Date.now(), the two api-media JSON readers drop their compensating ×1000, and migration 037 normalizes existing seconds-valued rows (threshold 1e11 ≈ 1973, so already-ms rows are skipped and the migration is safe to re-run). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: PlusA2M <plusa2m@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Media uploads stored
uploaded_atin epoch seconds while the admin renderersread it as epoch milliseconds, so new uploads displayed as
1/1970and sortedto the bottom. This standardizes the column on milliseconds (matching the content
tables) and migrates existing rows.
Fixes #889
Changes
uploaded_atasDate.now()(ms) at the three upload write sites(
admin-media.tsPOST /upload;api-media.tsPOST /uploadandPOST /upload-multiple). The deadcreated_atliteral in the sameapi-mediaobject is bumped to ms too for consistency (it is not inserted).
* 1000in the twoapi-media.tsJSON readers (the datais now ms). The admin/template readers already assume ms, so they are unchanged.
037_fix_media_uploaded_at_units.sqlto normalize legacyseconds-valued rows:
uploaded_at * 1000 WHERE uploaded_at < 1e11. Thethreshold (~1973 in ms) means already-ms rows are skipped and the migration is
safe to re-run. Regenerated
src/db/migrations-bundle.ts.that the API JSON returns a current-year ISO date.
This PR takes the ms-standardization path (the clean long-term fix; matches
content.created_at/updated_at) with a data migration for existing rows.The alternative is display-only: leave the column in seconds and multiply at
the ~5 admin read sites — no migration, but it keeps the unusual seconds
convention. I can switch to that approach if you'd prefer to avoid touching
existing data. (
media.created_at/updated_at/deleted_atare also written inseconds but are not currently displayed; I left those out of scope — let me know
if you'd like them normalized too.)
Testing
Unit Tests
media-uploaded-at-units.test.ts)npm test— full suite green)E2E Tests
Checklist