diff --git a/knexfile.js b/knexfile.js new file mode 100644 index 0000000..884cfc4 --- /dev/null +++ b/knexfile.js @@ -0,0 +1,21 @@ +'use strict'; + +const Path = require('path'); +const Hoek = require('@hapi/hoek'); +const Manifest = require('./server/manifest'); +const Plugin = require('./lib/plugins/@hapipal.schwifty'); + +// Take schwifty registration's knex option +// but specify the plugin's migrations directory + +module.exports = Hoek.applyToDefaults( + { + migrations: { + directory: Path.relative(process.cwd(), Plugin.options.migrationsDir) + } + }, + Manifest + .get('/register/plugins', process.env) + .find(({ plugin }) => plugin === '@hapipal/schwifty') + .options.knex +); diff --git a/lib/migrations/.gitkeep b/lib/migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/models/.gitkeep b/lib/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/plugins/@hapipal.schwifty.js b/lib/plugins/@hapipal.schwifty.js new file mode 100644 index 0000000..4b71d02 --- /dev/null +++ b/lib/plugins/@hapipal.schwifty.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + options: { + migrationsDir: `${__dirname}/../migrations` + } +}; diff --git a/package.json b/package.json index 7bfcea2..c5fcc28 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,12 @@ "dependencies": { "@hapi/boom": "9.x.x", "@hapipal/haute-couture": "4.x.x", - "joi": "17.x.x" + "@hapipal/schwifty": "6.x.x", + "joi": "17.x.x", + "objection": "2.x.x" + }, + "peerDependencies": { + "knex": "0.21.x" }, "devDependencies": { "@hapi/code": "8.x.x", @@ -25,7 +30,11 @@ "@hapi/eslint-plugin-hapi": "4.x.x", "@hapi/glue": "8.x.x", "@hapi/hapi": "20.x.x", +<<<<<<< HEAD "@hapi/inert": "6.x.x", +======= + "@hapi/hoek": "9.x.x", +>>>>>>> 66973ef ((flavor) objection v3.0.0) "@hapi/lab": "24.x.x", "@hapi/vision": "6.x.x", "@hapipal/confidence": "6.x.x", @@ -36,6 +45,11 @@ "dotenv": "8.x.x", "eslint": "7.x.x", "exiting": "6.x.x", +<<<<<<< HEAD "hapi-swagger": "14.x.x" +======= + "knex": "0.21.x", + "sqlite3": "5.x.x" +>>>>>>> 66973ef ((flavor) objection v3.0.0) } } diff --git a/server/manifest.js b/server/manifest.js index 126d373..6233f93 100644 --- a/server/manifest.js +++ b/server/manifest.js @@ -3,6 +3,7 @@ const Dotenv = require('dotenv'); const Confidence = require('@hapipal/confidence'); const Toys = require('@hapipal/toys'); +const Schwifty = require('@hapipal/schwifty'); // Pull .env into process.env Dotenv.config({ path: `${__dirname}/.env` }); @@ -34,7 +35,31 @@ module.exports = new Confidence.Store({ options: {} }, { +<<<<<<< HEAD plugin: './plugins/swagger' +======= + plugin: '@hapipal/schwifty', + options: { + $filter: 'NODE_ENV', + $default: {}, + $base: { + migrateOnStart: true, + knex: { + client: 'sqlite3', + useNullAsDefault: true, // Suggested for sqlite3 + connection: { + filename: ':memory:' + }, + migrations: { + stub: Schwifty.migrationsStubPath + } + } + }, + production: { + migrateOnStart: false + } + } +>>>>>>> 66973ef ((flavor) objection v3.0.0) }, { plugin: {