Flyway Database Migrations
Complete documentation of Flyway migrations V15-V31, including staging infrastructure, UUID to BIGINT migration, and catalog table seeding.Overview
Migrations are located in
src/main/resources/db/migration/ and executed automatically on application startup via Flyway.Migration Timeline
V11: Staging Infrastructure (581 lines)
Purpose: Production-grade bulk import system for million-record datasets Date: November 16, 2025Usage Workflow
V15: Password Reset Fields
Date: 2025-12-29 Purpose: Add password reset token functionality to users table.V16-V21: Catalog Tables
V16: Units Table (21 measurement units)
V16: Units Table (21 measurement units)
Date: 2025-12-29Purpose: Normalized catalog for measurement units.Units Included:
- Temperature: °C, °F
- Percentage: %
- Pressure: hPa, bar
- Gas Concentration: ppm
- Light: lux, W/m²
- Speed: m/s, km/h, RPM
- Flow: L/h, L/min, m³/h
- Water: mm (precipitation)
- Power: W, kW
- Chemistry: pH, mS/cm, dS/m
- Angle: ° (degrees)
V17: Actuator States Table
V17: Actuator States Table
Date: 2025-12-30Purpose: Catalog of actuator operational states with colors.
V18: Device Types Table
V18: Device Types Table
Date: 2025-12-30Purpose: Catalog of sensor and actuator types with validation ranges.34 Device Types Seeded:
- 13 Sensors: TEMPERATURE, HUMIDITY, SOIL MOISTURE, LIGHT INTENSITY, CO2 LEVEL, ATMOSPHERIC PRESSURE, WIND SPEED, WIND DIRECTION, RAINFALL, SOLAR RADIATION, PH, EC, UV INDEX
- 21 Actuators: VENTILATOR, FAN, HEATER, COOLER, IRRIGATOR, LIGHTING, CURTAIN, WINDOW, VALVE, PUMP, EXTRACTOR, MISTING, DEHUMIDIFIER, CO2 INJECTOR, etc.
V19: Sectors Table
V19: Sectors Table
Date: 2025-12-29Purpose: Greenhouse subdivisions for crop management.
V22-V25: UUID to BIGINT Migration
V22: Migrate UUID to BIGINT (780 lines)
Date: 2026-01-08 Purpose: Migrate all UUID primary keys to BIGINT for 40% performance improvement. Impact:- Index size reduced by 50%
- JOIN queries 40% faster
- Auto-increment IDs instead of UUID generation overhead
- tenants (root)
- users
- greenhouses
- sectors
- devices
- alerts
- settings
- command_history
V23: Cleanup UUID Migration (21,369 lines)
Date: 2026-01-09 Purpose: Remove temporary mapping tables after verification.V24: Add TSID and Codes (19,724 lines)
Date: 2026-01-10 Purpose: Add Time-Sorted ID (TSID) support and unique codes.V25: Migrate Existing IDs to TSID (15,977 lines)
Date: 2026-01-11 Purpose: Backfill TSID for existing records.V26-V30: Settings and Catalog Refinements
V26: Settings Replace Period with Actuator State
V26: Settings Replace Period with Actuator State
Date: 2026-01-12Purpose: Link settings to actuator states instead of periods.
V27: Create Data Types Table
V27: Create Data Types Table
Date: 2026-01-15Purpose: Catalog for data type validation.
V28: Change Greenhouse to Sector in Alerts/Settings
V28: Change Greenhouse to Sector in Alerts/Settings
Date: 2026-01-18Purpose: Alerts and settings now reference sectors instead of greenhouses.
V29: Add Description Fields and Nullable Message
V29: Add Description Fields and Nullable Message
Date: 2026-01-20Purpose: Add description fields to multiple tables.
V30: Rename Sectors Variety to Name
V30: Rename Sectors Variety to Name
Date: 2026-01-22Purpose: Rename
variety column to name in sectors table.V31: Seed All Initial Data (148 lines)
Date: 2026-02-23 Purpose: Populate catalog tables with production data.Migration Best Practices
Running Migrations
Flyway automatically executes migrations on application startup. Manual execution is rarely needed.
Migration Safety
✅ Safe Operations
- Add new columns (nullable)
- Create new tables
- Add indexes
- Insert seed data with
ON CONFLICT DO NOTHING
❌ Dangerous Operations
- Drop columns with data
- Change column types (may fail)
- Drop tables (data loss)
- Modify existing seed data
Rollback Strategy
Related Documentation
Database Architecture
Dual database strategy overview
Caching Strategy
Redis implementation details
API Reference
REST endpoints for data access