Skip to content

refactor(export): add @pgpmjs/migrate-client workspace package for typed sql_actions fetching#823

Open
pyramation wants to merge 3 commits intofeature/pgpm-export-graphqlfrom
devin/1773564678-export-migrate-client
Open

refactor(export): add @pgpmjs/migrate-client workspace package for typed sql_actions fetching#823
pyramation wants to merge 3 commits intofeature/pgpm-export-graphqlfrom
devin/1773564678-export-migrate-client

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Mar 15, 2026

refactor(export): add @pgpmjs/migrate-client workspace package for typed sql_actions fetching

Summary

Replaces the hand-rolled GraphQLClient usage for fetching sql_actions from the migrate endpoint with a new workspace package (@pgpmjs/migrate-client) that provides a typed ORM client generated from the migrate.graphql schema.

Before: Manual field strings + untyped fetchAllNodes('sqlActions', 'id\ndatabaseId\n...', { databaseId })
After: Typed migrateDb.sqlAction.findMany({ select: { id: true, ... }, where: { databaseId: { equalTo: databaseId } } })

Architecture

  • sdk/migrate-client/ — new workspace package containing the migrate.graphql schema and generated ORM code (SqlActionModel, MigrateFileModel, executeSql, runMigration)
  • @constructive-io/graphql-codegen is a devDependency only (used for pnpm generate regeneration)
  • Runtime dependencies are minimal: gql-ast, @0no-co/graphql.web, @constructive-io/graphql-types
  • pgpm/core depends on it via workspace:^no cross-repo npm publish required

The GraphQLClient and graphql-naming.ts are not deleted — they're still used by export-graphql-meta.ts (meta/services endpoint) and the CLI's database/schema fetching, which use a different GraphQL API schema.

Updates since last revision

  • Moved from cross-repo npm dep to workspace package. Originally this PR depended on @constructive-db/migrate-client from constructive-db#586 which would need to be published to npm. Now @pgpmjs/migrate-client lives in sdk/migrate-client/ as a workspace dep — no publishing step needed.
  • Moved from pgpm/ to sdk/ directory to match the convention of other SDK packages (constructive-sdk, constructive-cli, constructive-react).
  • The ORM source files were copied from the constructive-db generated output and committed directly. A pnpm generate script is included for future regeneration from the schema file.

Review & Testing Checklist for Human

  • ORM code was copied, not locally generated. The pnpm generate script in sdk/migrate-client requires graphile-connection-filter (transitive dep of codegen) which wasn't available in the build environment. The committed ORM files were copied from constructive-db's existing generated output. Verify that pnpm generate works in a fully-configured environment, or that the copied output matches what local codegen would produce.
  • conditionwhere behavioral change: The old code passed condition: { databaseId } (PostGraphile exact-match condition arg). The new code uses where: { databaseId: { equalTo: databaseId } } (PostGraphile filter arg). These should be functionally equivalent for UUID equality, but verify against a live migrate API that the same rows are returned.
  • Loss of retry logic: The old GraphQLClient.query() had 3 retries with exponential backoff for transient network errors (ECONNRESET, ECONNREFUSED, etc.). The ORM's FetchAdapter does not retry. Decide whether this is acceptable or whether a retry wrapper should be added.
  • Manual pagination correctness: The new code manually pages with first: 100 + afterCursor in a while loop. The old code used fetchAllNodes which abstracted pagination. Verify that the manual loop terminates correctly and returns identical results.
  • Schema drift: sdk/migrate-client/schemas/migrate.graphql is a static copy from constructive-db. If the upstream db_migrate schema changes, this file must be manually re-copied and pnpm generate re-run.
  • No CI ran on this PR (base branch feature/pgpm-export-graphql). Build was verified locally only. Recommend running pgpm export --graphql-endpoint <private-api> --migrate-endpoint <migrate-api> against a live Constructive instance to verify sql_actions are fetched and written correctly.

Notes

…ions fetching

Replace the hand-rolled GraphQLClient usage for sql_actions with the typed
ORM client from @constructive-db/migrate-client:

- Type-safe query building (no manual field strings)
- Type-safe filtering (no string condition building)
- Proper cursor-based pagination via ORM's findMany()
- Uses ORM's FetchAdapter instead of custom HTTP client for migrate endpoint

The GraphQLClient is still used for meta/services endpoint fetching
(export-graphql-meta.ts and CLI), since those use a different API schema.
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…grate-client

- Create pgpm/migrate-client/ as a workspace package (no cross-repo npm dep)
- Copy migrate.graphql schema + generated ORM from constructive-db
- Add codegen generate script for future regeneration
- Update pgpm/core to use workspace:^ dependency
- Update import from @constructive-db/migrate-client to @pgpmjs/migrate-client
@devin-ai-integration devin-ai-integration bot changed the title refactor(export): use @constructive-db/migrate-client ORM for sql_actions fetching refactor(export): add @pgpmjs/migrate-client workspace package for typed sql_actions fetching Mar 15, 2026
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