Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e26c54b
Author: Andrés <[email protected]>
Date:   Fri Dec 6 11:30:37 2024 +0100

    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.

commit fc68a24
Author: Andrés <[email protected]>
Date:   Fri Dec 6 11:25:33 2024 +0100

    chore: upgrade to node v22 (#748)
  • Loading branch information
rompemoldes committed Dec 6, 2024
1 parent 8fc4554 commit 9fbaaba
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Duplicate this file in the same directory and name it `.env`.
## Assign custom values for your project inside `.env`.

PORT=3000
URL=http://127.0.0.1:3000
## You need to export this variable manually to make it available for sequelize
## via `export DATABASE_URI=...` on the command line interface
# DATABASE_URI=<protocol://username:password@host:port/database>
DATABASE_URI=postgres://postgres:postgres@localhost:5432/postgres
# while using the "...kilt.io" endpoints, please add a trailing "/" so that polkadot.js displays the right colors.
BLOCKCHAIN_ENDPOINT=wss://kilt.ibp.network
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/Iron
lts/Jod
2 changes: 2 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('dotenv').config();

module.exports = {
url: process.env.DATABASE_URI,
'migrations-path': 'src/migrations',
Expand Down
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,33 @@ The database should start to populate from the configured indexer.
This project consciously did not define a `config/config.json` for sequelize.
Instead, it relies on the `url` property inside `.sequilizerc`.
In turn, the `url` takes `process.env.DATABASE_URI` as a value.
This means that `DATABASE_URI` needs to previously be set as an environment variable, sadly manually.

To be able to run any `sequelize-cli` commands, first you need to execute:

```
export DATABASE_URI=<protocol://username:password@host:port/database>
```

If you are using the default values, as created via `pnpm start-db`, it narrows it down to this:

```
export DATABASE_URI=postgres://postgres:postgres@localhost:5432/postgres
```

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

1. Start the database, if not running yet.
1. Make sure you have all dependencies installed, running:

```
pnpm install
```

2. Start the database, if not running yet.
Locally, you can run:
```
pnpm start-db
```
2. Run all past migrations, via:
3. Run all past migrations, via:

```
pnpm migrate
```

_Remember to manually set the `DATABASE_URI` first as described above._

3. Start the project to populate the database, by running:
4. Start the project to populate the database, by running:
```
pnpm dev
```
_After a while, you can stop the project, but the postgres container should continue running._
4. Add the seeds to the database:
5. Add the seeds to the database, by running:
```
pnpm seed
```
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"packageManager": "[email protected]",
"engines": {
"node": ">=20"
"node": ">=22"
},
"scripts": {
"prettify": "prettier --write \"src/**/*.astro\" \"src/**/*.ts*\" \"src/**/*.css*\"",
Expand All @@ -27,6 +27,7 @@
"@polkadot/extension-dapp": "^0.46.5",
"@polkadot/util": "^12.6.2",
"astro": "^3.6.5",
"dotenv": "^16.4.7",
"got": "^12.6.1",
"http-status-codes": "^2.3.0",
"lodash-es": "^4.17.21",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9fbaaba

Please sign in to comment.