This post was originally posted on Medium.com by Brenden Bishop
I’m not typically one for blogging, but I felt compelled to share this…
There I was — frustrated, tired, confused — all of a sudden our database hookup to Heroku was just FUBAR, gone, never to be seen again 👋. Smack in the middle of crunch-time, 10 days out from our Beta launch target date, and we just lost our whole database… 😱
What is Hasura?
Hasura is a popular open source GraphQL engine that allows developers to build and deploy scalable GraphQL APIs quickly and easily. They can use their existing database and create a GraphQL API with just a few clicks, making it an ideal solution for teams looking to automate and scale their GraphQL layer.
For those who don’t know, GraphQL is a query language for your API that was developed by Facebook as an alternative to REST APIs. It allows you to create flexible and scalable APIs where you can easily request exactly the data you need for a particular use case, rather than getting more data or having to make multiple API calls to get all the data. Also, it’s easy to update and evolve without breaking existing client applications. Since GraphQL is focused on the data rather than the endpoint, you can always add new fields or modify existing ones without affecting the way the client application accesses the data. It is particularly useful for applications that require frequent updates or for teams working on large, complex projects where the data requirements may change over time.
Now, back to Hasura… one of the standout features is its ability to allow you to define GraphQL schemas, tables, metadata, and data using code. This means that if anything goes wrong with the database, you can easily recover by simply applying the metadata, migrations, and seeds using Hasura’s command-line tools.
At Forwheel, we were using Hasura to host our dev instance and connect to a Heroku Postgres database. Then Heroku goes off and removes their free-tier model, which then appeared to delete our database!
We had just lost our Dev DB and all of its data! This was still a critical time period for feature development and bug fixes, and I was completely devastated. With my prior experience setting up DBs and the works, I was so sure that we now had just lost two weeks minimum to try and restore this (only me and one other dev and we have full-time jobs, this is on the side).
After much shock and anger, I briefly remembered that with Hasura they had all these concepts of metadata, seeds, and migrations. Luckily it’s made so easy that even when you manipulate the database through the Hasura console, you can generate commit changes with their CLI. So, with just a few commands, we were able to apply our metadata, migrations, and seeds to a new database (using https://neon.tech/) and get our dev instance up and running again in a matter of seconds (once I realized this was possible of course 🙄).
How to set up Hasura with a “database as code” implementation
Setting up your Hasura cloud instance locally is pretty straightforward and is done in a few simple steps:
First, install the CLI by running npm install -g hasura-cli or yarn global add hasura-cli.
Create a new Hasura project by running hasura init. This will create a new directory with the required files and dependencies for your Hasura project.
Once your project is set up, you can apply your metadata by running hasura metadata apply. This will create your GraphQL schema and tables based on your metadata file.
After your metadata is applied, you can apply your migrations by running hasura migrate apply. This will update your database with any changes you’ve made to your schema.
Finally, you can apply your seeds by running hasura seed apply. This will populate your database with the test and user data you’ve defined in your seeds file.
Thats it!
We run these commands as our database grows and evolves to easily keep all our database changes in code. I don’t know about you, but especially not having too much backend or DB experience, this was a lifesaver for me. Previously, I only had a handful of times dealing with database as code and I just remember it being a nightmare with migrations, versioning, permissions, etc. – it never quite “worked” for me. I always had conflicts and issues. Hasura just works.
Summary
Hasura has proven to be an invaluable tool for our small team at Forwheel as we work to build and deploy scalable GraphQL APIs for our food truck vendor-facing application. It has saved us time and headaches, and we are grateful to the Hasura team for their hard work in creating such a powerful solution. And yet, this is only scratching the surface of what it has to offer. For just two developers focused on the Mobile App UIs, not having to deal with a middle layer has increased our development time tenfold.
Yes, we signed up for Hasura Cloud, but our usage is still early and slow at the moment and so it’s all been free! Honestly, it’s an incredible product/service, and I am genuinely excited for when we increase our usage to start actually paying for this – it will be worth every penny 🤑.
Oh, I almost forgot… the ONE time we had an issue with the Hasura Cloud console UI, we got an immediate email back and an opportunity to walk through our issue over Google Meet with their support team and some devs within 48 hours. Again, we have not paid anything yet for this software. I know that type of service won’t last forever as I can see them continue to grow and scale massively, but just…
BRAVO Hasura, Bravo! 👏👏👏
P.S. Shame on you Heroku, not cool…
About the Author
Brenden is a software engineer and serial entrepreneur with a passion for using technology to solve problems. With almost 8 years of experience working in a large financial institution, Brenden has also started three companies in his career. Despite the past two being unsuccessful, he gained valuable insights and applied them to his current venture, Forwheel. Forwheel aims to revolutionize the mobile food industry by creating an unforgettable and universally accessible experience. When not working, Brenden enjoys coding, personal finance and trading, cooking, skiing, and golfing.