Boa tarde,
Eu iniciei o banco de dados Postgres com o docker-compose e estou tentando iniciar a aplicação Nestjs, mas está dando o seguinte erro:
[Nest] 24856 - 27/04/2023, 16:13:42 LOG [NestFactory] Starting Nest application...
[Nest] 24856 - 27/04/2023, 16:13:42 LOG [InstanceLoader] AppModule dependencies initialized +13ms
[Nest] 24856 - 27/04/2023, 16:13:42 LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 24856 - 27/04/2023, 16:13:42 LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 24856 - 27/04/2023, 16:13:42 LOG [InstanceLoader] ProdutoModule dependencies initialized +0ms
[Nest] 24856 - 27/04/2023, 16:13:42 LOG [InstanceLoader] UsuarioModule dependencies initialized +0ms
[Nest] 24856 - 27/04/2023, 16:13:42 LOG [InstanceLoader] ConfigModule dependencies initialized +1ms
[Nest] 24856 - 27/04/2023, 16:13:42 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
error: database "db_loja" does not exist
at Parser.parseErrorMessage (C:\Users\xxx\Cursos\Alura\nestjs\nestjs-typeorm-alura\node_modules\pg-protocol\src\parser.ts:369:69)
at Parser.handlePacket (C:\Users\xxx\Cursos\Alura\nestjs\nestjs-typeorm-alura\node_modules\pg-protocol\src\parser.ts:188:21)
at Parser.parse (C:\Users\aless\xxx\Alura\nestjs\nestjs-typeorm-alura\node_modules\pg-protocol\src\parser.ts:103:30)
at Socket.<anonymous> (C:\Users\xxx\Cursos\Alura\nestjs\nestjs-typeorm-alura\node_modules\pg-protocol\src\index.ts:7:48)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Se eu criar "na mão" o database no servidor de banco de dados, aí o Nestjs funciona, criando também as tabelas, pois o DataSource está configurado com synchronize : true
.
Há alguma forma em que o Nestjs TypeORM crie automaticamente o database caso não exista? Ou algum outro procedimento?