database-migration
Create a migration to add, remove, or edit columns, tables, or indexes in the database
When & Why to Use This Skill
This Claude skill automates the creation of database migrations for Postgres environments using Knex and TypeScript. It streamlines schema management by generating precise migration files to add, remove, or modify tables, columns, and indexes, ensuring consistency with existing project patterns and reducing manual coding errors.
Use Cases
- Feature Development: Rapidly generate migration scripts when introducing new data structures or tables for application features.
- Database Optimization: Efficiently add or remove indexes to enhance query performance based on database analysis.
- Schema Refactoring: Safely modify existing database schemas, such as renaming columns or changing data types, while maintaining Knex/TypeScript standards.
- Standardization: Ensure all team-generated migrations follow the specific project architecture by leveraging local migration templates and examples.
| name | database-migration |
|---|---|
| description | Create a migration to add, remove, or edit columns, tables, or indexes in the database |
What I do
- Create database migrations
- Add or remove columns
- Add or remove indexes
- Add or remove tables
When to use me
Use this when you are editing the database in any way. This can include adding, removing, or editing columns, tables, or indexes
Context
We are using Postgres in a typescript backend. The migrations are written in typescript leveraging Knex
Steps
- Run
npm run migrate:make name-of-migrationin the shell, wherename-of-migrationis the name of the migration - Open this file and you will find a blank Knex migration
- Search in
migrations/models/examplesfor existing examples of what you are trying to do, and use this as a template for your migration - Fill the migration file in with your changes