delivery_system/src/seed/load-data.js

31 lines
794 B
JavaScript

exports.seed = async function(knex) {
// Delete all existing data from the tables
// check is table exists first
const hasTable = await knex.schema.hasTable('timeslots');
if (hasTable) {
await knex('timeslots').del();
}
// Load data from the JSON files
const holidays = require('../data/holidays.json');
const timeslots = require('../data/timeslots.json');
// Insert the holiday dates into the holidays table
for (const date of holidays) {
await knex('holidays').insert({ date });
}
// Insert the time slots into the timeslots table
for (const { date, slots } of timeslots) {
for (const slot of slots) {
await knex('timeslots').insert({
date,
start_time: slot.start_time,
end_time: slot.end_time
});
}
}
};