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
26 changes: 13 additions & 13 deletions pgpm/core/__tests__/files/plan/writer.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'fs';
import os from 'os';
import path from 'path';
import { writeSqitchPlan } from '../../../src/files/plan/writer';
import { SqitchRow } from '../../../src/files/types';
import { writePgpmPlan } from '../../../src/files/plan/writer';
import { PgpmRow } from '../../../src/files/types';

describe('writeSqitchPlan', () => {
describe('writePgpmPlan', () => {
let tempDir: string;
let outputDir: string;

Expand All @@ -18,7 +18,7 @@ describe('writeSqitchPlan', () => {
fs.rmSync(tempDir, { recursive: true, force: true });
});

const createTestRows = (): SqitchRow[] => [
const createTestRows = (): PgpmRow[] => [
{
deploy: 'schemas/test/schema',
revert: 'schemas/test/schema',
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('writeSqitchPlan', () => {
replacer: (str: string) => str.replace('constructive-extension-name', 'test-module')
};

writeSqitchPlan(rows, opts);
writePgpmPlan(rows, opts);

const planPath = path.join(outputDir, 'test-module', 'pgpm.plan');
expect(fs.existsSync(planPath)).toBe(true);
Expand All @@ -67,7 +67,7 @@ describe('writeSqitchPlan', () => {
replacer: (str: string) => str.replace('constructive-extension-name', 'test-module')
};

writeSqitchPlan(rows, opts);
writePgpmPlan(rows, opts);

const planPath = path.join(outputDir, 'test-module', 'pgpm.plan');
const content = fs.readFileSync(planPath, 'utf-8');
Expand All @@ -90,7 +90,7 @@ describe('writeSqitchPlan', () => {
replacer: (str: string) => str.replace('constructive-extension-name', 'test-module')
};

writeSqitchPlan(rows, opts);
writePgpmPlan(rows, opts);

const planPath = path.join(outputDir, 'test-module', 'pgpm.plan');
const content = fs.readFileSync(planPath, 'utf-8');
Expand All @@ -108,7 +108,7 @@ describe('writeSqitchPlan', () => {
replacer: (str: string) => str.replace('constructive-extension-name', 'test-module')
};

writeSqitchPlan(rows, opts);
writePgpmPlan(rows, opts);

const planPath = path.join(outputDir, 'test-module', 'pgpm.plan');
const content = fs.readFileSync(planPath, 'utf-8');
Expand All @@ -117,7 +117,7 @@ describe('writeSqitchPlan', () => {
});

it('should handle rows with dependencies correctly', () => {
const rows: SqitchRow[] = [
const rows: PgpmRow[] = [
{
deploy: 'schemas/test/schema',
content: 'CREATE SCHEMA test;',
Expand All @@ -139,7 +139,7 @@ describe('writeSqitchPlan', () => {
replacer: (str: string) => str.replace('constructive-extension-name', 'test-module')
};

writeSqitchPlan(rows, opts);
writePgpmPlan(rows, opts);

const planPath = path.join(outputDir, 'test-module', 'pgpm.plan');
const content = fs.readFileSync(planPath, 'utf-8');
Expand All @@ -152,7 +152,7 @@ describe('writeSqitchPlan', () => {
});

it('should skip duplicate deploy paths', () => {
const rows: SqitchRow[] = [
const rows: PgpmRow[] = [
{
deploy: 'schemas/test/schema',
content: 'CREATE SCHEMA test;',
Expand All @@ -176,7 +176,7 @@ describe('writeSqitchPlan', () => {

const consoleSpy = jest.spyOn(console, 'log').mockImplementation();

writeSqitchPlan(rows, opts);
writePgpmPlan(rows, opts);

const planPath = path.join(outputDir, 'test-module', 'pgpm.plan');
const content = fs.readFileSync(planPath, 'utf-8');
Expand All @@ -203,7 +203,7 @@ describe('writeSqitchPlan', () => {
}
};

writeSqitchPlan(rows, opts);
writePgpmPlan(rows, opts);

const planPath = path.join(outputDir, 'test-module', 'pgpm.plan');
const content = fs.readFileSync(planPath, 'utf-8');
Expand Down
12 changes: 6 additions & 6 deletions pgpm/core/src/export/export-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path';
import { getPgPool } from 'pg-cache';

import { PgpmPackage } from '../core/class/pgpm';
import { SqitchRow, SqlWriteOptions,writeSqitchFiles, writeSqitchPlan } from '../files';
import { PgpmRow, SqlWriteOptions, writePgpmFiles, writePgpmPlan } from '../files';
import { exportMeta } from './export-meta';

interface ExportMigrationsToDiskOptions {
Expand Down Expand Up @@ -133,8 +133,8 @@ const exportMigrationsToDisk = async ({
]
});

writeSqitchPlan(results.rows, opts);
writeSqitchFiles(results.rows, opts);
writePgpmPlan(results.rows, opts);
writePgpmFiles(results.rows, opts);

let meta = await exportMeta({
opts: options,
Expand Down Expand Up @@ -163,7 +163,7 @@ const exportMigrationsToDisk = async ({
name: metaExtensionName
});

const metaPackage: SqitchRow[] = [
const metaPackage: PgpmRow[] = [
{
deps: [],
deploy: 'migrate/meta',
Expand Down Expand Up @@ -199,8 +199,8 @@ SET session_replication_role TO DEFAULT;
opts.replacer = metaReplacer.replacer;
opts.name = metaExtensionName;

writeSqitchPlan(metaPackage, opts);
writeSqitchFiles(metaPackage, opts);
writePgpmPlan(metaPackage, opts);
writePgpmFiles(metaPackage, opts);
}

pgPool.end();
Expand Down
11 changes: 8 additions & 3 deletions pgpm/core/src/files/plan/writer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';

import { Change, PlanFile, SqitchRow, Tag, ExtendedPlanFile } from '../types';
import { Change, PlanFile, PgpmRow, Tag, ExtendedPlanFile } from '../types';

export interface PlanWriteOptions {
outdir: string;
Expand All @@ -11,9 +11,9 @@ export interface PlanWriteOptions {
}

/**
* Write a Sqitch plan file based on the provided rows
* Write a PGPM plan file based on the provided rows
*/
export function writeSqitchPlan(rows: SqitchRow[], opts: PlanWriteOptions): void {
export function writePgpmPlan(rows: PgpmRow[], opts: PlanWriteOptions): void {
const dir = path.resolve(path.join(opts.outdir, opts.name));
fs.mkdirSync(dir, { recursive: true });

Expand Down Expand Up @@ -165,3 +165,8 @@ export function generateTagLineContent(tag: Tag): string {

return line;
}

/**
* @deprecated Use writePgpmPlan instead. This alias is kept for backwards compatibility.
*/
export const writeSqitchPlan = writePgpmPlan;
23 changes: 14 additions & 9 deletions pgpm/core/src/files/sql/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getEnvOptions } from '@pgpmjs/env';
import fs from 'fs';
import path from 'path';

import { SqitchRow } from '../types';
import { PgpmRow } from '../types';

export interface SqlWriteOptions {
outdir: string;
Expand All @@ -13,9 +13,9 @@ export interface SqlWriteOptions {
}

/**
* Write SQL files for Sqitch migrations (deploy, revert, verify)
* Write SQL files for PGPM migrations (deploy, revert, verify)
*/
export const writeSqitchFiles = (rows: SqitchRow[], opts: SqlWriteOptions): void => {
export const writePgpmFiles = (rows: PgpmRow[], opts: SqlWriteOptions): void => {
rows.forEach((row) => writeVerify(row, opts));
rows.forEach((row) => writeRevert(row, opts));
rows.forEach((row) => writeDeploy(row, opts));
Expand All @@ -30,9 +30,9 @@ const ordered = (arr?: string[]): string[] => {
};

/**
* Write a deploy SQL file for a Sqitch change
* Write a deploy SQL file for a PGPM change
*/
const writeDeploy = (row: SqitchRow, opts: SqlWriteOptions): void => {
const writeDeploy = (row: PgpmRow, opts: SqlWriteOptions): void => {
const globalOpts = getEnvOptions({
migrations: {
codegen: {
Expand Down Expand Up @@ -68,9 +68,9 @@ ${useTx ? 'COMMIT;' : ''}
};

/**
* Write a verify SQL file for a Sqitch change
* Write a verify SQL file for a PGPM change
*/
const writeVerify = (row: SqitchRow, opts: SqlWriteOptions): void => {
const writeVerify = (row: PgpmRow, opts: SqlWriteOptions): void => {
const globalOpts = getEnvOptions({
migrations: {
codegen: {
Expand Down Expand Up @@ -100,9 +100,9 @@ ${useTx ? 'COMMIT;' : ''}
};

/**
* Write a revert SQL file for a Sqitch change
* Write a revert SQL file for a PGPM change
*/
const writeRevert = (row: SqitchRow, opts: SqlWriteOptions): void => {
const writeRevert = (row: PgpmRow, opts: SqlWriteOptions): void => {
const globalOpts = getEnvOptions({
migrations: {
codegen: {
Expand Down Expand Up @@ -130,3 +130,8 @@ ${useTx ? 'COMMIT;' : ''}
`;
fs.writeFileSync(actualFile, content);
};

/**
* @deprecated Use writePgpmFiles instead. This alias is kept for backwards compatibility.
*/
export const writeSqitchFiles = writePgpmFiles;
7 changes: 6 additions & 1 deletion pgpm/core/src/files/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ export interface ResolvedReference {
}

// SQL file types
export interface SqitchRow {
export interface PgpmRow {
deploy: string;
revert?: string;
verify?: string;
content: string;
deps?: string[];
name?: string;
}

/**
* @deprecated Use PgpmRow instead. This alias is kept for backwards compatibility.
*/
export type SqitchRow = PgpmRow;