-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feedback on Hasura migrations #1211
Comments
Hi @akiran, thanks for the feedback. This is very helpful 👍 1., 2.: Based on the commands, I think you have followed this guide: https://docs.hasura.io/1.0/graphql/manual/migrations/existing-project.html. Please do correct me if I am wrong. We have not addressed the use case for creating migrations from an existing project (db) and continuing to use that project (db) with migrations. The guide addresses the use case for creating migrations from an existing project (db) and applying it on a new project (db) and continue using that. This is also the reason for first migration not appearing in the status output. We'll address this gap immediately. Reg. the Combining migrations files is a good suggestion. Something like a record and then save. But, this is only going to be an aesthetic change, since under the hood it'll be the same. Even if you have 800 migrations (we have users who have this many 😄), all of them will be applied at once in a single postgres transaction, when Showing the version status on Console is informative. @praveenweb Can you create off an issue and add this? Yes, rolling back migrations are possible with the |
@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 |
Got it. I'll get back after checking a latest Postgres dump. Yeah, it makes sense to group together migrations for maintainability. Will iterate over some ideas and get back. In the meanwhile, do let us know if you have any suggestions/ideas. |
For what it's worth, I followed the migration guide, but when applying to the existing database changed my initial migration to a select, then put the db dump back in the migration file. It also looks like running a schema creates a row in hbd_catalog.schema_migrations with the form #,###,###,###,### sourced from the number leading the migration. For example I had 1553035567544_schemaname.sql, in the db the version is 1,533,035,587,544, dirty false., so inserting a row here may skip the initial migration. |
@tranqy You're right. Whenever migration is applied, it's version (which is unix timestamp in nanoseconds by default) is entered into |
I got into a similar situation following https://docs.hasura.io/1.0/graphql/manual/migrations/existing-database.html. The source was a hasura instance running in an EC2 container
followed by a bunch of migrations that have been successfully applied on both the SOURCE and the DATABASE. I'm not quite sure how I got into this situation and since there is no migration on the SOURCE for '1570497949573' I have no idea what this migration contains that was supposedly the first migration applied to the DATABASE At first glance it looks like the DATABASE is in the same state as what I see when running I'd like to get this cleaned up so that I don't hit errors any time I try to run I tried running I apologize if this belongs elsewhere like StackOverflow or Discord, but it seemed relevant to the original issue |
Are you the only developer working on the project? |
Thanks for the prompt reply. There is one other developer working on the project but the server in question is a local instance of hasura running in a container, which is why I was surprised. It should only be affected by my own actions and not the other developer |
I'm not sure what I'm doing wrong, but at the very least it seems like your documentation is out of date so I figured I'd leave a comment here for that. What I'm doing: trying to move a heroku-hosted hasura instance to my local machine for local development and to version control migrations/schema changes. What I'm following: https://github.com/hasura/platform-docs/blob/master/platform/manual/guides/importing-existing-database.rst What's wrong:
|
@Californian That link is not for Hasura GraphQL Engine. Try this link: https://hasura.io/docs/1.0/graphql/manual/migrations/index.html |
I had a similar problem on an existing project, I'm using docker, so I saw that hdb_catalog already exists, so I removed docker volumes running |
I also had a similar problem when following the basic migrations tutorial. My initial (first) migration created from the initializing migrations step was registered as "Not Present" in the database. I "fixed" it by running When it comes to the subsequent steps re squashing steps to clean up, all the intermediary migrations created by the console are still registered as "Present" in the database after the squash is done (using This is a bit surprising (although for the sake of data integrety, I can understand why), and I would really like it if the docs said something about why this is how it is, and how to "clean up" the right way; am I just supposed to run `hasura migrate apply --skip-execution --version ? Or should I roll the database back and apply the squashed migration? Or should I have a second database to apply the squashed migration to, and do a manual diff between the results? I also suspect that the Add Checkpoints step should include running That was a lot of suggestions, but I also want to say that a really like the docs in general 😄 |
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? |
I tried migration as mentioned in hasura docs and ran in to some issues.
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.htmlWhen I tried to apply this migration on a new database, I got this error
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.hasura console
and started adding new columns from the hasura dashboard and migration are created automatically. Buthasura migrate apply
failed with error "table already exists".hasura migrate status
results inI 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
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)
Can you show
hdb_catalog.schema_migrations
table in hasura dashbaord. Useful when debugging issues with migrationsIs it possible to rollback migations ? I couldn't find docs related to rollback of migrations.
The text was updated successfully, but these errors were encountered: