Skip to content

Commit 1fbcc65

Browse files
authored
Merge pull request #834 from constructive-io/devin/1773712259-migrate-client-no-circular-deps
feat: add @pgpmjs/migrate-client workspace package with zero codegen deps
2 parents f90cc92 + 8d60a62 commit 1fbcc65

23 files changed

Lines changed: 6523 additions & 7420 deletions

pgpm/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"dependencies": {
5151
"@pgpmjs/env": "workspace:^",
5252
"@pgpmjs/logger": "workspace:^",
53+
"@pgpmjs/migrate-client": "workspace:^",
5354
"@pgpmjs/server-utils": "workspace:^",
5455
"@pgpmjs/types": "workspace:^",
5556
"csv-to-pg": "workspace:^",

pnpm-lock.yaml

Lines changed: 2648 additions & 7420 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/constructive-sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"build": "makage build",
2626
"build:dev": "makage build --dev",
2727
"generate": "tsx scripts/generate-sdk.ts",
28+
"generate:migrate-client": "tsx scripts/generate-migrate-client.ts",
2829
"lint": "eslint . --fix",
2930
"test": "jest --passWithNoTests",
3031
"test:watch": "jest --watch"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Generates the migrate-client ORM code from the migrate.graphql schema.
3+
*
4+
* This script lives in constructive-sdk (which already depends on
5+
* @constructive-io/graphql-codegen) and outputs into ../migrate-client/src/
6+
* so that migrate-client itself has zero codegen dependency — avoiding
7+
* circular deps when pgpm/core imports @pgpmjs/migrate-client.
8+
*/
9+
import {
10+
generateMulti,
11+
expandSchemaDirToMultiTarget,
12+
} from '@constructive-io/graphql-codegen';
13+
14+
const SCHEMA_DIR = '../migrate-client/schemas';
15+
const OUTPUT_DIR = '../migrate-client/src';
16+
17+
async function main() {
18+
console.log('Generating migrate-client ORM from schema files...');
19+
console.log(`Schema directory: ${SCHEMA_DIR}`);
20+
console.log(`Output directory: ${OUTPUT_DIR}`);
21+
22+
const baseConfig = {
23+
schemaDir: SCHEMA_DIR,
24+
output: OUTPUT_DIR,
25+
orm: true,
26+
reactQuery: false,
27+
verbose: true,
28+
docs: {
29+
agents: false,
30+
mcp: false,
31+
skills: false,
32+
}
33+
};
34+
35+
const expanded = expandSchemaDirToMultiTarget(baseConfig);
36+
if (!expanded) {
37+
console.error('No .graphql files found in schema directory.');
38+
process.exit(1);
39+
}
40+
41+
console.log(`Found targets: ${Object.keys(expanded).join(', ')}`);
42+
43+
const { results } = await generateMulti({
44+
configs: expanded,
45+
});
46+
47+
let realError = false;
48+
49+
for (const { name, result } of results) {
50+
if (result.success) {
51+
console.log(`[${name}] ${result.message}`);
52+
if (result.tables?.length) {
53+
console.log(` Tables: ${result.tables.join(', ')}`);
54+
}
55+
} else if (result.message?.includes('No tables found')) {
56+
console.log(`[${name}] SKIP: no tables (empty schema)`);
57+
} else {
58+
console.error(`[${name}] ERROR: ${result.message}`);
59+
realError = true;
60+
}
61+
}
62+
63+
if (realError) {
64+
console.error('\nGeneration failed');
65+
process.exit(1);
66+
}
67+
68+
console.log('\nMigrate-client ORM generation completed successfully!');
69+
}
70+
71+
main().catch((err) => {
72+
console.error('Fatal error:', err);
73+
process.exit(1);
74+
});

sdk/migrate-client/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# @pgpmjs/migrate-client
2+
3+
<p align="center" width="100%">
4+
<img height="120" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5+
</p>
6+
7+
<p align="center" width="100%">
8+
<a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
9+
<img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
10+
</a>
11+
<a href="https://github.com/constructive-io/constructive/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
12+
<a href="https://www.npmjs.com/package/@pgpmjs/migrate-client"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=sdk%2Fmigrate-client%2Fpackage.json"/></a>
13+
</p>
14+
15+
Typed GraphQL ORM client for the Constructive Migrate API (`db_migrate` schema).
16+
17+
Generated from `migrate.graphql` via `@constructive-io/graphql-codegen`.
18+
19+
## Usage
20+
21+
```typescript
22+
import { createClient } from '@pgpmjs/migrate-client';
23+
24+
const db = createClient({
25+
endpoint: 'https://migrate.example.com/graphql',
26+
headers: { Authorization: 'Bearer <token>' },
27+
});
28+
29+
// Fetch all sql_actions for a database
30+
const result = await db.sqlAction.findMany({
31+
select: { id: true, name: true, deploy: true, revert: true, verify: true, content: true },
32+
where: { databaseId: { equalTo: '<database-uuid>' } },
33+
}).unwrap();
34+
35+
console.log(result.sqlActions.nodes);
36+
```
37+
38+
## Regeneration
39+
40+
```bash
41+
pnpm generate
42+
```
43+
44+
This runs codegen against `schemas/migrate.graphql` and outputs to `src/`.
45+
46+
---
47+
48+
Built by the [Constructive](https://constructive.io) team.
49+
50+
## Disclaimer
51+
52+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
53+
54+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

sdk/migrate-client/package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@pgpmjs/migrate-client",
3+
"version": "0.0.1",
4+
"author": "Constructive <developers@constructive.io>",
5+
"description": "Typed GraphQL ORM client for the Constructive Migrate API (db_migrate schema)",
6+
"main": "index.js",
7+
"module": "esm/index.js",
8+
"types": "index.d.ts",
9+
"homepage": "https://github.com/constructive-io/constructive",
10+
"license": "MIT",
11+
"publishConfig": {
12+
"access": "public",
13+
"directory": "dist"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/constructive-io/constructive"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/constructive-io/constructive/issues"
21+
},
22+
"scripts": {
23+
"clean": "makage clean",
24+
"prepack": "npm run build",
25+
"build": "makage build",
26+
"build:dev": "makage build --dev",
27+
"generate": "pnpm --filter @constructive-io/sdk run generate:migrate-client",
28+
"lint": "eslint . --fix",
29+
"test": "jest --passWithNoTests",
30+
"test:watch": "jest --watch"
31+
},
32+
"keywords": [
33+
"graphql",
34+
"sdk",
35+
"orm",
36+
"constructive",
37+
"migrate",
38+
"db_migrate",
39+
"pgpm"
40+
],
41+
"dependencies": {
42+
"@0no-co/graphql.web": "^1.1.2",
43+
"@constructive-io/graphql-types": "workspace:^",
44+
"gql-ast": "workspace:^",
45+
"graphql": "^16.13.0"
46+
},
47+
"devDependencies": {
48+
"@types/node": "^22.19.11",
49+
"makage": "^0.1.12",
50+
"typescript": "^5.9.3"
51+
}
52+
}

0 commit comments

Comments
 (0)