Skip to content

Instantly share code, notes, and snippets.

@bibstha
Created July 2, 2024 04:37
Show Gist options
  • Save bibstha/cd3c8cf65425fc6fa0a5f2fe0766f815 to your computer and use it in GitHub Desktop.
Save bibstha/cd3c8cf65425fc6fa0a5f2fe0766f815 to your computer and use it in GitHub Desktop.
Kamal pre-deploy hook to run database migrations. File path .kamal/hooks/pre-deploy
#!/usr/bin/env ruby
# These environment variables are available:
# KAMAL_RECORDED_AT
# KAMAL_PERFORMER
# KAMAL_VERSION
# KAMAL_HOSTS
# KAMAL_COMMAND
# KAMAL_SUBCOMMAND
# KAMAL_ROLE (if set)
# KAMAL_DESTINATION (if set)
# Only check the build status for production deployments
if ENV["KAMAL_COMMAND"] == "rollback" || ENV["KAMAL_DESTINATION"] != "production"
exit 0
end
`kamal app exec -p -d $KAMAL_DESTINATION --version $KAMAL_VERSION "rails db:migrate"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment