Skip to content

Commit e26c54b

Browse files
authored
feat: simplify sequelize usage (#747)
Rely on `dotenv` to load the environment variable `DATABASE_URI` to make it available for the sequelize configuration. On this way, there is no need to export the variable value manually.
1 parent fc68a24 commit e26c54b

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
## Duplicate this file in the same directory and name it `.env`.
2+
## Assign custom values for your project inside `.env`.
3+
14
PORT=3000
25
URL=http://127.0.0.1:3000
3-
## You need to export this variable manually to make it available for sequelize
4-
## via `export DATABASE_URI=...` on the command line interface
6+
# DATABASE_URI=<protocol://username:password@host:port/database>
57
DATABASE_URI=postgres://postgres:postgres@localhost:5432/postgres
68
# while using the "...kilt.io" endpoints, please add a trailing "/" so that polkadot.js displays the right colors.
79
BLOCKCHAIN_ENDPOINT=wss://kilt.ibp.network

.sequelizerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('dotenv').config();
2+
13
module.exports = {
24
url: process.env.DATABASE_URI,
35
'migrations-path': 'src/migrations',

README.md

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,33 @@ The database should start to populate from the configured indexer.
4646
This project consciously did not define a `config/config.json` for sequelize.
4747
Instead, it relies on the `url` property inside `.sequilizerc`.
4848
In turn, the `url` takes `process.env.DATABASE_URI` as a value.
49-
This means that `DATABASE_URI` needs to previously be set as an environment variable, sadly manually.
50-
51-
To be able to run any `sequelize-cli` commands, first you need to execute:
52-
53-
```
54-
export DATABASE_URI=<protocol://username:password@host:port/database>
55-
```
56-
57-
If you are using the default values, as created via `pnpm start-db`, it narrows it down to this:
58-
59-
```
60-
export DATABASE_URI=postgres://postgres:postgres@localhost:5432/postgres
61-
```
6249

6350
**Before introducing any changes to the database structure you new to recreate the past.**
6451
**For this follow these steps:**
6552

66-
1. Start the database, if not running yet.
53+
1. Make sure you have all dependencies installed, running:
54+
55+
```
56+
pnpm install
57+
```
58+
59+
2. Start the database, if not running yet.
6760
Locally, you can run:
6861
```
6962
pnpm start-db
7063
```
71-
2. Run all past migrations, via:
64+
3. Run all past migrations, via:
7265

7366
```
7467
pnpm migrate
7568
```
7669

77-
_Remember to manually set the `DATABASE_URI` first as described above._
78-
79-
3. Start the project to populate the database, by running:
70+
4. Start the project to populate the database, by running:
8071
```
8172
pnpm dev
8273
```
8374
_After a while, you can stop the project, but the postgres container should continue running._
84-
4. Add the seeds to the database:
75+
5. Add the seeds to the database, by running:
8576
```
8677
pnpm seed
8778
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@polkadot/extension-dapp": "^0.46.5",
2828
"@polkadot/util": "^12.6.2",
2929
"astro": "^3.6.5",
30+
"dotenv": "^16.4.7",
3031
"got": "^12.6.1",
3132
"http-status-codes": "^2.3.0",
3233
"lodash-es": "^4.17.21",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)