Sync PostgreSQL scripts when pull request merges to master
Developer ToolDocument/FileSales EnablementRecipe ToolsDatabaseMarketing
What it does
When a pull request merges to the master branch in GitHub, this automation finds SQL files in that merge and deploys them to PostgreSQL. It compares the commit against the last successful deployment to run only new scripts.
Who it's for
Engineering teams who deploy database changes through pull requests and need PostgreSQL scripts to run automatically when merged.
How teams use this
Deploy schema changes automatically
When someone merges a pull request with SQL files to master, the scripts run in PostgreSQL without manual steps. The team sees the deployment logged in Google Sheets.
Prevent duplicate script deployments
The automation compares commits so it only runs SQL files that are new since the last deployment. Duplicate runs are prevented by tracking the commit history in Google Sheets.
Alert the team after deployment completes
Add a Slack channel notification after PostgreSQL runs the scripts so the team knows the deployment succeeded or failed. Include the commit ID and file count in the message.
Filter deployments by folder path
Set a condition to only deploy SQL files from a specific folder, such as migrations or schema. This prevents unintended scripts from running in production.
How it works
- Monitor for merged pull requests. Watch GitHub for new or updated pull requests. When a pull request merges to master, this automation starts and checks the commit details.
- Find the last successful deployment. Search Google Sheets for rows that track successful deployments. This retrieves the commit ID of the most recent deployment to PostgreSQL.
- Compare commits to find new files. Get the most recent commit ID from the master branch and compare it against the last deployment. This identifies which SQL files are new or changed.
- Deploy each SQL file. For each SQL file in the changed files list, run the script in PostgreSQL. The automation processes only files with the .sql extension.
- Log the deployment. Record the commit ID and deployment timestamp in Google Sheets so the next merge knows which scripts have already run.