Skip to content
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

cli: add command to reset migrations #5373

Closed
scriptonist opened this issue Jul 14, 2020 · 8 comments
Closed

cli: add command to reset migrations #5373

scriptonist opened this issue Jul 14, 2020 · 8 comments
Assignees
Labels
c/cli Related to CLI good first issue Good for newcomers hacktoberfest

Comments

@scriptonist
Copy link
Contributor

scriptonist commented Jul 14, 2020

hasura migrate reset

This command should clear the history of the migrations on the server and clear the local migrations. Basically, do steps 1 and 2 mentioned in this blog post: https://hasura.io/blog/resetting-hasura-migrations/

@scriptonist scriptonist added good first issue Good for newcomers c/cli Related to CLI labels Jul 14, 2020
@timhere
Copy link

timhere commented Jul 21, 2020

I agree that this would be a good addition as my feature development workflow has lots of writing TRUNCATE hdb_catalog.schema_migrations; and rm -r migrations.

@tharun208
Copy link

@scriptonist I like to work on this

@kolharsam
Copy link
Contributor

kolharsam commented Sep 6, 2020

@tharun208 you can go ahead, good luck! 😁

Edit: I've assigned this task to you as well.

@shraddhaag
Copy link
Contributor

Hi @tharun208! Wanted to check in if you need any help. Also, could you please open a draft PR with your progress?

@sushil97
Copy link

sushil97 commented Oct 5, 2020

I would like to work on this

@scriptonist
Copy link
Contributor Author

Haven't heard from @tharun208 in while so I think it's okay for you pick it up @sushil97

@sushil97
Copy link

@scriptonist i would love to work on this but right now i am working on another PR. So there will be some delays on this.

@athanhat
Copy link

athanhat commented May 4, 2021

Hi, I have just upgraded my hasura engine and CLI to

hasura version

INFO hasura cli                                    version=v2.0.0-alpha.9
INFO hasura graphql engine                         endpoint="http://localhost:8001/" version=v2.0.0-alpha.9

And I discovered that resetting the migration history on the server is still under construction. Moreover I noticed that you cannot do any more

TRUNCATE hdb_catalog.schema_migrations;

And if you pull the schema and metadata from the server, you will loose the granularity of having multiple migration steps, i.e.
a single migration step will be marked as applied on the server by skipping execution. But I wanted to restore my PostgreSQL database (all schemas and populated table) and then apply all migrations steps from a backup folder.

So after restoring my PostgreSQL database, I initialised metadata operations and migrations folder and copied schema migrations from a backup folder.

hasura migrate status --database-name default

VERSION        NAME                     SOURCE STATUS  DATABASE STATUS
1615111441648  Schema_auth              Present        Not Present
1615197558676  Account                  Present        Not Present
1615261416207  AccountConfirmation      Present        Not Present
etc...

Now the trick is to mark ALL migration steps as applied by skipping execution and make them present in the database. That can be done easily by running the following pipeline (check how many line you need to skip NR>?):

hasura migrate status --database-name default | awk 'NR>2 {print $1}' | xargs -I{} sh -c 'hasura migrate apply --version {} --skip-execution --database-name default'

Anyway hope that helps others that have the same problem until hasura team implements migrations reset with a more efficient and elegant solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/cli Related to CLI good first issue Good for newcomers hacktoberfest
Projects
None yet
Development

No branches or pull requests

8 participants