create-database-migration
Create Knex database migrations for the Benefriches API. Use when adding, modifying, or removing database columns/tables. Handles schema changes (create…
от incubateur-ademe★ 45 звёзд на GitHub
Установить create-database-migration в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Create Database Migration
Generate timestamped Knex migrations following project conventions.
Quick Start
- Create migration:
pnpm --filter api knex:new-migration {description}- Example:
pnpm --filter api knex:new-migration add-column-email-to-users-table - Creates timestamped file in
apps/api/src/shared-kernel/adapters/sql-knex/migrations/
- Example:
- Implement
up()anddown()functions in the generated file - Update
apps/api/src/shared-kernel/adapters/sql-knex/tableTypes.d.tsif schema changes - If new table created: run
pnpm --filter api test:integration:file src/shared-kernel/adapters/sql-knex/tableConsistency.integration-spec.ts(needs Docker). If a table is missing from theTablesinterface or fromapps/api/test/tablesToCleanUp.ts, it fails and names it. IntablesToCleanUp, put child tables before parent tables. - Run:
pnpm --filter api knex:migrate-latest
Transaction Handling
Knex automatically wraps each migration in a transaction — the knex parameter in up()/down() is already a transaction object. Do NOT call knex.transaction() inside migrations.
// WRONG — redundant nested transaction
export async function up(knex: Knex): Promise<void> {
await knex.transaction(async (trx) => {
await trx.schema.createTable("example", (table) => { /* ... */ });
});
}
// CORRECT — knex is already a transaction
export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable("example", (table) => { /* ... */ });
}
To opt out of auto-transaction for a specific migration (e.g., DDL that can't run in a transaction):
export const config = { transaction: false };
File Naming
Format: {YYYYMMDDHHmmss}_{verb}-{description}.ts
| Operation | Pattern | Example |
|---|---|---|
| Create table | create-table-{name} |
20250211105813_create-table-users-features-alerts.ts |
| Add column | add-column-{name}-to-{table} or add-{name}-to-{table} |
20250915091313_add_newsletter_subscription_to_users_table.ts |
| Drop column | drop-{column}-from-{table} |
20250613111514_drop-is_friche-column-from-sites-table.ts |
| Rename column | rename-{old}-to-{new}-in-{table} |
20250729160857_rename-insee-to-city_code-in-cities-table.ts |
| Update data | update-{description} |
20250225095318_update-friche-activity-values-in-sites-table.ts |
Use kebab-case OR snake_case consistently within a single filename.
Migration Templates
Create Table
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable("table_name", (table) => {
table.uuid("id").primary();
table.string("name").notNullable();
table.uuid("related_id").references("id").inTable("other_table");
table.timestamp("created_at").notNullable();
});
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists("table_name");
}
Add Column
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
await knex.schema.table("table_name", (table) => {
table.string("column_name"); // nullable by default
// OR: table.boolean("flag").defaultTo(false);
// OR: table.string("required_col").notNullable();
});
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.table("table_name", (table) => {
table.dropColumn("column_name");
});
}
Drop Column
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
await knex.schema.table("table_name", (table) => {
table.dropColumn("column_name");
});
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.table("table_name", (table) => {
table.string("column_name").nullable();
});
// Optionally restore data if recoverable
}
Rename Column
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
await knex.schema.table("table_name", (table) => {
table.renameColumn("old_name", "new_name");
});
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.table("table_name", (table) => {
table.renameColumn("new_name", "old_name");
});
}
Data Migration
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
await knex("table_name")
.whereIn("column", ["old_value1", "old_value2"])
.update({ column: "new_value" });
}
export async function down(knex: Knex): Promise<void> {
await knex("table_name")
.where("column", "new_value")
.update({ column: "old_value1" }); // Best effort
}
Complex Data Migration (JSON columns)
import type { Knex } from "knex";
export async function up(knex: Knex): Promise<void> {
const rows = await knex("table_name")
.select("id", "json_column")
.whereRaw(`json_column::json
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
- 01
Bash - 02
Read - 03
Write
FAQ
Что делает скилл create-database-migration?
Create Knex database migrations for the Benefriches API. Use when adding, modifying, or removing database columns/tables. Handles schema changes (create table, add/drop/rename columns), data migrations, and updates to tableTypes.d.ts.
Как установить скилл create-database-migration?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл create-database-migration запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…