Skip to content

Commit 6f4426e

Browse files
fersirnirubenguc
andauthored
Migrate to mongodb (#15)
* migrate to mongo * fix * fix entities * fix queries * Change tip data type to string * fix db init * fix docker compose file * change ssl * mongo indexes * fix indexes * fxi tests * fix sh * add mongo-express * fix indexes * fixes * minor details * fix tests * readme * readme details * Update package.json * Update README-es.md * Update README.md * Update app.resolver.ts * Update app.resolver.spec.ts Co-authored-by: Ruben Gutierrez <rubdeivis@gmail.com>
1 parent d2c2d47 commit 6f4426e

27 files changed

+1480
-405
lines changed

.env.sample

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NODE_ENV=production
2-
PORT=5000
2+
PORT=8080
33
LOG_NAME=ink-substrate-explorer-api
44
LOG_LEVEL=debug
55

@@ -8,11 +8,11 @@ GRAPHQL_PLAYGROUND=true
88
GRAPHQL_SORT_SCHEMA=true
99
GRAPHQL_INTROSPECTION=true
1010

11-
DATABASE_HOST=postgres
11+
DATABASE_HOST=mongo
1212
DATABASE_NAME=ink
13-
DATABASE_USERNAME=root
14-
DATABASE_PASSWORD=password
15-
DATABASE_PORT=5432
13+
DATABASE_USERNAME=mongodb
14+
DATABASE_PASSWORD=mongodb
15+
DATABASE_PORT=27017
1616
DATABASE_SSL_CA=""
1717
DATABASE_RETRY_ATTEMPTS=5
1818
DATABASE_RETRY_DELAY=3000

README-es.md

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Ink! Explorer API
1515

1616
## **Acerca del explorador**
1717

18-
Ink Explorer es una aplicacion que provee informacion relativa a los contratos que utilizan Ink! en blockchains basadas en Substrate. Se suscribe a la blockchain y a los eventos emitidos por los modulos de Ink! y guarda la informacion en su propia base de datos PostgreSQL. El back-end expone una API que puede interactuar con la base de datos y ejecutar consultas rapidas para obtener informacion especifica en poco tiempo.
18+
Ink Explorer es una aplicacion que provee informacion relativa a los contratos que utilizan Ink! en blockchains basadas en Substrate. Se suscribe a la blockchain y a los eventos emitidos por los modulos de Ink! y guarda la informacion en su propia base de datos. El back-end expone una API que puede interactuar con la base de datos y ejecutar consultas rapidas para obtener informacion especifica en poco tiempo.
1919

2020
La idea de este proyecto es brindar una herramienta que permita a los desarrolladores de Ink! explorar y analizar los contratos que se encuentran en blockchain. Esta herramienta se puede utilizar para analizar los contratos que se encuentran en blockchains basadas en Substrate que utilizan módulos Ink!. También se puede usar para analizar contratos que están en una blockchain local.
2121

@@ -40,7 +40,7 @@ pnpm i --frozen-lockfile
4040

4141
### Configurar las variables de entorno
4242

43-
**Nota**: El archivo .env tiene la configuracion para GraphQL, la base de datos PostgreSQL, Node y la url del RPC de la blockchain basada en Substrate.
43+
**Nota**: El archivo .env tiene la configuracion para GraphQL, la base de datos Mongo, Node y la url del RPC de la blockchain basada en Substrate.
4444

4545
```sh
4646
cp .env.sample .env
@@ -67,10 +67,10 @@ GRAPHQL_INTROSPECTION=true
6767
#### Configuraciones de la base de datos
6868

6969
```sh
70-
DATABASE_HOST=postgres
70+
DATABASE_HOST=mongo
7171
DATABASE_NAME=ink
72-
DATABASE_USERNAME=root
73-
DATABASE_PASSWORD=password
72+
DATABASE_USERNAME=mongodb
73+
DATABASE_PASSWORD=mongodb
7474
DATABASE_RETRY_ATTEMPTS=5
7575
DATABASE_RETRY_DELAY=3000
7676
```
@@ -89,37 +89,16 @@ BLOCK_CONCURRENCY=1000
8989

9090
## **Levantando el servicio (DEV)**
9191

92-
### Instanciar una BD Postgres utilizando docker (opcional)
92+
### Instanciar una BD Mongo utilizando docker (opcional)
9393

94-
Para levantar el servicio es necesario contar con una **BD PostgreSQL**. Para esto, el archivo **dev-docker-compose.yaml** ya tiene una imagen configurada lista para usar.
95-
Ejecutando el siguiente comando tambien instanciara un contenedor para pgAdmin:
94+
Para levantar el servicio es necesario contar con una **BD Mongo**. Para esto, el archivo **dev-docker-compose.yaml** ya tiene una imagen configurada lista para usar.
95+
Ejecutando el siguiente comando tambien instanciara un contenedor para Mongo Express:
9696

9797
```sh
9898
docker-compose -f dev-docker-compose.yaml up -d
9999
```
100100

101-
Una vez que el servicio se está ejecutando, se puede acceder a pgAdmin siguiendo el enlace que se muestra en la terminal (en este caso localhost:80).
102-
103-
![pgAdmin](/.images/pg_admin_up.png)
104-
105-
Las credenciales para acceder a pgAdmin son (establecidas en el archivo dev-docker-compose):
106-
107-
- PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
108-
- PGADMIN_DEFAULT_PASSWORD: "admin"
109-
110-
Registre un nuevo servidor en pgAdmin y establezca las credenciales para la base de datos PostgreSQL:
111-
112-
Haga clic derecho en 'Servidores' y seleccione "Registrarse" -> "Servidor"
113-
114-
![pgAdmin](/.images/pg_admin_select_server.png)
115-
116-
Establezca un nombre para el servidor (en este ejemplo, "Docker")
117-
118-
![pgAdmin](/.images/pg_admin_server_name.png)
119-
120-
Establezca las credenciales para la base de datos PostgreSQL (esto se puede encontrar en el archivo dev-docker-compose):
121-
122-
![pgAdmin](/.images/pg_admin_connection.png)
101+
Una vez que el servicio se está ejecutando, se puede acceder a Mongo Express siguiendo el enlace que se muestra en la terminal (en este caso localhost:8081).
123102

124103
### Instanciar un nodo local de Substrate (opcional)
125104

@@ -143,17 +122,17 @@ pnpm start:dev
143122
Ejecuta el servicio en el modo de desarrollo.
144123
El servicio se recargará si realiza ediciones.
145124

146-
**Nota**: Se requiere una base de datos postgres en funcionamiento y una conexión válida a un nodo de Substrate.
125+
**Nota**: Se requiere una base de datos Mongo en funcionamiento y una conexión válida a un nodo de Substrate.
147126

148127
## **Levantando el servicio (PROD)**
149128

150-
Para iniciar los contenedores del servicio de backend, la BD y pgAdmin ejecutar el siguiente comando:
129+
Para iniciar los contenedores del servicio de backend, la BD y Mongo Express ejecutar el siguiente comando:
151130

152131
```sh
153132
docker-compose up -d
154133
```
155134

156-
**Nota**: Se requiere una base de datos postgres en funcionamiento y una conexión válida a un nodo de Substrate.
135+
**Nota**: Se requiere una base de datos Mongo en funcionamiento y una conexión válida a un nodo de Substrate.
157136
Opcionalmente, comente el servicio de back-end en el archivo docker-compose si desea ejecutar la imagen localmente.
158137

159138
## Ejecutar la imagen de Docker del servicio back-end
@@ -250,7 +229,7 @@ query {
250229
```graphql
251230
{
252231
"data": {
253-
"version": "v1.0.5"
232+
"version": "v1.1.0"
254233
}
255234
}
256235
```
@@ -394,7 +373,7 @@ query {
394373
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
395374
"ss58": "42",
396375
"timestamp": 1666888006111,
397-
"tip": 0,
376+
"tip": "0",
398377
"tokens": "Unit",
399378
"type": 4,
400379
"version": 132
@@ -464,7 +443,7 @@ query {
464443
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
465444
"ss58": "42",
466445
"timestamp": 1666888006111,
467-
"tip": 0,
446+
"tip": "0",
468447
"tokens": "Unit",
469448
"type": 4,
470449
"version": 132
@@ -526,7 +505,7 @@ query {
526505
"signer": "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
527506
"ss58": "42",
528507
"timestamp": 1666888006111,
529-
"tip": 0,
508+
"tip": "0",
530509
"tokens": "Unit",
531510
"type": 4,
532511
"version": 4

README.md

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Ink! Explorer API
1515

1616
## **About the explorer**
1717

18-
Ink Explorer is an application that provides Ink contracts related information on Substrate based blockchains. It subscribes to blockchain and Ink modules events and store the information on its own PostgreSQL database. The backend exposes an API that can interact with the DB and run fast queries to get specific information in a short time.
18+
Ink Explorer is an application that provides Ink contracts related information on Substrate based blockchains. It subscribes to blockchain and Ink modules events and store the information on its own database. The backend exposes an API that can interact with the DB and run fast queries to get specific information in a short time.
1919

2020
The idea of this project is to provide a tool that allows developers of Ink! explore and analyze the contracts found on the blockchain. This tool can be used to analyze the contracts found on Substrate based blockchains that are using Ink! modules. It can also be used to analyze contracts that are on a local blockchain.
2121

@@ -40,7 +40,7 @@ pnpm i --frozen-lockfile
4040

4141
### Configure the environment variables
4242

43-
**Note**: The .env file has the configuration for GraphQL, the PostgreSQL database, Node and the RPC url of the Substrate Blockchain.
43+
**Note**: The .env file has the configuration for GraphQL, the Mongo database, Node and the RPC url of the Substrate Blockchain.
4444

4545
```sh
4646
cp .env.sample .env
@@ -67,10 +67,10 @@ GRAPHQL_INTROSPECTION=true
6767
#### Database configurations
6868

6969
```sh
70-
DATABASE_HOST=postgres
70+
DATABASE_HOST=mongo
7171
DATABASE_NAME=ink
72-
DATABASE_USERNAME=root
73-
DATABASE_PASSWORD=password
72+
DATABASE_USERNAME=mongodb
73+
DATABASE_PASSWORD=mongodb
7474
DATABASE_RETRY_ATTEMPTS=5
7575
DATABASE_RETRY_DELAY=3000
7676
```
@@ -89,37 +89,16 @@ BLOCK_CONCURRENCY=1000
8989

9090
## **Starting the project (DEV)**
9191

92-
### Start a Postgres DB using docker (optional)
92+
### Start a Mongo DB using docker (optional)
9393

94-
To start the project a **PostgreSQL DB** is needed. For that, the **dev-docker-compose.yaml** file already has an image set up ready to use.
95-
Running this command it will also start a container for pgAdmin:
94+
To start the project a **Mongo DB** is needed. For that, the **dev-docker-compose.yaml** file already has an image set up ready to use.
95+
Running this command it will also start a container for Mongo Express:
9696

9797
```sh
9898
docker-compose -f dev-docker-compose.yaml up -d
9999
```
100100

101-
Once the service is running, pgAdmin can be accessed following the link that is shown in the terminal (In this case localhost:80).
102-
103-
![pgAdmin](/.images/pg_admin_up.png)
104-
105-
The credentials to access pgAdmin are (set in the dev-docker-compose file):
106-
107-
- PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
108-
- PGADMIN_DEFAULT_PASSWORD: "admin"
109-
110-
Register a new server in pgAdmin and set the credentials for the PostgreSQL DB:
111-
112-
Right click on 'Servers' and select "Register" -> "Server"
113-
114-
![pgAdmin](/.images/pg_admin_select_server.png)
115-
116-
Set a name for the server (In this example "Docker")
117-
118-
![pgAdmin](/.images/pg_admin_server_name.png)
119-
120-
Set the credentials for the PostgreSQL DB (this can be found in the dev-docker-compose file):
121-
122-
![pgAdmin](/.images/pg_admin_connection.png)
101+
Once the service is running, Mongo Express can be accessed following the link that is shown in the terminal (In this case localhost:8081).
123102

124103
### Start a local Substrate Node (optional)
125104

@@ -143,17 +122,17 @@ pnpm start:dev
143122
Runs the service in the development mode.
144123
The service will reload if you make edits.
145124

146-
**Note**: A postgresDB up and running and a valid connection to a substrate node are required.
125+
**Note**: A Mongo DB up and running and a valid connection to a substrate node are required.
147126

148127
## **Starting the project (PROD)**
149128

150-
To start the backend service, DB and pgAdmin containers run the following command:
129+
To start the backend service, Mongo DB and Mongo Express containers run the following command:
151130

152131
```sh
153132
docker-compose up -d
154133
```
155134

156-
**Note**: A postgresDB up and running and a valid connection to a substrate node are required.
135+
**Note**: A Mongo DB up and running and a valid connection to a substrate node are required.
157136
Optionally comment the backend service in the docker-compose file if you want to run the image locally.
158137

159138
## Running the Back-end service Docker image
@@ -250,7 +229,7 @@ query {
250229
```graphql
251230
{
252231
"data": {
253-
"version": "v1.0.5"
232+
"version": "v1.1.0"
254233
}
255234
}
256235
```
@@ -394,7 +373,7 @@ query {
394373
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
395374
"ss58": "42",
396375
"timestamp": 1666888006111,
397-
"tip": 0,
376+
"tip": "0",
398377
"tokens": "Unit",
399378
"type": 4,
400379
"version": 132
@@ -464,7 +443,7 @@ query {
464443
"signer": "5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc",
465444
"ss58": "42",
466445
"timestamp": 1666888006111,
467-
"tip": 0,
446+
"tip": "0",
468447
"tokens": "Unit",
469448
"type": 4,
470449
"version": 132
@@ -526,7 +505,7 @@ query {
526505
"signer": "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM",
527506
"ss58": "42",
528507
"timestamp": 1666888006111,
529-
"tip": 0,
508+
"tip": "0",
530509
"tokens": "Unit",
531510
"type": 4,
532511
"version": 4

dev-docker-compose.yaml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
version: '3.7'
22
services:
3-
postgres:
4-
image: postgres:14.4
3+
mongo:
4+
image: mongo:latest
5+
environment:
6+
- MONGO_INITDB_ROOT_USERNAME=root
7+
- MONGO_INITDB_ROOT_PASSWORD=root
8+
- MONGO_INITDB_DATABASE=ink
9+
- MONGO_INITDB_USER=mongodb
10+
- MONGO_INITDB_PWD=mongodb
11+
ports:
12+
- '27017:27017'
13+
volumes:
14+
- ./initdb.d/:/docker-entrypoint-initdb.d/
15+
mongo-express:
16+
image: mongo-express
517
restart: always
618
ports:
7-
- 5432:5432
19+
- 8081:8081
820
environment:
9-
- POSTGRES_USER=root
10-
- POSTGRES_PASSWORD=password
11-
- POSTGRES_DB=ink
21+
ME_CONFIG_MONGODB_ADMINUSERNAME: root
22+
ME_CONFIG_MONGODB_ADMINPASSWORD: example
23+
ME_CONFIG_MONGODB_URL: mongodb://root:root@mongo:27017
1224
substrate:
1325
image: blockcoders/substrate-contracts-node
1426
restart: on-failure
1527
ports:
1628
- 9944:9944
17-
command: '--dev --ws-external'
18-
pgadmin:
19-
image: dpage/pgadmin4
20-
environment:
21-
PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
22-
PGADMIN_DEFAULT_PASSWORD: "admin"
23-
ports:
24-
- 80:80
25-
depends_on:
26-
- postgres
29+
command: '--dev --ws-external'

docker-compose.yaml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
#image: blockcoders/ink-substrate-explorer-api:latest
1111
restart: on-failure
1212
depends_on:
13-
- postgres
13+
- mongo
1414
build:
1515
context: .
1616
# dockerfile: dev.Dockerfile
@@ -27,29 +27,34 @@ services:
2727
ink-explorer-network:
2828
aliases:
2929
- "backend"
30-
postgres:
31-
image: postgres:14.4
32-
restart: always
33-
ports:
34-
- 5432:5432
30+
mongo:
31+
image: mongo:latest
3532
environment:
36-
- POSTGRES_USER=root
37-
- POSTGRES_PASSWORD=password
38-
- POSTGRES_DB=ink
33+
- MONGO_INITDB_ROOT_USERNAME=root
34+
- MONGO_INITDB_ROOT_PASSWORD=root
35+
- MONGO_INITDB_DATABASE=ink
36+
- MONGO_INITDB_USER=mongodb
37+
- MONGO_INITDB_PWD=mongodb
38+
ports:
39+
- '27017:27017'
40+
volumes:
41+
- ./initdb.d/:/docker-entrypoint-initdb.d/
3942
networks:
4043
ink-explorer-network:
4144
aliases:
42-
- "postgres"
43-
pgadmin:
44-
image: dpage/pgadmin4
45-
environment:
46-
PGADMIN_DEFAULT_EMAIL: "admin@admin.com"
47-
PGADMIN_DEFAULT_PASSWORD: "admin"
48-
ports:
49-
- 80:80
45+
- "mongo"
46+
mongo-express:
47+
image: mongo-express
48+
restart: always
5049
depends_on:
51-
- postgres
50+
- mongo
51+
ports:
52+
- 8081:8081
53+
environment:
54+
ME_CONFIG_MONGODB_ADMINUSERNAME: root
55+
ME_CONFIG_MONGODB_ADMINPASSWORD: example
56+
ME_CONFIG_MONGODB_URL: mongodb://root:root@mongo:27017
5257
networks:
5358
ink-explorer-network:
5459
aliases:
55-
- "pgadmin"
60+
- "mongo-express"

0 commit comments

Comments
 (0)