fix(migration): backfill workspace.time_used with current timestamp#26582
Closed
kitlangton wants to merge 1 commit into
Closed
fix(migration): backfill workspace.time_used with current timestamp#26582kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
Conversation
The schema declares time_used with `$default(() => Date.now())`, so new inserts via Drizzle get a real millisecond timestamp. The shipped ALTER migration backfilled existing rows with 0, so any user already on v1.14.43 has workspace rows stuck at 0 — they would sort as the oldest 'most recently used' rows forever, even when actively used pre-upgrade. Drizzle's bun-sqlite migrator skips by name only (not hash), so editing the existing migration file is a no-op for those users. Ship the backfill as a new migration that updates rows where time_used = 0, which: - covers users coming from any prior state in one pass - is idempotent (re-running the migration leaves non-zero rows alone) - leaves the existing migration file untouched Add a regression test for both the fresh-upgrade path and the already-applied-DEFAULT-0 path.
0f56311 to
afa7f8c
Compare
Contributor
Author
|
Closing — on reflection,
The original 'default to now instead of nullable' framing was based on a misread of the shipped fix — the column is already No-op. |
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.
Summary
workspacerows currently gettime_used = 0after the v1.14.43 migration shipped in fix(storage): default workspace time migration #26556, so they sort as the oldest "most recently used" rows forever even when they were in active use before the upgrade.time_used: integer().notNull().$default(() => Date.now()), so newly inserted rows via Drizzle get a real timestamp — only the migrated rows are wrong.20260509205313_backfill_workspace_time_usedthat runsUPDATE workspace SET time_used = unixepoch() * 1000 WHERE time_used = 0.Why a new migration (and not edit the existing one)
Drizzle's
bun-sqlitemigrator filtersgetMigrationsToRunby name only, not hash:So editing
20260507164347_add_workspace_time/migration.sqlin place is a no-op for any user who already applied the priorDEFAULT 0version (i.e. anyone on v1.14.43). A fresh migration with a new timestamp is the only path that reaches them.Why
WHERE time_used = 0DEFAULT 0, every row is 0, the backfill catches them all.time_used. Idempotent and self-documenting.Why
unixepoch() * 1000(notunixepoch('subsec') * 1000)unixepoch('subsec') * 1000introduces vs JSDate.now().Verification
bun test --timeout 5000 test/storage/workspace-time-migration.test.ts— 2 tests, covers both fresh-upgrade and already-DEFAULT-0 paths.bun typecheck