hasura / hasura/graphql-engine
Migrations-image fails to start up if a database-specific migrations-dir is missing
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: v2.3.0 (Docker image hasura/graphql-engine:v2.3.0.cli-migrations-v3)
CLI Version (for CLI related issue):
### Environment
Startup fails in local docker-compose, as well as when running in Azure app service (container)
### What is the expected behaviour?
In version 2.0.10 the problem was logged and ignored. 2.3.0 fails and the server refuses to start. The earlier behavior seems to be the correct one.
### Keywords
Migrations
Docker
### What is the current behaviour?
Startup fails with the current error message:
```
2022-03-10T19:18:22.565287419Z {"level":"info","msg":"getting lists of databases from server ","time":"2022-03-10T19:18:22Z"}
2022-03-10T19:18:22.609334334Z {"level":"error","msg":"skipping applying migrations on database THE_DATABASE, encountered: \nexpected to find a migrations directory for database THE_DATABASE in /tmp/hasura-project/migrations, but encountered error: stat /tmp/hasura-project/migrations/THE_DATABASE: no such file or directory","time":"2022-03-10T19:18:22Z"}
2022-03-10T19:18:22.690895543Z time="2022-03-10T19:18:22Z" level=fatal msg="operation failed on : THE_DATABASE"
```
### How to reproduce the issue?
1. Using the docker-compose example from [here](https://github.com/hasura/graphql-engine/blob/stable/install-manifests/docker-compose/docker-compose.yaml)
2. Create an empty directory `mkdir empty-dir`
3. Create some metadata for any (named) database
4. Change the docker-compose to mount the empty dir
```yaml
services:
graphql-engine:
volumes:
- type: bind
source: ./empty-dir
target: /hasura-migrations
```
5. Start up the service. 👉 the start up fails with the error from above.
### Screenshots or Screencast
### Please provide any traces or logs that could help here.
```
2022-03-10T19:18:22.565287419Z {"level":"info","msg":"getting lists of databases from server ","time":"2022-03-10T19:18:22Z"}
2022-03-10T19:18:22.609334334Z {"level":"error","msg":"skipping applying migrations on database THE_DATABASE, encountered: \nexpected to find a migrations directory for database THE_DATABASE in /tmp/hasura-project/migrations, but encountered error: stat /tmp/hasura-project/migrations/THE_DATABASE: no such file or directory","time":"2022-03-10T19:18:22Z"}
2022-03-10T19:18:22.690895543Z time="2022-03-10T19:18:22Z" level=fatal msg="operation failed on : THE_DATABASE"
```
### Any possible solutions?
Workaround:
I created an inherited image with the following snippet to force the creation of the relevant directories in migrations:
```bash
FROM hasura/graphql-engine:v2.3.0.cli-migrations-v3
COPY ./hasura-metadata /hasura-metadata
COPY ./hasura-migrations /hasura-migrations
RUN find /hasura-metadata/databases -maxdepth 1 -mindepth 1 -type d | xargs basename | xargs -I {} mkdir -p /hasura-migrations/{}
```
### Can you identify the location in the source code where the problem exists?
The failing migration is called here: https://github.com/hasura/graphql-engine/blob/master/cli/commands/migrate_apply.go#L268
### If the bug is confirmed, would you be willing to submit a PR?
Yes, given I have time to find the root cause.
Contributor guide
Assessment
This issue has not been assessed yet.