How to Configure Cloud SQL Schema Migration

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a cloud sql schema migration by granting your runner a dedicated database role. Then, you run your update scripts through a secure network path to the database. Most engineering teams run these updates from an automated deployment pipeline. Some teams also let engineers run migration scripts from their own laptops during urgent fixes. When teams give migration accounts broad admin rights, one bad script can drop production tables. Broad permissions also let anyone with those keys read

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.

You set up a cloud sql schema migration by granting your runner a dedicated database role. Then, you run your update scripts through a secure network path to the database. Most engineering teams run these updates from an automated deployment pipeline. Some teams also let engineers run migration scripts from their own laptops during urgent fixes. When teams give migration accounts broad admin rights, one bad script can drop production tables. Broad permissions also let anyone with those keys read sensitive customer data.

How to set up a cloud sql schema migration

Cloud SQL for PostgreSQL is a managed database service. Customers cannot create or use accounts that have full PostgreSQL superuser attributes. Google reserves the true superuser account, called cloudsqladmin, for its own system management tasks. Customers cannot change or delete these built-in system roles.

Instead, you use the cloudsqlsuperuser role for high-level database setup tasks. The default postgres admin user belongs to this role out of the box. It comes with no password, so you must set one before you log in. This default user can create roles, create databases, and log in. It does not hold true superuser or replication attributes. Still, the cloudsqlsuperuser role can create extensions that need superuser rights. It can also create event triggers, replication users, publications, and subscriptions.

To set up your migration workflow, avoid using the default postgres user for daily changes. Create a separate migration user and grant it ownership of the target database schemas. If a migration script needs to add a privileged extension, grant cloudsqlsuperuser to that runner role. Next, set up your pipeline runner so it can reach the database instance over your network. The runner logs in as the migration user, checks the tracking table, and runs the new changes. Your regular app users should only get read and write rights on existing tables. They should never own the schema or hold the cloudsqlsuperuser role.

What native roles solve and what they leave open

Splitting the migration role from the app role stops the app from changing table structures. Using a dedicated migration role also keeps your team off the default postgres account. You get a clear boundary between daily app traffic and structural database updates.

Still, native database roles only check who logs in at the start of a session. Once a user or runner logs in as the schema owner, the database trusts every command. A schema owner can alter tables, but it can also drop tables or truncate data. It can also run broad select queries that return emails, phone numbers, and card numbers. Native roles cannot check individual SQL statements in flight to block destructive commands. They also cannot pause a risky schema change until a peer reviews and approves it. If an engineer uses the migration role to debug an issue, no field masking happens. The database returns raw national IDs and card numbers directly to the client screen.

End-to-End Encryption + SQL Query Filtering: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why manual migration fixes create audit gaps

Automated pipelines work well until a migration fails halfway through a production rollout. When a deployment breaks, an engineer often needs to log in and fix the schema state. Teams usually share the migration role password or grant cloudsqlsuperuser to the engineer for the fix. This step opens a wide security gap during a high-stress incident.

Shared database users make it hard to tie a specific drop command to one person. Even with individual database accounts, native roles stay active until an admin revokes them by hand. Teams often forget to remove these high-level rights after the migration incident ends. A safe setup needs statement-level checks, approval steps for risky commands, and automatic data masking.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Does a Cloud SQL schema migration need a true PostgreSQL superuser?

No, customers cannot use true superuser accounts in Cloud SQL for PostgreSQL. You use a schema owner role or the cloudsqlsuperuser role to add extensions and event triggers.

Should my app use the same database role that runs schema migrations?

No, your app should use a separate role that only reads and writes table rows. Keep schema ownership and table change rights locked to a dedicated migration role.

How can we stop engineers from reading sensitive rows during a migration fix?

Native schema owner roles can read all data inside the tables they own. To protect sensitive data, add a control point that rewrites emails and card numbers in query results.

The query runs. The emails stay hidden.