Auto-apply Migration problems
See original GitHub issueI am facing two issues both related to applying migrations to the database. I have initialized Hasura using docker to a pre-existing project and Postgres database. I used the Hasura CLI to initialize the migrations and metadata files within a sub-directory of my project. Here are the two problems I am facing:
(1) Auto-applying migration scripts is not working
- I am following this guide: https://hasura.io/docs/1.0/graphql/core/migrations/advanced/auto-apply-migrations.html#auto-apply-migrations to set up auto-applying upon starting the Docker container.
- I have followed the steps in the ‘Applying migrations’ section where I have tried both setting the migration and metadata env variables as well as trying
-v. - I am also using the
hasura/graphql-engine:v1.3.2.cli-migrations-v2image. - I try setting the directory for the env variable in the script to something like this:
-e HASURA_GRAPHQL_MIGRATIONS_DIR=/Users/<name>/Desktop/<app>/db/hasura-migrations/migrations. - I even tried putting the bash script next to the migrations folder and just using
./migrationsas the path. - In both cases, I get the following error in my Docker log:
{"kind":"migrations-apply", "info":"directory /Users/<name>/Desktop/<app>/db/hasura-migrations/migrations does not exist, skipping migrations"}} - I have repeatedly verified that the directory is accurate, but I continue to get the same error saying the directory does not exist, and subsequently skips the migration apply. I am also unsure if this is a Docker or Hasura related error I am making, so I apologize if this error is not caused by Hasura.
(2) hasura migrate status is misleading
- I have been testing the migration scripts to see if they work by regressing my database such that some metadata inconsistency exists when I run
hasura console. - The console correctly gives the inconsistency error, but when I go to verify this using
hasura migrate status, theDATABASE STATUScolumn readsPRESENTfor all migration files which should be in theory not present, since they are not in the database. - As a result of this, running
hasura applysimply returnsnothing to apply. - I have actually tried manually running all of the
up.sqlmigration files against the database and everything works,hasura metadata applythen works, and everything is all good, it’s just that it won’t work automatically through the cli.
Overall, I am facing such challenges in automating the migration/metadata application process and would appreciate any help. Apologies once more if this is not the right place to post these, I had tried reaching out to a representative over the Hasura website, but have gotten little to no response.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
EntityFramework Core automatic migrations - Stack Overflow
When the model changes a lot and and multiple people work on the same project, migrations leads more problems than solutions. Moreover, having...
Read more >Automated Migration in Entity Framework 6
Learn how to implement automated migration in Entity Framework 6.x using enable-migrations command.
Read more >Migrations & Metadata Setup | Hasura GraphQL Docs
The following command will squash all migration files from the given migration to the latest migration into a single migration file. hasura migrate...
Read more >Recovery components | Microsoft Learn
Auto-Apply folders · Capturing Windows desktop applications using Windows User State Migration Tool (USMT)'s ScanState tool · Restoring settings ...
Read more >6.0 Migration Guide - JBoss.org
This guide discusses migration from Hibernate ORM version 6.0. ... Allows to "auto apply" a UserCollectionType whenever Hibernate encounters ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey man, do you remember what path was missing? I am having the same issue now, it is saying 'INFO nothing to apply on database default ’ whereas the metadata does work.
So, the way that Docker containers work is that they are self-contained. The filesystem on a Docker image is not connected to your host filesystem (unless you use a bind-mount).
Inside of your Docker image,
/Users/<name>/Desktop/<app>/db/hasura-migrations/migrationsdoes not exist, unless in your Dockerfile you have something like this:So what you need to do is put the
metadataandmigrationsfolder into the built container image. You can do this with:Assuming that this
Dockerfileexists in the same directory as yourmetadataandmigrationsfolder.The other thing you can do in local development if you don’t want to write a custom Dockerfile, is to mount your
migrationsandmetadataimages from your host into the container directories:The reason why this works is because of this:
You are mounting the local directory
./migrationsinto the container directory/hasura-migrations.Hope that answers your questions and clears things up 👍
When you run a migration against a Hasura instance, it makes an entry in the DB it’s connected to that the migration has been successfully applied on it.
hasura migrate statusessentially just checks the list of migrations against what the database has had run on it before.How are you “regressing the database” to break this? Are you deleting tables without tracking the deletions with migrations?
If you don’t track all changes ever made, Hasura’s migrations and metadata management become useless because there’s a “break” in the history. You need to manually fix it if this happens.