Skip to content

Commit

Permalink
database naming, added demouser info to seeding, readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
johndatserakis committed Dec 1, 2017
1 parent 7f315d2 commit 0d783b3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions src/db/seeds/dev/seed_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
password: password,
}
seedData.push(testUser)
continue
}

let testUser = {
token: faker.internet.password(),
firstName: faker.name.firstName(),
Expand Down
2 changes: 1 addition & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d783b3

Please sign in to comment.