forked from goldcaddy77/warthog
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): adds db:create and db:drop (goldcaddy77#133)
- Loading branch information
1 parent
27a8ab2
commit 61cc092
Showing
37 changed files
with
371 additions
and
56 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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { WarthogGluegunToolbox } from '../types'; | ||
|
||
module.exports = { | ||
name: 'db:create', | ||
run: async (toolbox: WarthogGluegunToolbox) => { | ||
const { db } = toolbox; | ||
await db.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { WarthogGluegunToolbox } from '../types'; | ||
|
||
module.exports = { | ||
name: 'db:drop', | ||
run: async (toolbox: WarthogGluegunToolbox) => { | ||
const { db } = toolbox; | ||
await db.drop(); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as cosmiconfig from 'cosmiconfig'; | ||
import { getBaseConfig } from '../src'; | ||
|
||
export async function getConfig() { | ||
const explorer = cosmiconfig('warthog'); | ||
const config = await explorer.search(); | ||
const baseConfig = getBaseConfig(); | ||
|
||
return { | ||
...config, | ||
...baseConfig | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { GluegunToolbox } from 'gluegun'; | ||
// TypeORM doesn't allow for the creation of DBs via QueryRunner, so use pgtools | ||
// @ts-ignore | ||
import * as pgtools from 'pgtools'; | ||
import * as util from 'util'; | ||
|
||
import { getConfig } from '../config'; | ||
|
||
module.exports = (toolbox: GluegunToolbox) => { | ||
toolbox.db = { | ||
create: async function create() { | ||
const config = await getConfig(); | ||
const createDb = util.promisify(pgtools.createdb) as Function; | ||
|
||
try { | ||
await createDb(getPgConfig(), config.database); | ||
} catch (error) { | ||
if (error.message.indexOf('duplicate') > 0) { | ||
toolbox.print.error(`Database '${config.database}' already exists`); | ||
return; | ||
} | ||
} | ||
toolbox.print.info(`Database '${config.database}' created!`); | ||
}, | ||
drop: async function create() { | ||
const config = await getConfig(); | ||
const dropDb = util.promisify(pgtools.dropdb) as Function; | ||
|
||
try { | ||
await dropDb(getPgConfig(), config.database); | ||
} catch (error) { | ||
if (error.name === 'invalid_catalog_name') { | ||
toolbox.print.error(`Database '${config.database}' does not exist`); | ||
return; | ||
} | ||
} | ||
toolbox.print.info(`Database '${config.database}' dropped!`); | ||
} | ||
}; | ||
}; | ||
|
||
async function getPgConfig() { | ||
const config = await getConfig(); | ||
return { | ||
host: config.host, | ||
user: config.username, | ||
password: config.password, | ||
port: config.port | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { GluegunToolbox } from 'gluegun'; | ||
|
||
export interface WarthogGluegunToolbox extends GluegunToolbox { | ||
db: { | ||
create: Function; | ||
drop: Function; | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
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
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
cli: { | ||
generatePath: './src/{kebabName}' | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
warthog.sqlite.tmp |
Oops, something went wrong.