fix(session): preserve time_updated on project_id migration#29109
Open
divitkashyap wants to merge 1 commit into
Open
fix(session): preserve time_updated on project_id migration#29109divitkashyap wants to merge 1 commit into
divitkashyap wants to merge 1 commit into
Conversation
Author
|
@nexxeln this is a follow-up to your #27094 — same root cause ( |
Bulk-rewriting project_id on session rows during startup project
discovery (Project.fromDirectory and Project.migrateProjectId) was
firing Drizzle's $onUpdate hook on time_updated, scrambling the
/sessions timeline by stamping every migrated session with the
startup timestamp.
Pass the column through unchanged via sql\`\${SessionTable.time_updated}\`
so Drizzle skips the auto-update, matching the existing pattern in
projectors.ts and data-migration.ts.
Closes anomalyco#25392
3ed0424 to
c9f83fc
Compare
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.
Issue for this PR
Closes #25392
Type of change
What does this PR do?
Two bulk
UPDATEstatements inproject.tsrewritesession.project_idwithout touchingtime_updated:Project.fromDirectory— moves sessions from theglobalproject into a real project when theirdirectorymatches (runs every time you open a project).Project.migrateProjectId— moves sessions when a project's ID changes (e.g. directory rename).Because
time_updatedhas Drizzle's.$onUpdate(() => Date.now())hook, every row touched by thoseUPDATEs gets itstime_updatedstamped to the current time. Net effect for users with any legacyglobal-scoped sessions:/sessionsshows every old session with today's date on every startup.Fix: pass the column through unchanged via
sql\${SessionTable.time_updated}`, which makes Drizzle skip the auto-update. Same pattern thatprojectors.ts(PR #27094) anddata-migration.ts` already use elsewhere in the file.How did you verify your code works?
Extended the existing regression test in
test/project/migrate-global.test.ts— capturestime_updatedbefore callingfromDirectory, then asserts it is identical after. Confirmed the test fails without the fix (the column drifts by tens of ms) and passes with it.Also verified directly against a local DB:
Before the fix: every recently-opened project's sessions cluster on the launch timestamp. After: the historical timeline is preserved.
bun turbo typecheck --filter opencodepasses.Checklist