Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pgpm/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dependencies": {
"@pgpmjs/env": "workspace:^",
"@pgpmjs/logger": "workspace:^",
"@pgpmjs/migrate-client": "workspace:^",
"@pgpmjs/server-utils": "workspace:^",
"@pgpmjs/types": "workspace:^",
"csv-to-pg": "workspace:^",
Expand Down
10,068 changes: 2,648 additions & 7,420 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sdk/constructive-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"build": "makage build",
"build:dev": "makage build --dev",
"generate": "tsx scripts/generate-sdk.ts",
"generate:migrate-client": "tsx scripts/generate-migrate-client.ts",
"lint": "eslint . --fix",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch"
Expand Down
74 changes: 74 additions & 0 deletions sdk/constructive-sdk/scripts/generate-migrate-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Generates the migrate-client ORM code from the migrate.graphql schema.
*
* This script lives in constructive-sdk (which already depends on
* @constructive-io/graphql-codegen) and outputs into ../migrate-client/src/
* so that migrate-client itself has zero codegen dependency — avoiding
* circular deps when pgpm/core imports @pgpmjs/migrate-client.
*/
import {
generateMulti,
expandSchemaDirToMultiTarget,
} from '@constructive-io/graphql-codegen';

const SCHEMA_DIR = '../migrate-client/schemas';
const OUTPUT_DIR = '../migrate-client/src';

async function main() {
console.log('Generating migrate-client ORM from schema files...');
console.log(`Schema directory: ${SCHEMA_DIR}`);
console.log(`Output directory: ${OUTPUT_DIR}`);

const baseConfig = {
schemaDir: SCHEMA_DIR,
output: OUTPUT_DIR,
orm: true,
reactQuery: false,
verbose: true,
docs: {
agents: false,
mcp: false,
skills: false,
}
};

const expanded = expandSchemaDirToMultiTarget(baseConfig);
if (!expanded) {
console.error('No .graphql files found in schema directory.');
process.exit(1);
}

console.log(`Found targets: ${Object.keys(expanded).join(', ')}`);

const { results } = await generateMulti({
configs: expanded,
});

let realError = false;

for (const { name, result } of results) {
if (result.success) {
console.log(`[${name}] ${result.message}`);
if (result.tables?.length) {
console.log(` Tables: ${result.tables.join(', ')}`);
}
} else if (result.message?.includes('No tables found')) {
console.log(`[${name}] SKIP: no tables (empty schema)`);
} else {
console.error(`[${name}] ERROR: ${result.message}`);
realError = true;
}
}

if (realError) {
console.error('\nGeneration failed');
process.exit(1);
}

console.log('\nMigrate-client ORM generation completed successfully!');
}

main().catch((err) => {
console.error('Fatal error:', err);
process.exit(1);
});
54 changes: 54 additions & 0 deletions sdk/migrate-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# @pgpmjs/migrate-client

<p align="center" width="100%">
<img height="120" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
</p>

<p align="center" width="100%">
<a href="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml">
<img height="20" src="https://github.com/constructive-io/constructive/actions/workflows/run-tests.yaml/badge.svg" />
</a>
<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>
<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>
</p>

Typed GraphQL ORM client for the Constructive Migrate API (`db_migrate` schema).

Generated from `migrate.graphql` via `@constructive-io/graphql-codegen`.

## Usage

```typescript
import { createClient } from '@pgpmjs/migrate-client';

const db = createClient({
endpoint: 'https://migrate.example.com/graphql',
headers: { Authorization: 'Bearer <token>' },
});

// Fetch all sql_actions for a database
const result = await db.sqlAction.findMany({
select: { id: true, name: true, deploy: true, revert: true, verify: true, content: true },
where: { databaseId: { equalTo: '<database-uuid>' } },
}).unwrap();

console.log(result.sqlActions.nodes);
```

## Regeneration

```bash
pnpm generate
```

This runs codegen against `schemas/migrate.graphql` and outputs to `src/`.

---

Built by the [Constructive](https://constructive.io) team.

## Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

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.
52 changes: 52 additions & 0 deletions sdk/migrate-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@pgpmjs/migrate-client",
"version": "0.0.1",
"author": "Constructive <developers@constructive.io>",
"description": "Typed GraphQL ORM client for the Constructive Migrate API (db_migrate schema)",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/constructive-io/constructive",
"license": "MIT",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/constructive-io/constructive"
},
"bugs": {
"url": "https://github.com/constructive-io/constructive/issues"
},
"scripts": {
"clean": "makage clean",
"prepack": "npm run build",
"build": "makage build",
"build:dev": "makage build --dev",
"generate": "pnpm --filter @constructive-io/sdk run generate:migrate-client",
"lint": "eslint . --fix",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch"
},
"keywords": [
"graphql",
"sdk",
"orm",
"constructive",
"migrate",
"db_migrate",
"pgpm"
],
"dependencies": {
"@0no-co/graphql.web": "^1.1.2",
"@constructive-io/graphql-types": "workspace:^",
"gql-ast": "workspace:^",
"graphql": "^16.13.0"
},
"devDependencies": {
"@types/node": "^22.19.11",
"makage": "^0.1.12",
"typescript": "^5.9.3"
}
}
Loading
Loading