Skip to content

Commit

Permalink
moved database creation to only run when a flag is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Crow committed Dec 3, 2021
1 parent 6dabd0f commit 040e7b2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ In the ```config``` folder, create the following files:
- database

You must GRANT ALL privileges to the given user on the given database

Once you have created these files, run the program using
```
node index.js -d
```
The `-d` flag tells the program to create the database tables and indexes it
needs.

# Command Line Options
- `-d`: create database tables and indexes that are missing. Does not delete or
modify existing tables, so you needn't worry if you run it when tables are
already set up.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const bodyParser = require("body-parser");
const {mysqlOptions, get} = require("./src/config.js");
const {createServices} = require("./src/model/export.js");
const {registerControllers} = require("./src/controllers/export.js");
const {parseCommandLineArguments} = require("./src/commandLine.js");
const {
extractMySqlConfig,
DatabaseConnection,
createRequiredTablesIn
DatabaseConnection
} = require("./src/model/database.js");
const {testDatabase} = require("./src/test.js");

Expand Down Expand Up @@ -42,7 +42,7 @@ app.use(session({


const db = new DatabaseConnection(get("dbPrefix"), mysqlOptions);
createRequiredTablesIn(db); //todo only run when cmd line flag is passed
parseCommandLineArguments(db);
//testDatabase(db);


Expand Down
19 changes: 19 additions & 0 deletions src/commandLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
This is a basic command line argument parser. Future versions will want to use a
real CLI library as the program grows more complicated.
*/



const {createRequiredTablesIn} = require("./model/database.js");



async function parseCommandLineArguments(databaseConnection){
const args = process.argv;

if(args.includes("-d")){
await createRequiredTablesIn(databaseConnection);
}
}
exports.parseCommandLineArguments = parseCommandLineArguments;

0 comments on commit 040e7b2

Please sign in to comment.