hapipal / schwifty

A model layer for hapi integrating Objection ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seeds dir for Knex

rickerd opened this issue · comments

I'm building an API on Hapi pal with Haute Couture, Hoek, Knex, Objection and Schwifty all is fine but when i use the seedsDir it breaks Hapi itself. The server won't start.
Tho I am able to run migrations + seeds.

Maybe it's an idea to add this to the options? I've been looking into it but can't find where to add it. I'm not that skilled in Schwifty/node yet.

module.exports = {
    plugins: {
        options: {
            migrationsDir: `${__dirname}/../migrations`,
            seedsDir: `${__dirname}/../seeds`, // <== this is making problems
        }
    }
};

We use a seeds directory sometimes without issue. Can you show how you had it setup when it was breaking hapi, and what specific error occurred?

It was only breaking Hapi when I added the seedsDir to the schwifty.js file like above.
When I put the directory in the knex.js file it all works just fine.

const Path = require("path");
const Hoek = require("hoek");
const Manifest = require("./server/manifest");
const PluginConfig = require("./lib/plugins/schwifty").plugins.options;

// Take schwifty registration's knex option
// but specify the plugin's migrations directory

module.exports = Hoek.applyToDefaults(
    {
        migrations: {
            directory: Path.relative(process.cwd(), PluginConfig.migrationsDir)
        },
        seeds: {
            directory: Path.relative(process.cwd(), `${PluginConfig.migrationsDir}/../seeds`) // <= placed it here and before I just used PluginConfig.seedsDir
        }
    },
    Manifest
        .get("/register/plugins", process.env)
        .find(({plugin}) => plugin === "schwifty")
        .options.knex
);

@rickerd The seeds config would look something like, (In the Manifest):

{
    plugin: 'schwifty',
    options: {
        ...,
        knex: {
            seeds: { directory: 'lib/seeds' } // Path relative to the project root
        }
    }
}

Also what error are you getting?

Now i'm not getting any errors anymore but I used the boilerplate.
https://github.com/hapipal/boilerplate/blob/objection-v2.2.1/lib/plugins/schwifty.js

When I add seedsDir to this file.. Hapi breaks. Maybe i'm doing this wrong but now I just moved it to https://github.com/hapipal/boilerplate/blob/objection-v2.2.1/knexfile.js this file.

Ok – the seeds prop should be a sibling of migrations in that 2nd link

What's the error you're getting?

Yeah i've done that and it works like a charm.
It's just that i thought it maybe could be in the schwifty.js file. But it works tho how I have it now.