diff --git a/knexfile.js b/knexfile.js index ade1164..ec64ae5 100644 --- a/knexfile.js +++ b/knexfile.js @@ -30,7 +30,7 @@ module.exports = { port: process.env.DB_PORT, user: process.env.DB_USER, password: process.env.DB_PASSWORD, - database: process.env.DB_DATABASE, + database: process.env.DB_DATABASE + '_development', }, migrations: { directory: './src/db/migrations', @@ -47,7 +47,7 @@ module.exports = { port: process.env.DB_PORT, user: process.env.DB_USER, password: process.env.DB_PASSWORD, - database: process.env.DB_DATABASE, + database: process.env.DB_DATABASE + '_production', }, migrations: { directory: './src/db/migrations', diff --git a/package.json b/package.json index 87881b1..5f935e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "koa-vue-notes-api", - "version": "1.2.6", + "version": "1.2.7", "description": "A SPA using Koa as the backend and Vue as the frontend.", "author": "John Datserakis", "private": true, diff --git a/readme.md b/readme.md index 4eb5778..d0e9d2f 100644 --- a/readme.md +++ b/readme.md @@ -120,9 +120,9 @@ We use controllers to keep our router thin. The controller's responsibility is t Here is our database setup. This project uses Knex to manage migrations and execute queries. I initially wrote wrote all the MySQL calls using raw SQL, but the need for a migrations manager pushed me towards an ORM for the MySQL database. Knex is awesome - very powerful, easy to use and make queries, and the migrations are nice to have for sure - especially for testing. -For this project you'll need to make two databases in your development environment, `koa_vue_notes` and `koa_vue_notes_testing`. In your production environment you would just have `koa_vue_notes`. Tests use a different database because the data there is extremely volatile - as table information is created and destroyed on every test. +For this project you'll need to make two databases in your development environment, `koa_vue_notes_development` and `koa_vue_notes_testing`. In your production environment you would just have `koa_vue_notes_production`. Tests use a different database because the data there is extremely volatile - as table information is created and destroyed on every test. The `knexfile.js` used here dynamically attaches to the proper database based the `NODE_ENV`. -The `knexfile.js` in the root of the project is all setup with the ability to read your `.env` file. Let's say you download this project - first you'll `npm install`, then create a `koa_vue_notes` database and a `koa_vue_notes_testing` database, then `knex migrate:latest` and `knex seed:run` to create and seed your tables. Currently it's set up to make five users and 100 notes distributed to those users. +The `knexfile.js` in the root of the project is all setup with the ability to read your `.env` file. Make sure to have knex installed globally, `npm install -g knex`. Let's say you download this project - first you'll `npm install`, then create a `koa_vue_notes` database and a `koa_vue_notes_testing` database, then `knex migrate:latest` and `knex seed:run` to create and seed your tables. Currently it's set up to make five users and 100 notes distributed to those users. ### middleware diff --git a/src/db/seeds/dev/seed_users.js b/src/db/seeds/dev/seed_users.js index 5002ceb..7033547 100644 --- a/src/db/seeds/dev/seed_users.js +++ b/src/db/seeds/dev/seed_users.js @@ -21,6 +21,19 @@ exports.seed = async function(knex, Promise) { throw new Error('PASSWORD_ENCRIPTION_ERROR') } + if (i === 0) { + let testUser = { + token: 'qwertyuiop', + firstName: 'DemoFirstName', + lastName: 'DemoLastName', + username: 'demousername', + email: 'demoemail@example.com', + password: password, + } + seedData.push(testUser) + continue + } + let testUser = { token: faker.internet.password(), firstName: faker.name.firstName(), diff --git a/tests/test.js b/tests/test.js index 4bfe4c8..e74df21 100644 --- a/tests/test.js +++ b/tests/test.js @@ -21,7 +21,7 @@ beforeAll(async () => { afterAll(async () => { //After all the tests are done we're going to close our server //and rollback our database. - await db.migrate.rollback() + // await db.migrate.rollback() //This closes the app but it doesn't stop the tests in //Jest when done - that's why we have to --forceExit