hapipal / schwifty

A model layer for hapi integrating Objection ORM
MIT License
73 stars 10 forks source link

Seeds dir for Knex #62

Closed rickerd closed 6 years ago

rickerd commented 6 years ago

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
        }
    }
};
devinivy commented 6 years ago

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?

rickerd commented 6 years ago

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
);
wswoodruff commented 6 years ago

@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?

rickerd commented 6 years ago

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.

wswoodruff commented 6 years ago

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

What's the error you're getting?

rickerd commented 6 years ago

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.