forked from johndatserakis/koa-vue-notes-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
knex work, seeds, migrations. Test file set up just a tiny bit more.
- Loading branch information
1 parent
4199502
commit 43d1fe3
Showing
9 changed files
with
157 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//This knexfile is just used for migrations. The actual | ||
//db object is built in ./src/db/db and is used throughout the app. | ||
|
||
require('dotenv').config(); | ||
|
||
module.exports = { | ||
|
||
client: 'mysql', | ||
connection: { | ||
host: process.env.DB_HOST, | ||
port: process.env.DB_PORT, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_DATABASE, | ||
}, | ||
migrations: { | ||
directory: './src/db/migrations', | ||
}, | ||
seeds: { | ||
directory: './src/db/seeds/dev', | ||
}, | ||
|
||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const faker = require('faker'); | ||
|
||
exports.seed = async function(knex, Promise) { | ||
|
||
//Make 100 notes for 10 different users | ||
let seedData = []; | ||
for (let i = 0; i < 100; i++) { | ||
let testNote = { | ||
userId: faker.random.number({min: 1, max: 10}), | ||
title: faker.lorem.sentence(), | ||
content: faker.lorem.sentences(Math.floor(Math.random() * 10) + 1) | ||
} | ||
seedData.push(testNote) | ||
} | ||
|
||
// Deletes ALL existing entries | ||
await knex('notes').truncate() | ||
|
||
//Insert users | ||
await knex('notes').insert(seedData); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const faker = require('faker'); | ||
const bcrypt = require('bcrypt'); | ||
|
||
exports.seed = async function(knex, Promise) { | ||
|
||
//Make 10 users using faker. Note: we're also bcrypting | ||
//the passwords to make it exactly like the real app. All their | ||
//passwords will be 'secret' | ||
let seedData = []; | ||
for (let i = 0; i < 10; i++) { | ||
let password = 'secret' | ||
try { | ||
password = await bcrypt.hash(password, 12) | ||
} catch (error) { | ||
throw new Error('PASSWORD_ENCRIPTION_ERROR') | ||
} | ||
|
||
let testUser = { | ||
token: faker.internet.password(), | ||
firstName: faker.name.firstName(), | ||
lastName: faker.name.lastName(), | ||
username: faker.internet.userName(), | ||
email: faker.internet.email(), | ||
password: password, | ||
} | ||
seedData.push(testUser) | ||
} | ||
|
||
// Deletes ALL existing entries | ||
await knex('users').truncate() | ||
|
||
//Insert users | ||
await knex('users').insert(seedData); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters