question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Hasura Cli export stored migration files

See original GitHub issue

I’ve accidentally deleted a particular set of migration files, and am left in a state as such:

VERSION        SOURCE STATUS  DATABASE STATUS
1562644590462  Not Present    Present

Unfortunately, there doesn’t appear to be a way to export this file from the database. I’ve found a blog describing how to reset the migrations, but exporting a particular migration seems like a common enough use case.

I would love to see an interface such as:

$ hasura migrate export <version>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
coco98commented, Aug 22, 2019

@jjangga0214 @scribahti Thanks for your detailed notes and ideas 😃

The primary issue, which is that of losing migrations can be solved by resetting all the migrations. Get the entire postgres schema and the hasura metadata.

We’ve thought about storing the migration files on hasura also, but the reason we went against that is because it creates lots of different sources of truth viz. 1) the state of the database and hasura metadata, 2) the migration files on the filesystem and the new one 3) Migrations stored on the database. Managing all 3 together and keeping them in sync becomes painful.

The current approach (inspired by rails like migrations say) is to treat the migration files that are on the filesystem like “source code” files that are either written by hand or generated by the console and then apply them to the database to modify the database state.

If one loses the migration files, it’s akin to losing source code. Also, it’s not a complete failure, because since the database has the latest state anyway, you can always reset from scratch. Ofcourse, resetting will cause loss of all the incremental changes and so on.

It seems like this is a problem that git or a version control system should solve. Exporting/importing and sharing migrations are git tasks now. This is how most migration systems behave.

@jjangga0214 @scribahti Does this make sense? The recommendation is to use git to make sure you don’t lose the migration files 😃 Would love your thoughts!

0reactions
jjangga0214commented, Aug 14, 2019

I’ve just found there is a table hdb_catalog.schema_migrations, which only has two columns version(bigint) and dirty(boolean). (By the way, what is the role of dirty? There’s no docs for hdb_catalog.schema_migrations) @scribahti and I assumed a virtual table named migrations on the above discusstion, and I think hdb_catalog.schema_migrations is actually the right table, which this issue(#2488) should be applied to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing Migrations | Hasura GraphQL Docs
Migrations are saved in a series or "versions" of Unix nanosecond timestamped ... Using the Hasura CLI, you can bootstrap these Migration files...
Read more >
Local Dev to Staging to getting Production-Ready with Hasura!
To disable Hasura's migration, you can do so via the Console served by the CLI. Head to to the Data -> Migrations tab...
Read more >
hasura metadata export | Hasura GraphQL Docs - Hasura CLI
Export Hasura GraphQL engine metadata from the database using the Hasura CLI. ... Export metadata and save it in migrations/metadata.yaml file:
Read more >
Migrations & Metadata Setup | Hasura GraphQL Docs
As you use the Hasura Console UI served by the CLI to make changes to your schema, database migration files are automatically generated...
Read more >
Moving from Self Hosted Hasura OSS to Hasura Cloud
Use pg_dump CLI tool or the PG Dump API to take a backup of your database and take a snapshot of your metadata...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found