Skip to content

Add pscale import d1 for Cloudflare D1 offline migration#1278

Open
no-itsbackpack wants to merge 6 commits into
mainfrom
import-d1
Open

Add pscale import d1 for Cloudflare D1 offline migration#1278
no-itsbackpack wants to merge 6 commits into
mainfrom
import-d1

Conversation

@no-itsbackpack

Copy link
Copy Markdown
Contributor

Summary

Adds pscale import d1 — an offline migration path from Cloudflare D1 (SQLite export) into PlanetScale Postgres.

  • CLI commands: doctor, export, lint, convert-schema, start (lint + plan; --dry-run preview), verify, status, complete / teardown
  • Core package: internal/migrate/d1/ — schema conversion, lint/plan, pgloader + small-table import paths, verify, migration state
  • Slim postgres helpers: internal/postgres/ — connection URI parsing, pgx open, psql discovery/version check only (no logical replication / pg_dump pipeline)
  • MCP tools: D1 import handlers wired into the MCP server
  • Tests & dev scripts: unit tests under internal/migrate/d1/, test_import_d1.sh, and script/d1-import-test/ for local e2e/benchmarks

This PR is intentionally scoped to D1 only. It does not include the postgres branch logical-replication import work from add-postgres-branch-imports.

Test plan

  • go test ./internal/migrate/d1/...
  • Local e2e: sample fixture, ~100MB, and ~2GB pgloader imports against dev API
  • CI green
  • Manual smoke: pscale import d1 doctor, pscale import d1 start --dry-run against a D1 export

Introduces the D1 import command group with lint, plan, pgloader-based load,
and verify, plus slim postgres connection helpers shared by the import path.

Co-authored-by: Cursor <cursoragent@cursor.com>
@no-itsbackpack no-itsbackpack requested a review from a team as a code owner June 26, 2026 19:39
Comment thread internal/migrate/d1/plan.go
Comment thread internal/migrate/d1/prepare.go Outdated
Use fmt.Fprintf instead of WriteString with Sprintf or concatenation to satisfy QF1012 and writestring checks.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread internal/migrate/d1/verify_checks.go Outdated
Comment thread internal/cmd/importcmd/d1.go Outdated
Comment thread internal/cmd/importcmd/d1.go
Unify JSON/human exit codes for status:error responses, populate lint
error envelopes, and format affected Go sources with go fmt.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 270bceb. Configure here.

Comment thread internal/migrate/d1/sqlite_load.go
no-itsbackpack and others added 2 commits June 26, 2026 15:01
Defer .read batch splits until a line completes a statement so multi-line
CREATE TABLE blocks are never cut mid-statement on large exports.

Co-authored-by: Cursor <cursoragent@cursor.com>
Validate migration state before pgloader when --migration-id is set so
state errors surface even when pgloader is missing locally.

Co-authored-by: Cursor <cursoragent@cursor.com>
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