-
Notifications
You must be signed in to change notification settings - Fork 0
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 #23 from developmentseed/feature/22-setup-script
Setup script Fix #22
- Loading branch information
Showing
6 changed files
with
408 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
yarn.lock | ||
node_modules | ||
.env | ||
cloudformation.yml | ||
cloudformation.yml | ||
setup/config.js |
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 |
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,46 @@ | ||
'use strict'; | ||
const knex = require('knex'); | ||
const setup = require('./structure'); | ||
|
||
const arg = (a) => process.argv.indexOf(a) !== -1; | ||
|
||
const db = knex({ | ||
client: 'pg', | ||
connection: process.argv[2] | ||
}); | ||
|
||
async function checkDangerousDbOp () { | ||
const exists = await db.schema.hasTable('scenarios'); | ||
if (exists && !arg('--force-override')) { | ||
console.log('ERROR: Database is not empty.'); | ||
console.log('Use --force-override if you want to delete everything.'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
async function main () { | ||
try { | ||
if (arg('--help') || arg('-h') || process.argv.length < 3 || process.argv[2] === '--force-override') { | ||
console.log('Set up the RAM database with:') | ||
console.log(''); | ||
console.log(' yarn setup [postgres_connection_string]'); | ||
console.log(''); | ||
console.log('Options:'); | ||
console.log(' --force-override', ' Use to override safe data check.'); | ||
console.log(' WARNING: All data will be lost'); | ||
console.log(''); | ||
process.exit(0); | ||
} | ||
|
||
await checkDangerousDbOp(); | ||
await setup.setupStructure(db); | ||
|
||
console.log('done'); | ||
process.exit(0); | ||
} catch (error) { | ||
console.log(error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
Oops, something went wrong.