Generate or execute data migration scripts with safety checks.
Generates, plans, and executes safe database migrations with rollback scripts and validation.
/plugin marketplace add majesticlabs-dev/majestic-marketplace/plugin install majestic-data@majestic-marketplace<action> [options]workflows/Generate safe data migration scripts or execute migrations with validation.
generate - Create migration script/data:migrate generate --source data.csv --target postgres --table orders
Generates:
plan - Preview migration without executing/data:migrate plan --migration migrations/20240115_add_tier.sql
Shows:
run - Execute migration/data:migrate run --migration migrations/20240115_add_tier.sql
Executes with:
backfill - Historical data backfill/data:migrate backfill --table orders --column tier --range "2023-01-01:2024-01-01"
generate:Task(subagent_type="majestic-data:transform:csv-to-sql",
prompt="Generate migration scripts for loading CSV to database table")
Or:
Task(subagent_type="majestic-data:transform:migration-builder",
prompt="Generate schema migration with safety checks")
backfill:Task(subagent_type="majestic-data:workflow:backfill-planner",
prompt="Plan and execute backfill operation for specified range")
# Migration Generated
**Source:** orders.csv
**Target:** PostgreSQL / public.orders
## Files Created
1. `migrations/20240115_create_orders.sql` - Forward migration
2. `migrations/20240115_create_orders_rollback.sql` - Rollback script
3. `migrations/20240115_create_orders_validate.sql` - Validation queries
## Schema
```sql
CREATE TABLE orders (
order_id BIGINT PRIMARY KEY,
customer_id BIGINT NOT NULL,
order_date DATE NOT NULL,
total NUMERIC(10, 2) NOT NULL,
status VARCHAR(20) NOT NULL
);
psql -d mydb -f migrations/20240115_create_orders.sql
After migration, run:
psql -d mydb -f migrations/20240115_create_orders_validate.sql
Expected results:
## Output: Plan
```markdown
# Migration Plan: 20240115_add_tier
## Summary
- **Type:** Schema change + backfill
- **Table:** customers
- **Estimated Duration:** 15 minutes
- **Risk Level:** š” Medium
## Changes
1. Add column `tier VARCHAR(20)`
2. Backfill from order history
3. Add NOT NULL constraint
4. Add CHECK constraint
## Impact Analysis
- **Rows affected:** 125,000
- **Table lock:** Brief (ALTER ADD COLUMN)
- **Backfill:** Batched, no lock
- **Constraint:** Requires validation
## Dependencies
- Requires: orders table populated
- Blocks: None
## Rollback
```sql
ALTER TABLE customers DROP COLUMN tier;
ā Safe to proceed
## Output: Run
```markdown
# Migration Execution: 20240115_add_tier
**Started:** 2024-01-15 14:00:00 UTC
**Status:** ā
SUCCESS
## Execution Log
| Step | Duration | Status |
|------|----------|--------|
| Pre-check: table exists | 0.1s | ā
|
| Pre-check: column not exists | 0.1s | ā
|
| Capture baseline | 0.5s | ā
|
| Add column | 0.3s | ā
|
| Backfill batch 1/13 | 45s | ā
|
| Backfill batch 2/13 | 42s | ā
|
| ... | ... | ... |
| Backfill batch 13/13 | 38s | ā
|
| Add constraint | 2.1s | ā
|
| Post-validation | 1.2s | ā
|
**Total Duration:** 12m 34s
## Validation Results
| Check | Result |
|-------|--------|
| Row count unchanged | ā
125,000 |
| No null tiers | ā
|
| Distribution reasonable | ā
|
## Tier Distribution
| Tier | Count | Percentage |
|------|-------|------------|
| bronze | 75,000 | 60% |
| silver | 31,250 | 25% |
| gold | 12,500 | 10% |
| platinum | 6,250 | 5% |
/migrateCode migration between frameworks and technologies with systematic planning and validation.