How to properly setup an architecture for working with Hasura metadata in different branches?

254 views Asked by At

Hasura has a great system of incremental migrations of database schema.

You set it up, create a new branch, launch console from cli, do your changes and get a bunch of migration files. Add those files to git, merge them with master, when you are ready and do 'migrate apply ...' to apply those changes to production DB.

Now, with metadata it does not work this way. Every time you launch hasura cli and do anything worth tracking - metadata file will updated.

Here is an example of the problem I am facing. There are two similar databases (hasura installations) - PROD and DEV.

I create to branches from master - branch A and branch B. Both will be working with DEV database. I start working on branch A, add some tables, add some permissions and relations. I end up with a bunch of migrations and metadata file that contains setup that was in master + my changes. When I finish with the branch, potentially I should do 'hasura migrate apply' & 'hasura metadata apply' and all changes will be moved to prod database.

My friend start working on a branch B, add some tables, add some permissions and relations. He end up with a bunch of migrations and metadata file that contains setup that was in master + his changes + my changes. So when he finishes with the branch, 'hasura migrate apply' will add all the stuff that he wants, but 'hasura metadata apply' will throw and error, because some of the clauses in it will be based on tables that where never migrated (tables created in branch A).

How should I sync metadata?

1

There are 1 answers

4
lokesh kumar On

Both of you are working on DEV, you do not need to do 'hasura migrate apply' etc. The changes you are doing are already done on DEV. When you are done with your changes merge to PROD branch and then do the migrations and applying metadata on PROD. These are to replicate the changes done on DEV to PROD.