Repository navigation
chore: normalise createdAt before the feed starts ordering on it - #17
Merged
Merged
Conversation
Pagination needs the feed and the leaderboard to order in the query rather than sort in the client, and Firestore's ordering has two behaviours that turn old data into damage a user can see: - A document that lacks the ordered field is excluded from the query. Not sorted last — absent. A note written before createdAt existed would vanish from the feed with nothing to indicate it ever had. - Values sort by type before value, and numbers come before timestamps. A note whose createdAt is epoch millis would land below every timestamped note whatever its date. toPost() already reads both shapes, and the project owner confirms notes from an older version of the app exist, so both are real. Neither announces itself: the first is a note quietly missing, the second a feed quietly in the wrong order. backfill-created-at.js normalises every note to a Timestamp. It reports by default and writes only with --apply, leaves notes that are already correct alone so a partial failure can simply be re-run, and batches writes 450 at a time. A note with no date anywhere is dated to the epoch rather than to now: inventing a recent date would float undated legacy notes to the top of every feed, which is a louder lie than showing them last. The report says how many fall into that case before anything is written. Eight tests run it against the emulator with legacy-shaped documents. The one that carries the argument asserts the hazard directly: an ordered query over two notes, one of them undated, returns one document before the migration and two after. The CLI path was also run end to end against the emulator — dry run reported 3 scanned, 2 needing a write, and changed nothing; --apply then wrote 2. This deliberately ships before the pagination it enables. Migrating the data and changing the query in one commit would mean the ordering going live against un-normalised documents if the second half failed. Kept in firestore-tests/ rather than a second Node project: it is the same emulator, the same dependencies and the same CI job, and the migration needs that emulator to be verified at all. The package description now says so. Co-Authored-By: Claude Opus 5 <noreply@anthropic.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.
Groundwork for pagination. Paginating the feed and the leaderboard means ordering in the query rather than sorting in the client — and Firestore's ordering has two behaviours that turn old data into damage a user can see:
createdAtexisted would vanish from the feed with nothing to indicate it ever had.createdAtis epoch millis would land below every timestamped note whatever its date.toPost()already reads both shapes, and notes from an older version of the app do exist, so both are real. Neither announces itself: the first is a note quietly missing, the second a feed quietly in the wrong order.The migration
backfill-created-at.jsnormalises every note to aTimestamp.--applyTimestampare untouched, so a partial failure can simply be re-runVerification
Eight tests run it against the emulator with legacy-shaped documents. The one that carries the argument asserts the hazard directly: an ordered query over two notes, one of them undated, returns one document before the migration and two after.
The CLI path was also run end to end against the emulator — the dry run reported 3 scanned and 2 needing a write and changed nothing;
--applythen wrote 2.Firestore suite is 32 → 40 tests.
Two choices worth naming
This ships before the pagination it enables. Migrating the data and changing the query in one commit would mean the ordering going live against un-normalised documents if the second half failed.
It lives in
firestore-tests/rather than a second Node project: same emulator, same dependencies, same CI job — and the migration needs that emulator to be verified at all. The package description now says so.🤖 Generated with Claude Code