-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from smooth-code/improve-scripts
feat: improve scripts
- Loading branch information
Showing
6 changed files
with
96 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
/* eslint-disable max-len */ | ||
import { exec } from 'mz/child_process' | ||
import { preventEnv } from './utils' | ||
import { | ||
preventEnv, | ||
wrapDockerCommand, | ||
getCommand, | ||
getCommandEnv, | ||
} from './utils' | ||
|
||
async function create({ docker, env, knexConfig }) { | ||
preventEnv('production', env) | ||
async function create(options) { | ||
preventEnv('production', options.env) | ||
|
||
const command = docker | ||
? `docker-compose run postgres createdb --host postgres --username ${ | ||
knexConfig.connection.user | ||
} ${knexConfig.connection.database}` | ||
: `createdb --username ${knexConfig.connection.user} ${ | ||
knexConfig.connection.database | ||
}` | ||
|
||
return exec(command) | ||
const env = getCommandEnv(options) | ||
const command = getCommand(options, 'createdb') | ||
return exec(wrapDockerCommand(options, command), { env }) | ||
} | ||
|
||
export default create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
/* eslint-disable max-len */ | ||
import { exec } from 'mz/child_process' | ||
import { preventEnv } from './utils' | ||
import { | ||
preventEnv, | ||
wrapDockerCommand, | ||
getCommand, | ||
getCommandEnv, | ||
} from './utils' | ||
|
||
async function drop({ docker, env, knexConfig }) { | ||
preventEnv('production', env) | ||
async function create(options) { | ||
preventEnv('production', options.env) | ||
|
||
const command = docker | ||
? `docker-compose run postgres dropdb --host postgres --username ${ | ||
knexConfig.connection.user | ||
} ${knexConfig.connection.database} --if-exists` | ||
: `dropdb --username ${knexConfig.connection.user} ${ | ||
knexConfig.connection.database | ||
} --if-exists` | ||
|
||
return exec(command) | ||
const env = getCommandEnv(options) | ||
const command = getCommand(options, 'dropdb --if-exists') | ||
return exec(wrapDockerCommand(options, command), { env }) | ||
} | ||
|
||
export default drop | ||
export default create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
/* eslint-disable max-len */ | ||
import { exec } from 'mz/child_process' | ||
import { preventEnv } from './utils' | ||
import { | ||
preventEnv, | ||
wrapDockerCommand, | ||
getCommand, | ||
getCommandEnv, | ||
} from './utils' | ||
|
||
async function load({ env, docker, structurePath, knexConfig }) { | ||
preventEnv('production', env) | ||
async function load(options) { | ||
const { structurePath } = options | ||
preventEnv('production', options.env) | ||
|
||
const command = docker | ||
? `docker exec -i \`docker-compose ps -q postgres\` psql --username ${ | ||
knexConfig.connection.user | ||
} ${knexConfig.connection.database} < ${structurePath}` | ||
: `psql -h localhost --username ${knexConfig.connection.user} ${ | ||
knexConfig.connection.database | ||
} < ${structurePath}` | ||
const env = getCommandEnv(options) | ||
const command = `${getCommand(options, 'psql')} < ${structurePath}` | ||
|
||
return exec(command) | ||
return exec(wrapDockerCommand(options, command), { env }) | ||
} | ||
|
||
export default load |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters