← 返回列表
全部 Skill›数据与AI Data & AI›flyway-liquibase-guideline

flyway-liquibase-guideline

作者 @findsun-vn · 语言 en
Guide safe Spring Boot database migration design using Flyway or Liquibase, with Flyway-style versioned SQL as the default.
数据与AI Data & AI数据工程通用待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
0
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

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.sql
  • V2__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_INCREMENT
  • created_at DATETIME NOT NULL
  • updated_at DATETIME NOT NULL
  • deleted_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:

  • users
  • roles
  • user_roles
  • refresh_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:

  1. add new structure
  2. backfill data
  3. update code to read/write the new structure
  4. 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
评论
Ffindsun-vn
findsun-vn
findsun-vn/E-Commerce
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@findsun-vn
所属大类数据与AI Data & AI / 数据工程
国内可用性通用
最近源活动—
风险提示无
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。