-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nathan Fiscaletti
authored and
Nathan Fiscaletti
committed
Jan 9, 2022
1 parent
69fc847
commit 371b3ac
Showing
11 changed files
with
168 additions
and
23 deletions.
There are no files selected for viewing
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,14 @@ | ||
server: | ||
host: '127.0.0.1' | ||
port: 1234 | ||
https: | ||
enabled: false | ||
certificate: '/absolute/path/to.crt' | ||
private_key: '/absolute/path/to.key' | ||
|
||
database: | ||
host: 'localhost' | ||
port: 3306 | ||
user: 'root' | ||
password: 'aoc1080p' | ||
database: 'coattail' |
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,14 @@ | ||
server: | ||
host: '127.0.0.1' | ||
port: 1234 | ||
https: | ||
enabled: false | ||
certificate: '/absolute/path/to.crt' | ||
private_key: '/absolute/path/to.key' | ||
|
||
database: | ||
host: 'localhost' | ||
port: 3306 | ||
user: 'root' | ||
password: 'aoc1080p' | ||
database: 'coattail' |
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,14 @@ | ||
server: | ||
host: '127.0.0.1' | ||
port: 1234 | ||
https: | ||
enabled: false | ||
certificate: '/absolute/path/to.crt' | ||
private_key: '/absolute/path/to.key' | ||
|
||
database: | ||
host: 'localhost' | ||
port: 3306 | ||
user: 'root' | ||
password: 'aoc1080p' | ||
database: 'coattail' |
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,48 @@ | ||
const environment = require(`../../environment`); | ||
const config = require(`../../config`); | ||
const connection = require(`../../core/data/connection`); | ||
|
||
module.exports = { | ||
description: 'Basic actions pertaining to database management.', | ||
actions: { | ||
"migrate": { | ||
description: 'Manages migrations', | ||
flags: { | ||
"latest": "Run all migrations that have not yet been run.", | ||
"rollback": "Rollback the last batch of migrations performed." | ||
} | ||
}, | ||
}, | ||
|
||
migrate: async (flags) => { | ||
const conf = config.load(); | ||
const conn = connection.connect(conf); | ||
|
||
if (flags.includes('latest')) { | ||
console.log(`Using environment: ${environment.getEnvironmentName()}`) | ||
const [batchNo, log] = await conn.migrate.latest({ | ||
directory: './lib/core/data/migrations' | ||
}); | ||
if (log.length === 0) { | ||
console.log('Already up to date'); | ||
} | ||
console.log(`Batch ${batchNo} run: ${log.length} migrations`); | ||
console.log(log.join('\n')); | ||
process.exit(); | ||
} | ||
|
||
if (flags.includes('rollback')) { | ||
console.log(`Using environment: ${environment.getEnvironmentName()}`) | ||
const [batchNo, log] = await conn.migrate.rollback({ | ||
directory: './lib/core/data/migrations' | ||
}); | ||
if (log.length === 0) { | ||
console.log('Already at the base migration'); | ||
} | ||
console.log(`Batch ${batchNo} rolled back: ${log.length} migrations`); | ||
console.log(log.join('\n')); | ||
process.exit(); | ||
} | ||
} | ||
} | ||
|
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,18 +1,14 @@ | ||
const fs = require(`fs`); | ||
const path = require(`path`); | ||
const yaml = require(`js-yaml`); | ||
const { getEnvironmentName } = require(`./environment`); | ||
|
||
module.exports = { | ||
load: () => { | ||
const dir = `${__dirname}/../config`; | ||
const configs = fs.readdirSync(dir).filter(element => element.endsWith(`.yml`) || element.endsWith(`.yaml`)); | ||
const results = []; | ||
load: (env = 'development') => { | ||
env = getEnvironmentName(env); | ||
|
||
for(const configFile of configs) { | ||
const contents = fs.readFileSync(path.join(dir, configFile), 'utf8'); | ||
results[path.parse(configFile).name] = yaml.load(contents); | ||
} | ||
|
||
return results; | ||
const location = path.join(__dirname, '../config/', `${env}.yaml`); | ||
const contents = fs.readFileSync(location, 'utf8'); | ||
return yaml.load(contents); | ||
} | ||
}; |
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,41 @@ | ||
// Update with your config settings. | ||
|
||
module.exports = { | ||
|
||
development: { | ||
client: 'mysql', | ||
connection: require(`../../config`).load(`development`).database, | ||
pool: { | ||
min: 2, | ||
max: 10 | ||
}, | ||
migrations: { | ||
tableName: 'knex_migrations' | ||
} | ||
}, | ||
|
||
staging: { | ||
client: 'mysql', | ||
connection: require(`../../config`).load(`staging`).database, | ||
pool: { | ||
min: 2, | ||
max: 10 | ||
}, | ||
migrations: { | ||
tableName: 'knex_migrations' | ||
} | ||
}, | ||
|
||
production: { | ||
client: 'mysql', | ||
connection: require(`../../config`).load(`production`).database, | ||
pool: { | ||
min: 2, | ||
max: 10 | ||
}, | ||
migrations: { | ||
tableName: 'knex_migrations' | ||
} | ||
} | ||
|
||
}; |
11 changes: 11 additions & 0 deletions
11
lib/core/data/migrations/20220109183353_create_subscriptions.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,11 @@ | ||
const tableName = 'subscriptions'; | ||
|
||
exports.up = function(knex) { | ||
return knex.schema.createTable(tableName, function (table) { | ||
table.increments('id'); | ||
}); | ||
}; | ||
|
||
exports.down = function(knex) { | ||
return knex.schema.dropTable(tableName); | ||
}; |
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,16 @@ | ||
const VALID_ENVS = [ 'development', 'production', 'staging' ]; | ||
|
||
function getEnvironmentName(env = 'development') { | ||
if (process.env.NODE_ENV) { | ||
if (!VALID_ENVS.includes(process.env.NODE_ENV)) { | ||
throw new Error(`Invalid value ${process.env.NODE_ENV} for NODE_ENV envirionment variable. Must be one of [ ${VALID_ENVS.join(', ')} ].`); | ||
} | ||
env = process.env.NODE_ENV; | ||
} | ||
|
||
return env; | ||
} | ||
|
||
module.exports = { | ||
getEnvironmentName | ||
}; |