1 | <h1 align="center">
|
2 | <br>
|
3 | <a href="https://www.energyweb.org/"><img src="https://www.energyweb.org/wp-content/uploads/2019/04/logo-brand.png" alt="EnergyWeb" width="150"></a>
|
4 | <br>
|
5 | EnergyWeb Origin
|
6 | <br>
|
7 | <h2 align="center">Origin-Backend</h2>
|
8 | <br>
|
9 | </h1>
|
10 |
|
11 | **Origin-Backend** package provides the API for managing users, certificate, requests and devices in the Origin project.
|
12 |
|
13 | ## Development
|
14 |
|
15 | Origin-backend project is currently not meant to be run as a separate nest application. In order to run origin-backend project please refer to https://github.com/energywebfoundation/origin/tree/master/packages/origin-backend-app
|
16 |
|
17 | Default TypeOrm configuration requires running PostgreSQL database. The detailed config with .env parameters is:
|
18 |
|
19 | ```
|
20 | DB_HOST - default 'localhost'
|
21 | DB_PORT - default 5432
|
22 | DB_USERNAME - default 'postgres',
|
23 | DB_PASSWORD - default 'postgres',
|
24 | DB_DATABASE - default 'origin',
|
25 | ```
|
26 |
|
27 | or
|
28 |
|
29 | ```
|
30 | DATABASE_URL - postgres://{user}:{password}@{host}:{port}/{database}
|
31 | ```
|
32 |
|
33 | ### Using TypeORM migrations
|
34 |
|
35 | Exchange project uses TypeORM mechanism to perform SQL data migrations. For detailed information please refer to https://github.com/typeorm/typeorm/blob/master/docs/migrations.md
|
36 |
|
37 | - `yarn typeorm:run` to update DB to latest exchange tables schema
|
38 | - `yarn typeorm:migrate SampleMigrationName` to create new migration file based on the changes in the code entities
|
39 |
|
40 | Development flow:
|
41 |
|
42 | - run `yarn typeorm:run` - to apply latest migrations
|
43 | - apply changes in the entities, like change the variable name or type
|
44 | - run `yarn typeorm:migrate LastestChanges...`
|
45 | - inspect newly created migration in /migrations folder
|
46 | - run `yarn typeorm:run` to apply newly created migration
|
47 |
|
48 | **Warning:**
|
49 |
|
50 | **Existing migration files from `/migration` folder should never be edited after being committed.**
|
51 |
|
52 | ### PostgreSQL installation using Docker
|
53 |
|
54 | ```
|
55 | docker pull postgres
|
56 | docker run --name origin-postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres
|
57 | ```
|
58 |
|
59 | #### pgAdmin
|
60 |
|
61 | ```
|
62 | docker pull dpage/pgadmin4
|
63 | docker run -p 80:80 \
|
64 | -e 'PGADMIN_DEFAULT_EMAIL=user@domain.com' \
|
65 | -e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
|
66 | -d dpage/pgadmin4
|
67 | ```
|