-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
knexfile.js for migrations #116
Comments
You can |
You're right, that should work. Thanks |
This helped me too, but @daffl I'm trying to sort out what the best practice is here. Migrating and seeding is a key feature, so would it make sense for feathers-knex to do this type of setup when installed? In addition, the knex CLI isn't available when installed via the instructions in the README, is the preferred approach to also install knex globally to leverage the migration/seed apis? Thanks! |
Feathers adapters try to be as little in the way of the normal usage of the ORM/database as possible. So whatever the Knex documentation recommends will also work here. The main concern of this adapter is to connect a Knex model to the service interface and implement the common querying mechanism but that is pretty much it. |
Cool, fair enough. Didn't see anything in the knex docs to accommodate the feathers setup but like I said the above recommendation worked great. To get migrations/seeding working i just installed knex globally, ran const app = require('./src/app');
module.exports = app.get('postgres'); Then I could use the standard default/production feathers config files and add migration instructions there, e.g.: "postgres": {
"client": "pg",
"connection": "postgres://user:password@localhost:5432/database",
"seeds": {
"directory": "../src/seeds"
} Then seeding worked great with I believe migrations will work as well with this strategy. Thanks for the reply man! |
If you would like to add that information to the Readme, a pull request would be very welcome :) |
Thanks for the solution. May I add that it seems to be necessary to also comment out the parts in the models that create tables, as they seem to run before the migrations are called. |
I know this is an old issue, but I echo the sentiment above re: migrations being a fundamental part of an application. This should really be addressed by the tool and in the documentation. |
It's about adding the information above which can be done by editing the readme. |
I'd like to make a suggestion - I'm using typescript for my project and the provided method in the readme did not work well. I kept running into typescript errors when trying to require ./src/app. I installed typescript-require but that didn't really seem to work but I found a simpler way:
Can we update the readme to this as it supports both normal js and typescript without having to install any additional packages. It also is more efficient as theres in most cases probably no reason to load the entire app just for the knexfile. Correct me if I'm wrong though, this is my first featherjs app. Edit Looking at the readme again, changing knexfile.js to knexfile.ts would have solved my issue as well (first time TS user as well). Curious though if it would still be better to recommend using the config module instead of requiring the entire app. |
I'm trying to configure knex migrations in my feathersjs app, I need to create a knexfile with the configurations for knex migrations to work, but I don't want to have my database configuration in two places (feathersjs config and knexfile), does anybody know how handle database configuration for both?
The text was updated successfully, but these errors were encountered: