@@ -2,7 +2,7 @@ import { exec } from "child_process";
2
2
import { createGzip } from "zlib" ;
3
3
import { createReadStream , createWriteStream , statSync } from "fs" ;
4
4
import { promisify } from "util" ;
5
- import { unlink } from "fs/promises" ;
5
+ import { unlink , mkdir } from "fs/promises" ;
6
6
import * as path from "path" ;
7
7
import { S3Client } from "@aws-sdk/client-s3" ;
8
8
import { Upload } from "@aws-sdk/lib-storage" ;
@@ -99,8 +99,19 @@ async function dumpAndGzip(
99
99
const gzipFile = path . join ( exportsDir , `backup-${ timestamp } .sql.gz` ) ;
100
100
101
101
try {
102
- // Create dump
103
- const dumpCommand = `PGPASSWORD=password docker exec -i postgres pg_dump -U postgres example_db > ${ dumpFile } ` ;
102
+ // Ensure exports directory exists
103
+ await mkdir ( exportsDir , { recursive : true } ) ;
104
+
105
+ // Create dump - detect environment and use appropriate command
106
+ const isCI =
107
+ process . env . CI === "true" || process . env . GITHUB_ACTIONS === "true" ;
108
+ const dumpCommand = isCI
109
+ ? `PGPASSWORD=password pg_dump -h localhost -p 5432 -U postgres example_db > ${ dumpFile } `
110
+ : `PGPASSWORD=password docker exec -i postgres pg_dump -U postgres example_db > ${ dumpFile } ` ;
111
+
112
+ console . log (
113
+ `Running dump command (CI: ${ isCI } ): ${ dumpCommand . replace ( "PGPASSWORD=password" , "PGPASSWORD=***" ) } `
114
+ ) ;
104
115
await execAsync ( dumpCommand ) ;
105
116
106
117
// Get original file size
@@ -149,7 +160,7 @@ async function dumpAndGzip(
149
160
console . log ( "Continuing without S3 upload." ) ;
150
161
}
151
162
} else if ( skipUpload ) {
152
- console . log ( "S3 upload skipped as requested ." ) ;
163
+ console . log ( "S3 upload skipped." ) ;
153
164
} else if ( ! bucketName ) {
154
165
console . log ( "No S3 bucket name provided. Skipping upload." ) ;
155
166
}
0 commit comments