This repository has been archived by the owner on Feb 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
knexfile.js
90 lines (76 loc) · 2.79 KB
/
knexfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
DATABASE CONFIGURATION
A. Creating a New Database
1. Install/Verify PostGreSql
Navigate to your root directory.
in terminal run 'postgres' -> if nothing happens then postgres is not installed.
run 'brew install postgres' to install postgres
2. Initialize Database System
Navigate to your root directory.
in terminal run 'initdb db/' -> a folder of 'db/' should be in the directory.
find your .gitignore file and add description (ie ## ignore db files) and add 'db/'
B. Starting The Database
1. Connecting Postgres and the Database
in terminal run 'postgres -D db/'
2. Creating a Table
in a NEW terminal window run 'createdb development' -> creates a database named development.
C. Creating Migrations
in terminal run 'knex migrate:make <optional filename>' -> 'migrations/' in the directory
************************************
DATABASE SEEDING for development
To seed the database with data so that model operations can be tested
run the ^^above^^ database setup steps with the following additions:
> 'npm install -g knex' to access knex on the command line
> Now we need to build the database structure we've defined onto the database.
We run a schema file that to do so. Once it's done, you can ctrl-C out.
> 'node lib/schema.js'
> 'knex --env development seed:run' to seed the development database
with data monsters!
To verify that you've been successful we should check the database.
> 'psql development' to open a command-line database explorer
> '\d' to look at the tables in our database.
> if 'no relations exist', you've done something wrong!
> You can run postgreSQL commands here (don't forget semi-colons!)
> 'SELECT * FROM message;'
***********************************
DATABASE CONFIGURATION for test
With a running postgres server process (postgres -D)
> 'NODE_ENV=test node lib/schema.js'
Do not seed database for tests
Before running tests, make sure to enter 'creatdb test'
*/
module.exports = {
development: {
client: 'postgresql',
connection: {
host: 'localhost',
port: 5432,
database: 'development',
},
migrations: {
directory: './migrations',
tableName: 'knex_migrations',
},
seeds: {
directory: './lib/seeders',
},
debug: false, // set true for verbose database operations
},
test: {
client: 'postgresql',
connection: {
host: 'localhost',
port: 5432,
database: 'test',
},
migrations: {
directory: './migrations',
tableName: 'knex_migrations',
},
debug: false, // set true for verbose database operations
},
production: {
client: 'postgresql',
connection: process.env.DATABASE_URL,
},
};