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.

Feedback on Hasura migrations

See original GitHub issue

I tried migration as mentioned in hasura docs and ran in to some issues.

  1. I started creating tables from hasura dashboard with running hasura console. So migration files are not generated. I want to bring in the schema to migrations. I followed this guide to generate first migration https://docs.hasura.io/1.0/graphql/manual/migrations/database-with-migrations.html

When I tried to apply this migration on a new database, I got this error

Error: apply failed: [postgres-error] query execution failed ($.args[0].args)
File: ''
[42P06] FatalError: schema "public" already exists

I had to comment this line CREATE SCHEMA public; from public-schema.sql which is generated with command pg_dump -O -x -h <db-host> -p <db-port> -U <db-user> -d <db-name> --schema public --schema-only > public-schema.sql

Commenting/removing CREATE SCHEMA public; from public-schema.sql is not mentioned in the documentation.

  1. After generating first migration, I ran hasura console and started adding new columns from the hasura dashboard and migration are created automatically. But hasura migrate apply failed with error “table already exists”. hasura migrate status results in
VERSION        SOURCE STATUS  DATABASE STATUS
1544721345907  Present        Not Present
1544721838932  Not Present    Present
1544721935023  Not Present    Present

I think, first migration is not added in hdb_catalog.schema_migrations. Can you update docs about how to add first migration generated from existing database to schema_migrations

  1. Currently new migration files are generated for each schema change. This could result in lot of migration file when the project is newly started. It would be better if there is an option to make few changes and save a single migration file for all these changes at once. For example: Create a table and add 20 columns of this table and save a migration file. (Currently system creates 21 migration files for this case)

  2. Can you show hdb_catalog.schema_migrations table in hasura dashbaord. Useful when debugging issues with migrations

  3. Is it possible to rollback migations ? I couldn’t find docs related to rollback of migrations.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dchoigtcommented, Apr 20, 2022

I would like to rerun my migrations or at least a specific one. I can get the db sql migration to run by removing the entry inside of schema_migrations but I cannot get my metadata to run again. If I look at the hdb_metadata table it still has the older metadata instead of my new stuff. What do I do?

1reaction
akirancommented, Dec 14, 2018

@shahidhk Thanks for the prompt response.

I am using the Postgres from docker file given by hasura.

Regarding 3: I am interested in consolidated migration files for better maintainability of code. If we have all schema changes related to a feature in one file, it will be easy to refer back in future

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 directories consisting of up.sql and down.sql files in pure SQL syntax,...
Read more >
Local Dev to Staging to getting Production-Ready with Hasura!
We will look at different aspects of local development like running the server/database, managing migrations, testing out Actions and Events ...
Read more >
Migrations & Metadata Introduction | Hasura GraphQL Docs
Hasura Migrations are a SQL representation of the state of your database schema which can be used to keep track of, update, roll-back...
Read more >
Schema Migrations with Hasura Console
When I click add table and then navigate back to my editor to review the migration, I'll find the following now in my...
Read more >
2020 Year In Review - Hasura
“The Hasura GraphQL Engine fronts a Postgres database instance and can accept GraphQL requests from your client apps. It can be configured to ......
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