Skip to content

Commit cd95118

Browse files
committed
refactor(pgpm): split dials sources into @pgpmjs/import and @pgpmjs/diff; move shared pipeline glue into @pgpmjs/transform
1 parent 8599839 commit cd95118

37 files changed

Lines changed: 297 additions & 68 deletions

pgpm/cli/__tests__/diff-e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*
1010
* PREREQUISITES: a running PostgreSQL instance via standard PG* env vars.
1111
*/
12-
import { diffCatalogSnapshots, loadDiffSideFromDisk, snapshotCatalog, withoutColumnOrder } from '@pgpmjs/export';
13-
import { diffChangeSets, loadModule } from '@pgpmjs/transform';
12+
import { loadDiffSideFromDisk } from '@pgpmjs/diff';
13+
import { diffCatalogSnapshots, diffChangeSets, loadModule, snapshotCatalog, withoutColumnOrder } from '@pgpmjs/transform';
1414
import * as fs from 'fs';
1515
import * as path from 'path';
1616
import { teardownPgPools } from 'pg-cache';

pgpm/cli/__tests__/import-e2e.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
*
1515
* PREREQUISITES: a running PostgreSQL instance via standard PG* env vars.
1616
*/
17-
import { copyBlockToInsert, diffCatalogSnapshots, preprocessDumpText, snapshotCatalog } from '@pgpmjs/export';
17+
import { copyBlockToInsert, preprocessDumpText } from '@pgpmjs/import';
18+
import { diffCatalogSnapshots, snapshotCatalog } from '@pgpmjs/transform';
1819
import * as fs from 'fs';
1920
import * as path from 'path';
2021
import { teardownPgPools } from 'pg-cache';

pgpm/cli/__tests__/transform-e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* PREREQUISITES: a running PostgreSQL instance via standard PG* env vars.
1111
*/
12-
import { diffCatalogSnapshots, snapshotCatalog } from '@pgpmjs/export';
12+
import { diffCatalogSnapshots, snapshotCatalog } from '@pgpmjs/transform';
1313
import * as fs from 'fs';
1414
import * as path from 'path';
1515
import { teardownPgPools } from 'pg-cache';

pgpm/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@
4747
"dependencies": {
4848
"@inquirerer/utils": "^3.3.9",
4949
"@pgpmjs/core": "workspace:^",
50+
"@pgpmjs/diff": "workspace:^",
5051
"@pgpmjs/env": "workspace:^",
5152
"@pgpmjs/export": "workspace:^",
53+
"@pgpmjs/import": "workspace:^",
5254
"@pgpmjs/logger": "workspace:^",
5355
"@pgpmjs/slice": "workspace:^",
5456
"@pgpmjs/transform": "workspace:^",

pgpm/cli/src/commands/diff.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@ import { PgpmMigrate, PgpmRow, SqlWriteOptions, writePgpmFiles, writePgpmPlan }
22
import {
33
deltaChangesToRows,
44
DiffSide,
5+
loadDiffSideFromDisk,
6+
sqlToDiffChanges
7+
} from '@pgpmjs/diff';
8+
import { Logger } from '@pgpmjs/logger';
9+
import {
510
diffCatalogSnapshots,
11+
diffChangeSets,
612
EXPORT_GRANULARITIES,
713
ExportGranularity,
814
isExportGranularity,
9-
loadDiffSideFromDisk,
10-
resolveDiffSideKind,
15+
loadModule,
16+
SemanticDiffResult,
17+
SemanticObjectDiff,
1118
snapshotCatalog,
12-
sqlToDiffChanges,
1319
withoutColumnOrder
14-
} from '@pgpmjs/export';
15-
import { Logger } from '@pgpmjs/logger';
16-
import { diffChangeSets, loadModule, SemanticDiffResult, SemanticObjectDiff } from '@pgpmjs/transform';
20+
} from '@pgpmjs/transform';
1721
import { spawn } from 'child_process';
1822
import * as fs from 'fs';
19-
import { CLIOptions, cliExitWithError, extractFirst, Inquirerer, ParsedArgs } from 'inquirerer';
23+
import { cliExitWithError, CLIOptions, extractFirst, Inquirerer, ParsedArgs } from 'inquirerer';
2024
import * as os from 'os';
2125
import * as path from 'path';
2226
import { getPgPool } from 'pg-cache';

pgpm/cli/src/commands/export.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PgpmPackage } from '@pgpmjs/core';
22
import { getEnvOptions } from '@pgpmjs/env';
3-
import { EXPORT_GRANULARITIES, exportGraphQL, exportMigrations, GraphQLClient, graphqlRowToPostgresRow, isExportGranularity, parsePartitionConfig, PartitionConfig } from '@pgpmjs/export';
3+
import { exportGraphQL, exportMigrations, GraphQLClient, graphqlRowToPostgresRow } from '@pgpmjs/export';
4+
import { EXPORT_GRANULARITIES, isExportGranularity, parsePartitionConfig, PartitionConfig } from '@pgpmjs/transform';
45
import { getGitConfigInfo } from '@pgpmjs/types';
56
import { CLIOptions, Inquirerer } from 'inquirerer';
67
import { resolve } from 'path';

pgpm/cli/src/commands/import.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import {
22
dumpCompatibilityWarnings,
3+
importDumpRows,
4+
linkTextualDeps,
5+
loadDumpSource
6+
} from '@pgpmjs/import';
7+
import { Logger } from '@pgpmjs/logger';
8+
import {
39
EXPORT_GRANULARITIES,
410
ExportGranularity,
5-
importDumpRows,
611
isExportGranularity,
7-
linkTextualDeps,
8-
loadDumpSource,
912
parsePartitionConfig,
1013
PartitionConfig,
14+
PartitionCycleError,
1115
partitionExportRows
12-
} from '@pgpmjs/export';
13-
import { Logger } from '@pgpmjs/logger';
14-
import { PartitionCycleError } from '@pgpmjs/transform';
16+
} from '@pgpmjs/transform';
1517
import { cliExitWithError, CLIOptions, Inquirerer, ParsedArgs } from 'inquirerer';
1618
import * as path from 'path';
1719

pgpm/cli/src/commands/transform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PgpmMigrate, PgpmPackage, PgpmRow } from '@pgpmjs/core';
2+
import { Logger } from '@pgpmjs/logger';
23
import {
34
diffCatalogSnapshots,
45
EXPORT_GRANULARITIES,
@@ -7,13 +8,12 @@ import {
78
loadModuleSource,
89
parsePartitionConfig,
910
PartitionConfig,
11+
PartitionCycleError,
1012
PartitionedPackageRows,
1113
partitionExportRows,
1214
restructureExportRows,
1315
snapshotCatalog
14-
} from '@pgpmjs/export';
15-
import { Logger } from '@pgpmjs/logger';
16-
import { PartitionCycleError } from '@pgpmjs/transform';
16+
} from '@pgpmjs/transform';
1717
import * as fs from 'fs';
1818
import { cliExitWithError, CLIOptions, Inquirerer, ParsedArgs } from 'inquirerer';
1919
import * as path from 'path';

pgpm/diff/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @pgpmjs/diff
2+
3+
`pgpm diff` engine: identity-keyed semantic schema diff between any two SQL sources — pgpm modules, SQL dumps, or live databases (dumped via `pg_dump` by the CLI).
4+
5+
Every side normalizes to the same `DiffInputChange[]` seam consumed by the semantic diff driver in `@pgpmjs/transform`, so the comparison is source- and dial-invariant. `deltaChangesToRows` lifts the resulting deltas back onto deployable `PgpmRow`s.
6+
7+
Used by the `pgpm diff` CLI command (`pgpm/cli`). Sibling front doors: `@pgpmjs/export` (live database), `@pgpmjs/import` (dumps).
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ describe('stripDumpPreamble', () => {
5555
'-- PostgreSQL database dump',
5656
'--',
5757
'\\restrict abcdef',
58-
"SET statement_timeout = 0;",
59-
"SET lock_timeout = 0;",
58+
'SET statement_timeout = 0;',
59+
'SET lock_timeout = 0;',
6060
"SELECT pg_catalog.set_config('search_path', '', false);",
6161
"SET default_tablespace = '';",
6262
'\\connect mydb',

0 commit comments

Comments
 (0)