-
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.
Fixed #39 and added migrations, changed estimate format to hh:mm:ss
- Loading branch information
Showing
16 changed files
with
166 additions
and
103 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,2 +1,10 @@ | ||
import './firsttimesetup'; | ||
import './routes'; | ||
import db from './db'; | ||
import migrate from './migrate'; | ||
import logger from './logger'; | ||
|
||
db.then(async () => { | ||
logger.info('Running migrations...'); | ||
await migrate(); | ||
logger.info('Migrations done, starting server...'); | ||
require('./routes'); // eslint-disable-line global-require | ||
}); |
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 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
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,27 @@ | ||
import _ from 'lodash'; | ||
import { models } from './models'; | ||
import migrations from './migrations'; | ||
import logger from './logger'; | ||
|
||
export default async function migrate() { | ||
const migrationsRun = await models.Migration.find({}); | ||
|
||
for (let i = 0; i < migrations.length; ++i) { | ||
const migration = migrations[i]; | ||
if (_.find(migrationsRun, { id: migration.id })) { | ||
logger.debug(`Skipping migration ${migration.id}`); | ||
} else { | ||
logger.info(`Running migration ${migration.id}`); | ||
logger.info(migration.description); | ||
const res = await migration.run(); // eslint-disable-line no-await-in-loop | ||
const migrationResult = new models.Migration({ | ||
id: migration.id, | ||
description: migration.description, | ||
result: res | ||
}); | ||
logger.info('Migration result:', res); | ||
await migrationResult.save(); // eslint-disable-line no-await-in-loop | ||
logger.info(`Migration ${migration.id} done`); | ||
} | ||
} | ||
} |
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,72 @@ | ||
import _ from 'lodash'; | ||
import { models } from './models'; | ||
import { teamsToString } from './helpers'; | ||
import settings from './settings'; | ||
|
||
export default [ | ||
{ | ||
id: 'setupEvents', | ||
description: 'Sets up the events for the first time', | ||
async run() { | ||
// set up default event if not defined | ||
const events = await models.Event.find(); | ||
if (events.length === 0) { | ||
const defaultEvent = new models.Event({ | ||
name: 'Default Event' | ||
}); | ||
return defaultEvent.save(); | ||
} | ||
return null; | ||
} | ||
}, | ||
{ | ||
id: 'setupRoles', | ||
description: 'Sets up the roles for the first time', | ||
async run() { | ||
// set up default roles if not defined | ||
const roles = await models.Role.find(); | ||
if (roles.length === 0) { | ||
return Promise.all(_.map(settings.defaultRoles, role => { | ||
const defaultRole = new models.Role(role); | ||
return defaultRole.save(); | ||
})); | ||
} | ||
return null; | ||
} | ||
}, | ||
{ | ||
id: 'fixTimes', | ||
description: 'Updates estimates from hh:mm format (which turned out to not be very user friendly) to hh:mm:ss format "intelligently"', | ||
async run() { | ||
const allRuns = await models.Submission.find({}, 'estimate'); | ||
await Promise.all(_.map(allRuns, run => { | ||
const match = /^(\d+):(\d+)$/.exec(run.estimate); | ||
if (match) { | ||
const [, hrs, mins] = match; | ||
if (parseInt(hrs, 10) < 15) { | ||
run.estimate = `${hrs.padStart(2, '0')}:${mins}:00`; | ||
} else { | ||
run.estimate = `00:${hrs.padStart(2, '0')}:${mins}`; | ||
} | ||
return run.save(); | ||
} | ||
return true; | ||
})); | ||
return `Updated the estimates on ${allRuns.length} runs`; | ||
} | ||
}, | ||
{ | ||
id: 'addRunners', | ||
description: 'Adds the runners property to all runs', | ||
async run() { | ||
const allRuns = await models.Submission.find({}, 'user runType teams') | ||
.populate('user', 'connections.twitch.displayName') | ||
.populate({ path: 'teams.members', populate: { path: 'user', select: 'connections.twitch.displayName' } }); | ||
await Promise.all(_.map(allRuns, run => { | ||
run.runners = run.runType === 'solo' ? run.user.connections.twitch.displayName : teamsToString(run.teams); | ||
return run.save(); | ||
})); | ||
return `Updated the runners on ${allRuns.length} runs`; | ||
} | ||
} | ||
]; |
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
Oops, something went wrong.