I'm trying to seed some data into a database. The seed file is written in Typescript, then compiled into Javascript for knex to run. When I try and run the seed file I get the error listed in the title.
Error: Invalid seed file: seed.js must have a seed function
The error itself suggests that the code doesn't have a seed function, I've tried altering the JS file itself instead of compiling the TS file and also tried numerous ways of returning the connection.
This is the TS file I've written to compile(seed.ts);
const {
patientData, gpData, ailmentData, surgeryData,
} = require('../data/index.js');
const seed = (knex: any, Promise: any) => knex.migrate
.rollback()
.then(() => knex.migrate.latest())
.then(() => {
const surgeries = knex('surgeries')
.insert(surgeryData)
const patients = knex('patients').insert(patientData).returning('*');
const gps = knex('gps').insert(gpData).returning('*')
return Promise.all([surgeries,patients, gps])
})
.then(([patients, gps]) => {
console.log(patients, '<-- patients')
console.log(gps, '<-- GPs')
// const ailments = knex('ailments').insert
// (ailmentData).returning('*')
return knex('surgeries', 'gps', 'patients')
.returning('*')
})
This is the output of the compiling(seed.js);
var _a = require('../data/index.js'), patientData = _a.patientData, gpData = _a.gpData, ailmentData = _a.ailmentData, surgeryData = _a.surgeryData;
var seed = function (knex, Promise) { return knex.migrate
.rollback()
.then(function () { return knex.migrate.latest(); })
.then(function () {
var surgeries = knex('surgeries')
.insert(surgeryData);
var patients = knex('patients').insert(patientData).returning('*');
var gps = knex('gps').insert(gpData).returning('*');
return Promise.all([surgeries, patients, gps]);
})
.then(function (_a) {
var patients = _a[0], gps = _a[1];
console.log(patients, '<-- patients');
console.log(gps, '<-- GPs');
// const ailments = knex('ailments').insert
// (ailmentData).returning('*')
return knex('surgeries', 'gps', 'patients')
.returning('*');
}); };