How should I initialize my schema via node/npm/kne

2019-09-15 04:50发布

问题:

Every new dev in our project is asked to do:

To create the database for the first time, run: $ mysql -u root -p < sql/schema.sql

We're using knex internally in the project. How can we use it to create the schema instead or manual mysql commands? How do we hook up npm for that?

Should we do it on npm install, or npm init? How do we hook up those build targets to knex?

回答1:

Generally speaking, a shell script may satisfy your needs:

  • create database
  • knex migrate latest
  • knex run seeds

npm scripts is what you want, technically, it just open another shell and run commands in it.