-
Notifications
You must be signed in to change notification settings - Fork 0
fix(api): start new IPNS entries at seq 1 to match client expectation #255
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
apps/api/src/migrations/1740500000000-BackfillIpnsSequenceNumbers.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| /** | ||
| * Migration: Backfill IPNS sequence numbers from '0' to '1' | ||
| * | ||
| * Before this fix, upsertFolderIpns created new entries with | ||
| * sequenceNumber='0' while the client stored sequenceNumber=1n | ||
| * (computing 0+1=1 after the first publish). Phase 16 added | ||
| * conflict detection via expectedSequenceNumber, exposing this | ||
| * off-by-one mismatch as 409 errors. | ||
| * | ||
| * This migration bumps non-root entries that have published content | ||
| * (latestCid IS NOT NULL) from '0' to '1' to align with what | ||
| * the client already stored. | ||
| * | ||
| * Root entries (created during vault init with latestCid=null) are | ||
| * excluded because their first actual publish goes through the | ||
| * UPDATE path which correctly increments. | ||
| */ | ||
| export class BackfillIpnsSequenceNumbers1740500000000 implements MigrationInterface { | ||
| name = 'BackfillIpnsSequenceNumbers1740500000000'; | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| UPDATE "folder_ipns" | ||
| SET "sequence_number" = '1' | ||
| WHERE "sequence_number" = '0' | ||
| AND "latest_cid" IS NOT NULL | ||
| AND "is_root" = false | ||
| `); | ||
| } | ||
|
|
||
| public async down(_queryRunner: QueryRunner): Promise<void> { | ||
| // Not reversible — we can't distinguish which rows were backfilled | ||
| // vs. which legitimately had sequence_number='1' before. | ||
| // This is a data-only migration with no schema changes. | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.