@@ -2,7 +2,12 @@ import { exec } from 'mz/child_process'
22import { appendFile , readdir , exists } from 'mz/fs'
33import { dirname } from 'path'
44import mkdirp from 'mkdirp'
5- import { requireEnv } from './utils'
5+ import {
6+ requireEnv ,
7+ wrapDockerCommand ,
8+ getCommand ,
9+ getCommandEnv ,
10+ } from './utils'
611
712async function getMigrationInserts ( { migrationsPath } ) {
813 if ( ! await exists ( migrationsPath ) ) return ''
@@ -15,26 +20,20 @@ async function getMigrationInserts({ migrationsPath }) {
1520 . join ( '' )
1621}
1722
18- async function dump ( {
19- docker,
20- env,
21- structurePath,
22- migrationsPath,
23- knexConfig,
24- } ) {
25- requireEnv ( 'development' , env )
23+ async function dump ( options ) {
24+ const { structurePath, migrationsPath } = options
25+ requireEnv ( 'development' , options . env )
2626
2727 mkdirp . sync ( dirname ( structurePath ) )
2828
29- const command = docker
30- ? `docker-compose exec postgres pg_dump --schema-only --username ${
31- knexConfig . connection . user
32- } ${ knexConfig . connection . database } > ${ structurePath } `
33- : `pg_dump --schema-only --username ${ knexConfig . connection . user } ${
34- knexConfig . connection . database
35- } > ${ structurePath } `
29+ const env = getCommandEnv ( options )
30+ const command = ` ${ getCommand (
31+ options ,
32+ 'pg_dump --schema-only' ,
33+ ) } > ${ structurePath } `
34+
35+ await exec ( wrapDockerCommand ( options , command ) , { env } )
3636
37- await exec ( command )
3837 const migrationInserts = await getMigrationInserts ( { migrationsPath } )
3938 return appendFile ( structurePath , `-- Knex migrations\n\n${ migrationInserts } ` )
4039}
0 commit comments