Skip to content

Commit

Permalink
Merge pull request #322 from smile0711/city-jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
smile0711 authored Jan 3, 2025
2 parents 19d86ef + 8fec741 commit 1fcad7e
Show file tree
Hide file tree
Showing 43 changed files with 2,124 additions and 603 deletions.
29 changes: 29 additions & 0 deletions api/db/seed/09-update.roles.seed.ts
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);
}
Loading

0 comments on commit 1fcad7e

Please sign in to comment.