Why this matters
- Manual
ALTER TABLEin production causes environment drift — staging passes, production fails mysteriously. - Zero-downtime deployments require migration strategies that avoid locking entire tables during peak checkout.
- Flyway and Liquibase integrate with Spring Boot CI pipelines — migrations run before new code serves traffic.
- Interview DevOps questions ask how you add a column to a 50-million-row table without downtime.
Clustered (PK)
Table rows (sorted by PK)
Row 1id=1
Row 2id=2
Row 3id=3
Non-clustered (email)
email index→ row pointer
Table heapunordered rows
Why versioned migrations
Schema is code. VaultCommerce stores migrations in src/main/resources/db/migration/:
db/migration/
V1__create_customers.sql
V2__create_products.sql
V3__create_orders.sql
V4__add_orders_shipping_address.sql
Flyway tracks applied versions in flyway_schema_history. On startup (or CI deploy step), only pending scripts run — never twice, never out of order.
-- V4__add_orders_shipping_address.sql
ALTER TABLE orders
ADD COLUMN shipping_address_json JSONB;
UPDATE orders SET shipping_address_json = '{}'::jsonb
WHERE shipping_address_json IS NULL;
ALTER TABLE orders
ALTER COLUMN shipping_address_json SET NOT NULL;
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 3 sections
- Flyway with Spring Boot
- Safe migration patterns
- Operations that lock tables
Test yourself
Answer these before moving on — recall is what makes it stick.