The Simplest Way to Make Cloud SQL and Mercurial Work Like They Should
Pairing cloud sql and mercurial lets teams version schema changes and run safe database updates. Developers commit SQL files to Mercurial, and build jobs apply them to Cloud SQL. This setup keeps database changes tied to a clear commit history. Every table change links back to a specific code revision and author. Teams can review SQL scripts before any job touches production data. When a release fails, the commit log shows what changed and why. How cloud sql and mercurial handle identity and
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Pairing cloud sql and mercurial lets teams version schema changes and run safe database updates. Developers commit SQL files to Mercurial, and build jobs apply them to Cloud SQL.
This setup keeps database changes tied to a clear commit history. Every table change links back to a specific code revision and author. Teams can review SQL scripts before any job touches production data. When a release fails, the commit log shows what changed and why.
How cloud sql and mercurial handle identity and data flow
Data flows in one direction from your Mercurial repo to your database instance. An engineer writes a migration script and pushes the changeset to Mercurial. A hook or build server detects the new commit and starts a job. That job reads the SQL file from the repo and logs in to Cloud SQL.
Permissions in Cloud SQL for PostgreSQL work differently than in self-hosted databases. It is a managed service, so customers cannot create users with true superuser attributes. A Google-managed system user named cloudsqladmin holds the actual superuser privileges. Customers cannot delete or modify these system roles or users.
Instead, you assign the cloudsqlsuperuser role to your admin accounts. This role grants select high-level rights, like creating event triggers and replication users. It also lets a user create extensions that need superuser rights. The default postgres admin user belongs to this role and can create roles and databases. Still, that default user starts without a password, so you must set one first. It also lacks true superuser or replication attributes.
Common failure modes and how to scope roles
Many teams make the mistake of storing static database passwords inside Mercurial repos. If someone clones the repo to a laptop, that secret leaks right away. Another common risk is running every Mercurial build job with the default admin account. When a build runner uses an overprivileged role, one bad script can drop tables.
Shared service accounts also ruin audit trails during busy release windows. Five engineers might push changesets to Mercurial in the same hour. If all five jobs log in as the same database user, logs look identical. You cannot tell which commit caused a lock or corrupted a row. Unlogged ad-hoc queries from local machines make this mystery even worse.
End-to-End Encryption + SQL Query Filtering: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix this, separate your migration roles from your daily app roles. Create a dedicated role in Cloud SQL just for Mercurial schema runner jobs. Give that role only the rights needed to alter target tables in one schema. Do not hand out the cloudsqlsuperuser role unless a script must add an extension.
Keep your network paths tight between the Mercurial build runner and the database. Allow traffic only from the specific runner subnet rather than open public networks. For human fixing, require individual database accounts instead of shared admin logins. Apply data masking to rewrite matched fields like emails, phone numbers, and card numbers in results. This keeps sensitive customer details safe while engineers check production state after a release.
Auditing schema changes across both tools
Good security requires matching your Mercurial commit log with your database query log. Before a job runs, check that the changeset passed peer review in Mercurial. Tag the SQL execution with the commit hash and the author name. When you check database logs later, you can trace every query back to source control. This simple habit turns chaotic database updates into a clean, repeatable workflow.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Can a Mercurial runner use a true PostgreSQL superuser in Cloud SQL?
No, customers cannot create or use accounts with true superuser attributes in Cloud SQL. You can grant the cloudsqlsuperuser role when a job needs to create extensions or triggers.
Should we use the default postgres user for Mercurial automation?
No, avoid using the default postgres admin account for automated repo jobs. Create a separate user with narrower rights scoped only to your app schema.
How do we protect sensitive data when debugging failed Mercurial migrations?
Use role-based controls and data masking on the database session. Masking rewrites matched fields like national IDs, emails, and card numbers in query results.
Related guides
In this post