Просмотр исходного кода

:pencil: backend | updated README | using env variables

master
TOJ 5 лет назад
Родитель
Сommit
4c863f0cb4
4 измененных файлов: 44 добавлений и 15 удалений
  1. 25
    3
      backend/README.md
  2. 9
    2
      backend/server/.env.sample
  3. 8
    8
      backend/server/manifest.js
  4. 2
    2
      docker-compose.yml

+ 25
- 3
backend/README.md Просмотреть файл

14
 ## :package: Installation
14
 ## :package: Installation
15
 
15
 
16
 1. Install dependencies with `npm install`
16
 1. Install dependencies with `npm install`
17
-2. Fill out your database connection details in `./config/dev.js`
18
-3. A test database container is provided and can be started with `docker-compose up -d`
19
-4. Populate some basic tables for your database using `npx knex migrate:latest`
17
+2. Copy the environments sample file from `./server/.env.sample` and rename it to `./server/.env`
18
+3. Fill out your database connection details in `./server/.env`
19
+4. A test database container is provided and can be started with `docker-compose --env-file ./backend/server/.env up -d`
20
+5. Populate some basic tables for your database using `npx knex migrate:latest`
21
+
22
+## :package: Migrations
23
+
24
+We use Knex.js,which comes with a couple nice database migration and seeding tools.
25
+Migrating tracks changes in schema. Migration steps are contained in the `./db/migrations` folder. Seeding adds dummy data once our database tables have been created and schemas are set. Starting seed steps are contained in `./db/seeds` and use the `mock.js` file as the main dummy data source.
26
+
27
+### Migrating
28
+* Run `npm run migrate` to run all migrations and establish the base schema
29
+* Run `npm run unmigrate` to roll back one migration
30
+
31
+### Seeding
32
+* Run `npm run seed` to seed the database with dummy data
33
+
34
+### Restarting
35
+Since we can't unseed the database, it's best to destroy the `dev` database and rebuild it.
36
+
37
+1. Stop the database by navigating to the project root directory `cd ../` and running `docker-compose down`
38
+2. Destroy the database volume `docker volume rm siimee_db`. BE CAREFUL.
39
+3. Restart the database while still at the project root with `docker-compose --env-file ./backend/server/.env up -d`
40
+4. Recreate schemas and tables but navigating to `./backend` and running `npm run migrate`
41
+5. Reseed the dummy data with `npm run seed`
20
 
42
 
21
 ## :electric_plug: Run
43
 ## :electric_plug: Run
22
 
44
 

+ 9
- 2
backend/server/.env.sample Просмотреть файл

3
 # Confused? See https://github.com/motdotla/dotenv
3
 # Confused? See https://github.com/motdotla/dotenv
4
 #
4
 #
5
 # e.g.
5
 # e.g.
6
-# PORT=4000
7
-APP_SECRET=mysecret
6
+API_HOST=localhost
7
+API_PORT=3001
8
+APP_SECRET=mysecret
9
+
10
+DB_ROOT_PASSWORD=root
11
+DB_USER=root
12
+DB_NAME=test
13
+DB_HOST=localhost
14
+DB_TYPE=mysql

+ 8
- 8
backend/server/manifest.js Просмотреть файл

11
 // Glue manifest as a confidence store
11
 // Glue manifest as a confidence store
12
 module.exports = new Confidence.Store({
12
 module.exports = new Confidence.Store({
13
     server: {
13
     server: {
14
-        host: 'localhost',
14
+        host: process.env.API_HOST,
15
         port: {
15
         port: {
16
             $filter: 'NODE_ENV',
16
             $filter: 'NODE_ENV',
17
             $default: {
17
             $default: {
18
-                $param: 'PORT',
18
+                $param: 'API_PORT',
19
                 $coerce: 'number',
19
                 $coerce: 'number',
20
-                $default: 3001
20
+                $default: process.env.API_PORT
21
             },
21
             },
22
             test: { $value: undefined }         // Let the server find an open port
22
             test: { $value: undefined }         // Let the server find an open port
23
         },
23
         },
69
                     $base: {
69
                     $base: {
70
                         migrateOnStart: true,
70
                         migrateOnStart: true,
71
                         knex: {
71
                         knex: {
72
-                            client: 'mysql',
72
+                            client: process.env.DB_TYPE,
73
                             useNullAsDefault: true,
73
                             useNullAsDefault: true,
74
                             connection: {
74
                             connection: {
75
-                                host : 'localhost',
76
-                                user : 'root',
77
-                                password : 'root',
78
-                                database : 'test'
75
+                                host : process.env.DB_HOST,
76
+                                user : process.env.DB_USER,
77
+                                password : process.env.DB_ROOT_PASSWORD,
78
+                                database : process.env.DB_NAME
79
                             }
79
                             }
80
                         }
80
                         }
81
                     },
81
                     },

+ 2
- 2
docker-compose.yml Просмотреть файл

7
         volumes:
7
         volumes:
8
           - siimee_db:/var/lib/mysql
8
           - siimee_db:/var/lib/mysql
9
         environment:
9
         environment:
10
-          MYSQL_ROOT_PASSWORD: root
11
-          MYSQL_DATABASE: test
10
+          MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
11
+          MYSQL_DATABASE: "${DB_NAME}"
12
         ports:
12
         ports:
13
           - '3306:3306'
13
           - '3306:3306'
14
 
14
 

Загрузка…
Отмена
Сохранить