Agent Skills
› OpenAEV-Platform/openaev
› add-migration
add-migration
GitHub用于创建基于 Flyway 的 Java 数据库迁移脚本,处理表结构变更、租户隔离及 ES 重建索引。
Trigger Scenarios
需要修改数据库 schema
新增或修改数据表字段
涉及租户隔离的表结构设计
Install
npx skills add OpenAEV-Platform/openaev --skill add-migration -g -y
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 NULLvs nullabletenant_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


