Backend Migrations

Automate Prisma migrations for PostgreSQL schema changes.

1|Updated Dec 4, 2024
One-click install
npx skills add https://github.com/imkdw/imkdw-dev --skill backend-migrations-imkdw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Backend Migrations
Source: https://github.com/imkdw/imkdw-dev/tree/main/.claude/skills/backend-migrations
Command: npx skills add https://github.com/imkdw/imkdw-dev --skill backend-migrations-imkdw

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Database schema changes are inherently risky and complex, often leading to data loss or inconsistencies if not managed properly. This Skill ensures the safe, consistent, and version-controlled evolution of your PostgreSQL database schema using Prisma.

Core Features & Use Cases

  • Prisma Migration Workflow: Create and apply database migrations using the Prisma CLI, automating schema updates and tracking changes.
  • Split Schema Management: Organize schema definitions by domain (e.g., member.prisma, article.prisma) for improved clarity and maintainability in large projects.
  • Data Integrity & Conventions: Implement best practices like UUID primary keys, soft deletes, and proper indexing to maintain robust data integrity.
  • Use Case: When adding a new field to an existing database table, use this Skill to generate a new Prisma migration, apply it, and ensure the database schema is updated without manual intervention or risk of data loss.

Quick Start

Guide me through creating a new Prisma migration to add a 'description' field to the 'Article' model, ensuring it's nullable and properly indexed.

Frequently Asked Questions about Backend Migrations

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

FAQPage Schema
How do I create a Prisma migration to add a new column to an existing PostgreSQL table?

Create a Prisma migration by modifying your schema file to add the column, then run `prisma migrate dev` to generate and apply the migration. Prisma automatically tracks schema changes, generates SQL, and updates your database without manual intervention.

What's the best way to organize Prisma schemas in large projects?

Use split-schema management by organizing schema definitions by domain into separate files (e.g., `member.prisma`, `article.prisma`) within `prisma/schema/`. This improves clarity and maintainability while Prisma migrations consolidate all changes in `prisma/migrations`.

Can I use soft deletes with Prisma migrations on PostgreSQL?

Yes. Add an optional `deletedAt` timestamp field to your Prisma model, then run a migration to add the column. This approach maintains data integrity by marking records as deleted rather than removing them, tracked through version control.

Do I need to manually write SQL when managing PostgreSQL schema changes with Prisma?

No. Prisma migrations automate SQL generation from schema changes. You modify your Prisma schema, run `prisma migrate dev` or `prisma db push`, and Prisma generates and executes the SQL, eliminating manual SQL writing and reducing data loss risk.

How do I ensure UUID primary keys and proper indexing in my Prisma database schema?

Define UUID as your primary key type in the Prisma model and add `@db.Uuid` annotations. Index foreign keys and frequently queried fields using `@@index`. Migrations enforce these conventions automatically when you run `prisma migrate dev`.

What happens when I run `prisma generate` after updating my schema?

Running `prisma generate` updates the Prisma Client based on your schema definitions, ensuring your application code stays synchronized with database structure. Combine with `prisma migrate dev` to apply schema changes and regenerate the client.