create-database-migration

Automate Knex migration creation and management for the Benefriches API.

45|3|Updated Jul 10, 2023
One-click install
npx skills add https://github.com/incubateur-ademe/benefriches --skill create-database-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-database-migration
Source: https://github.com/incubateur-ademe/benefriches/tree/main/.claude/skills/create-database-migration
Command: npx skills add https://github.com/incubateur-ademe/benefriches --skill create-database-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill automates the creation and maintenance of Knex database migrations for the Benefriches API, enabling safe schema evolution in development and production.

Core Features & Use Cases

  • Migration scaffolding: Generate timestamped migration files following project conventions.
  • Schema evolution: Support create/alter/rename/drop table and column changes, plus data migrations.
  • Consistency enforcement: Remind to update tableTypes.d.ts and run migrations to keep codegen in sync.

Quick Start

  1. Create a migration: pnpm --filter api knex:new-migration {description}
  2. Implement up() and down() in the generated file
  3. Update apps/api/src/shared-kernel/adapters/sql-knex/tableTypes.d.ts if schema changes
  4. Run migrations: pnpm --filter api knex:migrate-latest

Frequently Asked Questions about create-database-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a Knex database migration for schema changes?

To create a Knex database migration, generate a timestamped file using pnpm --filter api knex-new-migration, implement the up() and down() functions, update tableTypes.d.ts if the schema changes, and run pnpm --filter api knex:migrate-latest.

What do I need to update when modifying a database table with Knex?

When modifying a database table with Knex, you must update the tableTypes.d.ts file in apps/api/src/shared-kernel/adapters/sql-knex to keep TypeScript codegen in sync with the new schema structure.

Can I use Knex migrations for both schema and data migrations?

Yes, Knex migrations support both schema and data migrations. You can create, alter, rename, or drop tables and columns, as well as perform data migrations within the generated migration files.

How does the Knex migration template handle naming conventions?

The Knex migration template enforces consistency by generating timestamped migration files that follow strict project naming conventions, ensuring safe schema evolution in both development and production environments.

Does Node.js Knex support renaming tables and columns in migrations?

Yes, Node.js Knex supports renaming tables and columns within migrations. The Skill automates scaffolding for these alterations, ensuring the up() and down() methods are correctly implemented for reversibility.

What is the best way to run Knex migrations after schema updates?

The best way to run Knex migrations after schema updates is executing pnpm --filter api knex:migrate-latest, which applies pending migrations and ensures the database schema reflects the latest code changes.