How to Configure Spanner Schema Migration

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a spanner schema migration, store your DDL files in version control. Then use a build runner with a database role to apply those changes. Most engineering teams run these updates from an automated deployment pipeline. Still, urgent bugs often push engineers to run manual database updates from laptops. To move fast, teams grant broad admin roles to developers and build runners. A single bad command with broad rights can drop a live table. How a native spanner schema migration works A

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.

To set up a spanner schema migration, store your DDL files in version control. Then use a build runner with a database role to apply those changes. Most engineering teams run these updates from an automated deployment pipeline. Still, urgent bugs often push engineers to run manual database updates from laptops. To move fast, teams grant broad admin roles to developers and build runners. A single bad command with broad rights can drop a live table.

How a native spanner schema migration works

A native spanner schema migration relies on cloud identity and access roles. First, an admin creates a service account for the deployment tool. Next, the admin attaches a role that allows schema updates on the database. Developers write schema changes as plain text files in a code repo. When the team merges a change, the build runner logs into the cloud. The runner reads the state table to see which files already ran. Then it sends the new DDL statements to the database API.

The database processes schema changes in the background without locking all reads. Large changes like adding an index can take several minutes or hours. The migration tool waits for the database to finish the background task. Once the task finishes, the tool writes a new row to the tracking table. This record stops the runner from sending the same change twice. Teams also grant human engineers cloud roles so they can check failed updates.

What native cloud roles solve and what they miss

Native cloud roles do a good job of blocking outside attackers. They check who can log in and which database instance they can reach. You can split roles between read users, write apps, and schema admins. You can also bind roles to specific cloud projects to keep test data separate. Cloud audit logs record when a role connects or changes a database.

Still, cloud roles stop checking once the user or runner logs in. A role that can add a new column can also drop a table. If an engineer logs in to fix a stuck migration, they get full access. Native roles cannot pause a single dangerous drop statement for peer review. They also let engineers read raw customer rows while checking table structures. If a script queries user tables during a check, raw emails and phone numbers return. You need controls that inspect each command and rewrite sensitive fields in results.

End-to-End Encryption + API Schema Validation: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to make database schema updates safer

Teams can make updates safer by batching related DDL changes together. Sending many small statements one by one slows down the database. Group your new tables and columns into a single update step when possible. Always test the exact migration files against a staging database before production. Check how long index builds take on staging data before you run them live.

You should also remove standing admin roles from human developer accounts. When engineers need to inspect a live schema, limit what commands they run. Set up rules that block drop statements unless a second engineer approves them. Apply data masking to rewrite card numbers and national IDs in query results. This lets engineers verify table layouts without exposing private customer data on their screens.

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

How do you handle a failed spanner schema migration?

First, check the database operation log to see why the statement failed. Fix the syntax or data conflict in a new migration file. Never edit a file that already ran on a shared database.

Do schema changes lock the database during an update?

No, the database applies most schema updates in the background with zero downtime. Your apps can still read and write rows while new indexes build. Very large index builds still use extra system resources, so watch your load.

Should developers run schema migration tools from their laptops?

Developers should only run local migration tools against test or local emulator databases. Production schema changes should run through an automated build pipeline or controlled session. This keeps a clear audit log of every command sent to production.

The query runs. The emails stay hidden.