flyway-liquibase-guideline
Skill: flyway-liquibase-guideline
Purpose
Ensure schema evolution is handled in a way that is:
- versioned
- reproducible
- production-safe
- compatible with Spring Boot workflows
- aligned with module-based delivery
- respectful of existing data and deployment reality
Scope
Use this skill when generating or reviewing:
- initial schema migrations
- incremental schema changes
- index additions
- relation table additions
- compatible rename/replacement patterns
- auth schema evolution
- rollout sequencing notes
Default Migration Strategy
Unless explicitly overridden, prefer:
- Flyway-compatible SQL migrations
- MySQL-compatible syntax
- versioned files under:
backend/src/main/resources/db/migration/
Preferred naming pattern:
V<version>__<description>.sql
Examples:
V1__create_user_tables.sqlV2__add_user_status_index.sql
If the project explicitly standardizes on Liquibase, adapt the same safety principles to Liquibase format.
Core Principle
Prefer forward-only, additive, auditable schema evolution.
Do not treat migrations as throwaway setup scripts.
Treat them as long-lived production artifacts.
Migration Safety Rules
Additive-first rule
Prefer:
- creating new tables
- adding new nullable columns
- adding indexes
- adding new join tables
- adding new constraints when safe
Be cautious with:
- dropping columns
- renaming columns directly
- changing types incompatibly
- destructive data transformations
Backward compatibility rule
When practical:
- stage risky changes across multiple migrations
- allow old and new code paths to coexist briefly
- backfill before enforcing stricter constraints
- avoid breaking rolling deployments
Production caution rule
Do not assume:
- empty database
- immediate full downtime
- no existing data
- perfect manual operator intervention
Migration Structure Rule
A migration should usually represent one coherent unit of schema evolution.
Good examples:
- create auth base tables
- add refresh token indexes
- introduce audit log table
- add new status column and supporting index
Bad examples:
- unrelated schema changes mixed together
- massive all-in-one migration for many modules without reason
Required Alignment Rule
Every migration must stay aligned with:
- planner business rules
- OpenAPI-important fields
- DB schema design
- backend entity mapping expectations
Do not introduce critical hidden schema drift casually.
Base Column Rule
Business tables created through migration should include:
id BIGINT PRIMARY KEY AUTO_INCREMENTcreated_at DATETIME NOT NULLupdated_at DATETIME NOT NULLdeleted_at DATETIME NULL
Unless there is a clearly approved exception.
Index / Constraint Rule
Migration design must preserve schema quality:
- add PKs
- add FKs for real relationships
- index all FK columns
- add unique constraints for truly unique business fields
- add search/filter indexes where planner behavior implies them
Do not postpone obvious integrity/index requirements carelessly.
Soft Delete Rule
If the system uses soft delete:
- preserve
deleted_at - do not convert soft delete expectations into hard delete by accident
- ensure new tables meant for business entities include soft delete support where required
Auth Schema Rule
For auth-related migrations, preserve the approved auth schema intent.
Typical expectations:
usersrolesuser_rolesrefresh_tokens
Passwords must remain stored as:
password_hash
Never use plain text password storage as the final schema model.
Rename / Replace Strategy Rule
When a field or structure conceptually changes, prefer staged patterns such as:
- add new structure
- backfill data
- update code to read/write the new structure
- remove old structure in a later approved migration
Avoid direct destructive renames when safer staged evolution is appropriate.
Seed / Data Backfill Rule
If a migration needs data backfill:
- keep it deterministic
- keep it safe
- keep it limited in scope
- avoid mixing large operational data fixes casually into structural migration unless necessary
Reference/static seed-safe operations are acceptable when they are stable and intentional.
Rollback Rule
Do not assume perfect rollback by destructive reverse SQL.
Instead:
- design safer forward migrations
- document risky changes
- split risky transformations into stages
- make deployment order clear
Rollback notes may still be documented where appropriate.
Liquibase Compatibility Rule
If Liquibase is used instead of Flyway:
- preserve the same principles
- keep changes versioned and auditable
- maintain explicit ordering
- keep destructive changes controlled
- align closely with Spring Boot runtime expectations
Forbidden Patterns
- rewriting historical migration content after it is conceptually applied
- dropping tables/columns casually
- destructive incompatible type changes without staging
- mixing many unrelated module changes in one migration without reason
- using migrations as unversioned ad hoc SQL dumps
- persisting plain text password fields in auth schema
Final Goal
Migration design should be:
- versioned
- safe
- incremental
- maintainable
- deployment-aware
- compatible with real team development over time
