-
Notifications
You must be signed in to change notification settings - Fork 8
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 #322 from smile0711/city-jobs
- Loading branch information
Showing
43 changed files
with
2,124 additions
and
603 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {Knex} from 'knex'; | ||
const storeData = require('./../seed_data/update_roles_data.json'); | ||
|
||
export async function seed(knex: Knex): Promise<void> { | ||
console.log('Updating roles data'); | ||
const promises = []; | ||
for(const newRoleData of storeData) { | ||
const p = (async () => { | ||
try { | ||
const rows = await knex('role') | ||
.where('name', '=', newRoleData.name); | ||
if (rows.length === 0) { | ||
console.log(`Adding ${newRoleData.name}`); | ||
await knex('role').insert(newRoleData); | ||
} else { | ||
console.log(`Updating ${newRoleData.name}`); | ||
await knex('role') | ||
.where('name', newRoleData.name) | ||
.update(newRoleData); | ||
} | ||
} catch (err) { | ||
console.error(`There was an error inserting or updating the role: ${newRoleData.name}`); | ||
console.error(err); | ||
} | ||
})(); | ||
promises.push(p); | ||
} | ||
await Promise.all(promises); | ||
} |
Oops, something went wrong.