Skip to content
Back to skills

Api Data Migration

ASecurity

Generate Drizzle migrations with composite indexes, multi-tenancy support (organization_id), and timestamp triggers. Use when creating tables, adding columns, or implementing tenant isolation.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
databasesbashsqlapidatabaseperformance

Works with

  • api

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill api-data-migration --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Data Migration?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api Data Migration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-api-data-migration/badge)](https://www.skillsdirectory.com/skills/david-li0406-api-data-migration)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: api-data-migration
description: Generate Drizzle migrations with composite indexes, multi-tenancy support (organization_id), and timestamp triggers. Use when creating tables, adding columns, or implementing tenant isolation.
allowed-tools:
  - Read
  - Write
  - Edit
  - Glob
  - Grep
---

# Data Migration

## Purpose

Generate Drizzle ORM migrations with proper schema definition, composite indexes for tenant queries, multi-tenancy support (organization_id), and timestamp triggers.

## When to Use

- Creating new database tables
- Adding columns to existing tables
- Creating indexes for performance
- Implementing tenant isolation at database level

## What It Generates

### Directory Structure

```
packages/db-main/drizzle/0001_{timestamp}_{name}.sql
packages/db-main/src/schemas/{entity}.ts
```

## Patterns Enforced

### organization_id Column

All tables MUST have `organization_id` as first column:

- Type: `uuid`
- Nullable: `false` (required)
- Indexed: Yes
- Used for tenant scoping

### Composite Indexes

For queries like `WHERE organization_id = ? AND status = ?`:

- Create index on `(organization_id, status)`
- Improves query performance for tenant-scoped queries
- Avoids N+1 queries

### Timestamps

All tables have:

- `created_at TIMESTAMP NOT NULL DEFAULT NOW()`
- `updated_at TIMESTAMP NOT NULL DEFAULT NOW()`
- Trigger to update `updated_at` on UPDATE

### Foreign Keys

- Foreign keys use `ON DELETE CASCADE` for cleanup
- References use `organization_id` in FK for tenant isolation

## Usage Example

```bash
/skill data-migration --name=add_products_table --schema='id:uuid,name:text,price:int,active:boolean' --domain=main
```

## Related Files

- [Data Repository](../data-repository/SKILL.md) - Repository for the table
- [Feature CQRS](../feature-cqrs/SKILL.md) - CQRS handlers using the table

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…