Skip to content

fix(sync): reorder D1 dump CREATE before INSERT to fix FK-ordering import failure#4

Merged
prdai merged 1 commit into
mainfrom
fix/d1-import-fk-order
Jul 7, 2026
Merged

fix(sync): reorder D1 dump CREATE before INSERT to fix FK-ordering import failure#4
prdai merged 1 commit into
mainfrom
fix/d1-import-fk-order

Conversation

@prdai

@prdai prdai commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Preview envs failed importing dev D1 into the preview DB: no such table: main.cycles: SQLITE_ERROR (BitByBit-B3/neo-project-labor-tracker-poc#199, run 28886570311).
  • wrangler d1 export interleaves CREATE+INSERT per table in source order, not dependency order. A table with an FK to one that sorts later (e.g. workers -> cycles) gets its INSERT run before the target's CREATE.
  • Same failure class documented in neo-project-labor-tracker-poc's scripts/sync-stable-to-dev.sh fix — applying the same reorder here.
  • syncD1 now preprocesses the exported dump: hoists every non-INSERT line (DDL) ahead of all INSERT lines, wrapped in PRAGMA foreign_keys=OFF;, before importing.

Test plan

  • bun run typecheck
  • bun test (9 pass)
  • bun run build
  • Rerun the preview job on neo-project-labor-tracker-poc#199 against a v1.2.2 tag once merged

…port failure

d1 export interleaves CREATE+INSERT per table. A table with an FK to
a table that sorts later alphabetically (e.g. workers -> cycles) gets
its INSERT run before the target table's CREATE, failing import with
"no such table: main.cycles: SQLITE_ERROR" (seen on
neo-project-labor-tracker-poc#199, run 28886570311).

Preprocess the dump before import: hoist every non-INSERT (DDL)
statement ahead of all INSERTs, with foreign_keys=OFF for the load.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@prdai, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 125d9e54-f29a-45b8-b834-9ae8fbeb8408

📥 Commits

Reviewing files that changed from the base of the PR and between b33d3e0 and 998fcbf.

⛔ Files ignored due to path filters (1)
  • dist/index.cjs is excluded by !**/dist/**
📒 Files selected for processing (1)
  • src/sync.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/d1-import-fk-order

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@prdai
prdai merged commit 9707678 into main Jul 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant