
Streamlining Spanner migrations with Antigravity CLI headless mode

Google’s Finance Engineering team needed to modernize their legacy data layer by migrating to Cloud Spanner, a globally distributed, strongly consistent database, without taking production services offline. The challenge was manually rewriting dual-write logic across dozens of Data Access Objects (DAOs), a slow and error-prone process that would have required implementing multi-phase dual-write architectures in every DAO. The team built an automated refactoring pipeline using Antigravity CLI in headless mode to accelerate migration while maintaining strict data parity in staging environments.
The migration was structured in three phases: historical backfill copying existing records to Spanner while preserving referential integrity; dual-write/dual-read implementation modifying every DAO to write mutations to both the legacy store and Spanner in parallel; and automated API verification and parity checking that intercepted RPC traffic to verify byte-for-byte equivalence across both stores. Each DAO required a dedicated MutationConverter class, dual-write branch handling and rollback logic, and unit tests using fake time sources and test doubles. Doing this manually across 30+ DAOs would have taken months.
The team first standardized their DAO refactoring pattern around a decoupled MutationConverter interface, isolating Spanner schema translation into dedicated converter units instead of embedding raw table names in core business logic. This created a rigid, deterministic contract that an AI coding agent could reliably reason about.
Antigravity CLI in headless mode was chosen over interactive AI chat interfaces because headless mode enables systematic, multi-file code updates across an entire codebase without manual terminal prompts. The team built an orchestration script (migration_ui.py) that runs Antigravity in headless mode (-p). This approach enabled: deterministic prompt architectures treated as version-controlled engineering artifacts with precise rules for Spanner edge cases like timestamp serialization and nullability conversions; batch execution and automated verification where the script takes a target DAO, retrieves source code and schema, feeds it to Antigravity with structural conventions, generates the converter, refactored DAO, and tests, then runs blaze test and feeds errors back into Antigravity for self-correction; and overnight execution at scale where engineers queue up DAOs at end of day and find validated changelists ready for human review by morning.
The results included significant reduction in migration effort, highly reliable data migration because every DAO adhered to the same tested pattern and underwent automated testing, and allowing engineers to focus on higher-value tasks like data modeling and performance optimization. The article concludes with three tips: decouple schema translation first by defining a strict interface before writing migration scripts; move from interactive chat to headless automation for repetitive refactoring across more than three or four files; and let the build system act as a guardrail by connecting AI generation directly to test harnesses so the model fixes errors before human review.


