Local changes
Start Nhost locally:
nhost dev
tip
Make sure you have Docker installed on your computer. It’s required for Nhost to work.
The nhost dev
command will automatically start a complete Nhost environment locally on your computer using:
- Postgres
- Hasura
- Authentication
- Storage
- Serverless Functions
- Mailhog
You use this local environment to do changes and testing before you deploy your changes to production.
Running nhost dev
also starts the Hasura Console.
tip
It's important that you use the Hasura Console that is started automatically when you do changes. This way, changes are automatically tracked for you.
In the Hasura Console, create a new table customers
with two columns:
- id
- name
When we created the customers
table there was also a migration created automatically. The migration was created at under nhost/migrations/default
.
$ ls -la nhost/migrations/default
total 0
drwxr-xr-x 3 eli staff 96 Feb 7 16:19 .
drwxr-xr-x 3 eli staff 96 Feb 7 16:19 ..
drwxr-xr-x 4 eli staff 128 Feb 7 16:19 1644247179684_create_table_public_customers
This database migration has only been applied locally, meaning, you created the customers
table locally but it does not (yet) exists in production.
To apply the local change to production we need to commit the changes and push it to GitHub. Nhost will then automatically pick up the change in the repository and apply the changes.
tip
You can commit and push files in another terminal while still having nhost dev
running.
git add -A
git commit -m "Initialized Nhost and added a customers table"
git push
Head over to the Deployments tab in the Nhost console to see the deployment.
Once the deployment finishes the customers
table is created in production.
We've now completed the recommended workflow with Nhost:
- Develop locally using the Nhost CLI.
- Push changes to GitHub.
- Nhost deploys changes to production.