hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.03k stars 2.76k forks source link

Generate migration diff from CLI #8991

Open kgkg opened 1 year ago

kgkg commented 1 year ago

Is your proposal related to a problem?

We're using TypeORM to define database structure. Right now the only way to create hasura migrations is changing database structure via hasura console, so we need to define structure in both Hasura and TypeORM (which is terrible dev experience and also is prone to errors).

What we want to achive is flow like 1) update typeorm entity files 2) synchronize dev db using typeorm's sync 3) generate migrations diff with Hasura to apply migrations on stage/prod envs.

Describe the solution you'd like

The solution would be a way to generate migration as diff from currently applied migrations via command line.

It could be done with command hasura migrate diff like most ORMs do.

Describe alternatives you've considered

We could use TypeORM migratons but it will make our deployment flow much harder to perform - one server (with typeorm) would update database, while server running Hasura has to update it's metadata. It would be much easier to manage migrations with Hasura.

If the feature is approved, would you be willing to submit a PR?

Unfortunatelly I'm not familiar with implementing database diff algos.

adas98012 commented 1 year ago

You should use TypeORM migrations, as that will support your use case better. We'll work with our Documentation team to add more information on using custom migrations system with Hasura GraphQL.

munjalpatel commented 1 year ago

We also have a use case where our developers launch Hasura Console via our internal dev web portal. Because of this, Hasura migrations are not persisted to the disk. An API to get a list of all migrations or a way to generate incremental migrations using cli would be very helpful.