Módulo para criar/migrar as relações do banco de dados do projeto PInSIS
Module to create/migrate the relations of the database of project PInSIS
Este projeto utiliza o[node-pg-migrate](https://github.com/salsita/node-pg-migrate).
This subproject utilize the[node-pg-migrate](https://github.com/salsita/node-pg-migrate).
## Exemplo de uso:
## Use example:
```bash
```bash
DATABASE_URL='postgresql://logindb:password@localhost/dbtest' npm run migrate up # Cria todos os schemas
DATABASE_URL='postgresql://logindb:password@localhost/dbtest' npm run migrate up # Create all schemas
DATABASE_URL='postgresql://logindb:password@localhost/dbtest' npm run migrate down # Cria o banco de dados
DATABASE_URL='postgresql://logindb:password@localhost/dbtest' npm run migrate down # Undo the last migration
```
```
Observe que é necessário definir uma variável de ambiente ao executar os comandos acima.
Observe that is necessary to define a env variable by the executation of the above commands.
Para uma documentação mais completa e métodos alternativos de utilizar os comandos consule[node-pg-migrate CLI Usage](https://github.com/salsita/node-pg-migrate/blob/master/docs/cli.md)
There is a documentation more complete and alternative methods to utilize the library in[node-pg-migrate CLI Usage](https://github.com/salsita/node-pg-migrate/blob/master/docs/cli.md).
## Camadas
Observe que quando os migrates ups executados no exemplo anterior passarão por todas as migrações existentes em ./migrations e criarão os modelos na ordem cronológica.
## Layers
No caso dos migrates downs, cada execução irá "descer uma camada" em relação às migrações.
Consulte a documentação original para ver métodos alternativos para simplificar o uso.
Observe that when the `migrates up`commands are executed in the previous example, all the migrations in `./migrations` will be used to create the database in cronologic order.
In case of `migrate down`commands, each execution will "down one layer" in relation of the migrations.
## Migrar o banco
You can find in the original documentation alternative methods to simplify the use.
## Migrate the database
```bash
```bash
# Esses comandos criarão modelos no diretório /migrations
# This commands will create models in the directory ./migrations
# Por questões de padronização, adotou-se que os nomes das migrações
# Because of standartion, the migrations name will use _ instead of space
# teriam espacamento substituido por _
# by instance: add_table_1
# por exemplo: add_table_1
# alter_colum_x_from_table2
# alter_colum_x_from_table2
npm run migrate create nome da migracao
Examples
npm run migrate create migration4
npm run migrate create migration5
npm run migrate create add_table_agent
npm run migrate create add_views_agentuses
```
```
## Possíveis erros
## Possible errors
-Os principais problemas encontrados estão relacionados à conexão com o DB
-The main problems verified are relationed to the database connection.
Em caso de erros verifique se é possível fazer conexão com o DB com o
In case of errors, verify if is possible do the connection with database
psql por exemplo (no mesmo usuário em que está se executando os comandos)
by `psql`command (in the same user that is in configuration file).