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

Add Git hook to rollback phantom migrations on branch switch #110

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

m-darbinyan
Copy link
Collaborator

@m-darbinyan m-darbinyan commented Dec 20, 2024

Closes #18

Description

This PR introduces functionality to automatically rollback phantom migrations when switching branches with git checkout. By default, this feature is disabled. Users can enable it via:

  • Environment Variable: export ACTUAL_DB_SCHEMA_GIT_HOOKS_ENABLED=true
  • Initializer: ActualDbSchema.config[:git_hooks_enabled] = true

After enabling, users should run the rake task to install the Git hook:
rake actual_db_schema:install_git_hooks

Screenshots

Success

Screenshot 2024-12-23 at 17 25 14

Configuration disabled

Screenshot 2024-12-23 at 17 28 18

.git/hooks directory doesn't exist

Screenshot 2024-12-23 at 17 28 55

post-checkout hook already exists

When hook is up to date
Screenshot 2024-12-23 at 17 25 45

Update
Screenshot 2024-12-23 at 17 26 11

Decline overwrite
Screenshot 2024-12-23 at 17 41 53
...
Screenshot 2024-12-23 at 17 43 02

@m-darbinyan m-darbinyan force-pushed the issue-18-add-git-hooks-for-branch-switch branch from 057f2ff to 1d300ee Compare December 20, 2024 12:18
Copy link
Member

@ka8725 ka8725 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-darbinyan

I think we are on the right track. I still have some comments. Also, can we utilize the "gem post-install" functionality to run this rake task automatically? After installation, it could ask several questions, such as:

  • Would you like to install Git hooks to automatically roll back phantom migrations when switching branches?
  • Would you also like to run db:migrate tasks automatically when switching branches?

It would be great to implement the second question as well, even for manual installation. I believe it should be implemented first before addressing the gem post-installation process.

If you have any questions or better ideas, don’t hesitate to reach out to me. Thanks!

lib/actual_db_schema/git_hooks.rb Outdated Show resolved Hide resolved
lib/actual_db_schema/git_hooks.rb Outdated Show resolved Hide resolved
@m-darbinyan m-darbinyan force-pushed the issue-18-add-git-hooks-for-branch-switch branch from 1d300ee to 17ce4cb Compare December 23, 2024 13:31
@m-darbinyan m-darbinyan force-pushed the issue-18-add-git-hooks-for-branch-switch branch from 17ce4cb to 3c4ae77 Compare December 23, 2024 13:35
@ka8725 ka8725 merged commit a8b4d93 into main Dec 23, 2024
8 checks passed
@ka8725 ka8725 deleted the issue-18-add-git-hooks-for-branch-switch branch December 23, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Git hook that runs the checker on branch switch
2 participants