Agent SkillsOpenAEV-Platform/openaev › add-migration

add-migration

GitHub

用于创建基于 Flyway 的 Java 数据库迁移脚本,处理表结构变更、租户隔离及 ES 重建索引。

.github/skills/add-migration/SKILL.md OpenAEV-Platform/openaev

Trigger Scenarios

需要修改数据库 schema 新增或修改数据表字段 涉及租户隔离的表结构设计

Install

npx skills add OpenAEV-Platform/openaev --skill add-migration -g -y
More Options

Non-standard path

npx skills add https://github.com/OpenAEV-Platform/openaev/tree/main/.github/skills/add-migration -g -y

Use without installing

npx skills use OpenAEV-Platform/openaev@add-migration

指定 Agent (Claude Code)

npx skills add OpenAEV-Platform/openaev --skill add-migration -a claude-code -g -y

安装 repo 全部 skill

npx skills add OpenAEV-Platform/openaev --all -g -y

预览 repo 内 skill

npx skills add OpenAEV-Platform/openaev --list

SKILL.md

Frontmatter
{
    "name": "add-migration",
    "description": "Creates a Flyway Java-based migration for schema changes. Handles table creation, column additions, tenant isolation, and ES reindex. Use when asked to modify the database schema."
}

Add Migration

Prerequisites

  • What schema change is needed (new table, new column, FK, index, etc.)
  • Whether the table is tenant-scoped or platform-level
  • The next migration version number

Before writing the migration, confirm with the user:

  • The exact DDL statements to execute
  • Whether the change is additive (new table/column) or destructive (drop/rename)
  • How tenant-scoped data will be handled (FK to tenants, NOT NULL vs nullable tenant_id)

Procedure

Step 1 — Find the next version number

ls openaev-api/src/main/java/io/openaev/migration/ | sort | tail -5

Pattern: V4_{XX}__Description.java — increment XX.

Step 2 — Create the migration class

Location: openaev-api/src/main/java/io/openaev/migration/

package io.openaev.migration;

import java.sql.Statement;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.springframework.stereotype.Component;

@Component
public class V4_XX__Description extends BaseJavaMigration {
  @Override
  public void migrate(Context context) throws Exception {
    try (Statement statement = context.getConnection().createStatement()) {
      // SQL here
    }
  }
}

Step 3 — Apply tenant isolation (if applicable)

For tenant-scoped tables:

CREATE TABLE my_entities (
  my_entity_id VARCHAR(255) NOT NULL,
  my_entity_name VARCHAR(255) NOT NULL,
  tenant_id VARCHAR(255) NOT NULL,
  -- ... other columns ...
  CONSTRAINT pk_my_entities PRIMARY KEY (my_entity_id),
  CONSTRAINT fk_my_entities_tenant FOREIGN KEY (tenant_id)
    REFERENCES tenants(tenant_id) ON DELETE CASCADE
);
CREATE INDEX idx_my_entities_tenant ON my_entities(tenant_id);

Default tenant: 2cffad3a-0001-4078-b0e2-ef74274022c3

Step 4 — Handle ES reindex (if needed)

If modifying an entity indexed in Elasticsearch, add a reindex trigger:

DELETE FROM indexing_status;

Step 5 — Verify

mvn clean install -DskipTests -Pdev    # Migration runs on startup
mvn test                                # Ensure tests pass with new schema

Version History

  • 3.260818.1 Current 2026-08-20 12:00

Same Skill Collection

.github/skills/add-contract-output-type/SKILL.md
.github/skills/add-test/SKILL.md
.github/skills/create-feature-module/SKILL.md
.github/skills/reduce-tx-baseline/SKILL.md
.github/skills/review-code/SKILL.md
.github/skills/review-docs/SKILL.md
.github/skills/review-frontend/SKILL.md
.github/skills/review-migration/SKILL.md
.github/skills/review-multi-tenancy/SKILL.md
.github/skills/review-performance/SKILL.md
.github/skills/review-security/SKILL.md
.github/skills/activate-tenant-table/SKILL.md

Metadata

Files
0
Version
3.260818.1
Hash
96bb64e0
Indexed
2026-08-20 12:00

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-26 08:16
浙ICP备14020137号-1 $방문자$