Skip to content
Merged
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
20 changes: 15 additions & 5 deletions pgpm/core/src/export/export-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ interface ExportMigrationsToDiskOptions {
repoName?: string;
/** GitHub username/org for module scaffolding. Required for non-interactive use. */
username?: string;
/** Output directory for service/meta module. Defaults to outdir if not provided. */
serviceOutdir?: string;
}

interface ExportOptions {
Expand All @@ -170,6 +172,8 @@ interface ExportOptions {
repoName?: string;
/** GitHub username/org for module scaffolding. Required for non-interactive use. */
username?: string;
/** Output directory for service/meta module. Defaults to outdir if not provided. */
serviceOutdir?: string;
}

const exportMigrationsToDisk = async ({
Expand All @@ -187,9 +191,12 @@ const exportMigrationsToDisk = async ({
metaExtensionDesc,
prompter,
repoName,
username
username,
serviceOutdir
}: ExportMigrationsToDiskOptions): Promise<void> => {
outdir = outdir + '/';
// Use serviceOutdir for service module, defaulting to outdir if not provided
const svcOutdir = (serviceOutdir || outdir.slice(0, -1)) + '/';

const pgPool = getPgPool({
...options.pg,
Expand Down Expand Up @@ -278,11 +285,11 @@ const exportMigrationsToDisk = async ({
// Detect missing modules at workspace level and prompt user
const svcMissingResult = await detectMissingModules(project, [...SERVICE_REQUIRED_EXTENSIONS], prompter);

// Create/prepare the module directory
// Create/prepare the module directory (use serviceOutdir if provided)
const svcModuleDir = await preparePackage({
project,
author,
outdir,
outdir: svcOutdir,
name: metaExtensionName,
description: metaDesc,
extensions: [...SERVICE_REQUIRED_EXTENSIONS],
Expand Down Expand Up @@ -342,6 +349,7 @@ SET session_replication_role TO DEFAULT;

opts.replacer = metaReplacer.replacer;
opts.name = metaExtensionName;
opts.outdir = svcOutdir;

writePgpmPlan(metaPackage, opts);
writePgpmFiles(metaPackage, opts);
Expand All @@ -363,7 +371,8 @@ export const exportMigrations = async ({
metaExtensionDesc,
prompter,
repoName,
username
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service module files written to wrong directory

The opts.outdir is never updated to svcOutdir before writing the service module files. While preparePackage correctly uses svcOutdir to create the directory structure at line 292, the subsequent calls to writePgpmPlan and writePgpmFiles at lines 353-354 still use opts which contains the original outdir. Only opts.replacer and opts.name are updated at lines 350-351, but opts.outdir remains unchanged. This causes service module migration files to be written to the DB module's directory instead of serviceOutdir, completely breaking the feature this PR aims to implement.

Additional Locations (1)

Fix in Cursor Fix in Web

username,
serviceOutdir
}: ExportOptions): Promise<void> => {
for (let v = 0; v < dbInfo.database_ids.length; v++) {
const databaseId = dbInfo.database_ids[v];
Expand All @@ -382,7 +391,8 @@ export const exportMigrations = async ({
outdir,
prompter,
repoName,
username
username,
serviceOutdir
});
}
};
Expand Down