Migrations
Migrations with ralph
Section titled “Migrations with ralph”Migrations require careful, systematic changes across a codebase. ralph’s iterative approach ensures consistent progress with verification at each step.
Database Schema Migration
Section titled “Database Schema Migration”Migrate from one schema to another.
Prompt
Section titled “Prompt”# Database Schema Migration
Migrate from legacy schema to new normalized schema.
## Schema Changes
### Users TableOld:```sqlCREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(255), address VARCHAR(500), city VARCHAR(100), country VARCHAR(100));New:
CREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(255), address_id INT REFERENCES addresses(id));
CREATE TABLE addresses ( id INT PRIMARY KEY, street VARCHAR(500), city VARCHAR(100), country_id INT REFERENCES countries(id));Migration Steps
Section titled “Migration Steps”- Create new tables (migration file)
- Migrate data (migration file)
- Update application code to use new schema
- Update queries
- Drop old columns (final migration)
Code Changes Needed
Section titled “Code Changes Needed”- Update TypeScript types
- Update ORM models
- Update repository methods
- Update API responses
Process
Section titled “Process”- Create migration file:
npm run db:migrate:create - Run migration:
npm run db:migrate - Update affected code
- Run tests
- Commit with migration number
Verification
Section titled “Verification”npm run db:migrate:statusshows all applied- All tests pass
- No references to old column names
Completion
Section titled “Completion”When schema is fully migrated and all tests pass, output:
## TypeScript Upgrade
Upgrade TypeScript and fix all new errors.
### Setup
```tomladapter = "claude"maxIterations = 40Prompt
Section titled “Prompt”# Upgrade TypeScript to 5.x
Upgrade from TypeScript 4.x to 5.x and fix all type errors.
## Step 1: Upgrade```bashnpm install typescript@5 --save-devCommon Issues to Fix
Section titled “Common Issues to Fix”1. Verbatim Module Syntax
Section titled “1. Verbatim Module Syntax”// Old (might warn)import { Type } from './types';
// New (explicit type import)import type { Type } from './types';2. Module Resolution
Section titled “2. Module Resolution”// moduleResolution: "bundler" is new option// May need to update tsconfig.jsonProcess
Section titled “Process”- Run
npm run typecheckto see errors - Fix errors one file at a time
- Run typecheck again
- Commit when a batch of errors is fixed
tsconfig.json Updates
Section titled “tsconfig.json Updates”May need to update:
targetmodulemoduleResolutionstrictoptions
Completion
Section titled “Completion”When npm run typecheck exits with 0, output:
## Node.js Version Upgrade
Upgrade Node.js version and fix compatibility issues.
### Prompt
```markdown# Upgrade Node.js 18 to 20
Upgrade from Node.js 18 to Node.js 20 LTS.
## Changes to Address
### 1. Package.jsonUpdate engines:```json{ "engines": { "node": ">=20.0.0" }}2. Native Fetch
Section titled “2. Native Fetch”Node 20 has native fetch. Can remove:
node-fetchcross-fetch- polyfills
3. Deprecated APIs
Section titled “3. Deprecated APIs”Check for deprecated APIs:
url.parse()→new URL()querystring→URLSearchParams
Process
Section titled “Process”- Update .nvmrc to
20 - Update package.json engines
- Run
npm installwith Node 20 - Fix deprecation warnings
- Run tests
- Update CI config
CI Updates
Section titled “CI Updates”Update GitHub Actions / other CI:
node-version: '20'Completion
Section titled “Completion”When all tests pass on Node.js 20, output:
## Framework Migration
Migrate from Express to Fastify (example).
### Prompt
```markdown# Migrate Express to Fastify
Replace Express.js with Fastify for better performance.
## Conversion Patterns
### App Setup```typescript// Expressimport express from 'express';const app = express();
// Fastifyimport Fastify from 'fastify';const app = Fastify({ logger: true });Routes
Section titled “Routes”// Expressapp.get('/users/:id', (req, res) => { res.json({ id: req.params.id });});
// Fastifyapp.get('/users/:id', async (request, reply) => { return { id: request.params.id };});Middleware
Section titled “Middleware”// Express middlewareapp.use(express.json());app.use(cors());
// Fastify pluginsawait app.register(fastifyCors);// JSON parsing is automaticMigration Order
Section titled “Migration Order”- Install Fastify:
npm install fastify @fastify/cors - Create new app.ts with Fastify setup
- Migrate routes one by one
- Migrate middleware to plugins
- Update tests
- Remove Express:
npm uninstall express
Process
Section titled “Process”- Start with app.ts / main entry
- Migrate one route file at a time
- Run tests after each file
- Commit after each successful migration
Completion
Section titled “Completion”When no Express imports remain and all tests pass, output:
## CSS Framework Migration
Migrate from one CSS approach to another.
### Prompt
```markdown# Migrate CSS Modules to Tailwind
Replace CSS Modules with Tailwind CSS utility classes.
## Conversion Examples
### Basic Styling```jsx// Before (CSS Modules)import styles from './Button.module.css';<button className={styles.primary}>Click</button>
// .primary { background: blue; color: white; padding: 8px 16px; }
// After (Tailwind)<button className="bg-blue-500 text-white px-4 py-2">Click</button>Conditional Classes
Section titled “Conditional Classes”// Before<div className={`${styles.card} ${isActive ? styles.active : ''}`}>
// After<div className={`p-4 rounded shadow ${isActive ? 'ring-2 ring-blue-500' : ''}`}>Process
Section titled “Process”- Ensure Tailwind is configured
- Pick a component
- Convert CSS classes to Tailwind utilities
- Remove CSS Module import
- Delete .module.css file
- Test visual appearance
- Commit
Finding Components to Migrate
Section titled “Finding Components to Migrate”find src -name "*.module.css" | head -1Completion
Section titled “Completion”When no .module.css files remain in src/, output:
<Aside type="tip" title="Migration Testing">For migrations, visual testing is important. Consider adding screenshot comparisons before and after.</Aside>
## Tips for Migration Tasks
### 1. Establish Clear Conversion Rules
Tables work well:
```markdown| Before | After ||--------|-------|| `oldFunction()` | `newFunction()` |2. Define the Migration Order
Section titled “2. Define the Migration Order”Specify what to migrate first:
## Migration Order1. Core utilities (no dependencies)2. Shared components3. Feature modules4. Entry points3. Include Rollback Plan
Section titled “3. Include Rollback Plan”## If Something Breaks1. `git stash` current changes2. Identify the breaking change3. Create a fix or skip that file4. Continue migration4. Verify at Each Step
Section titled “4. Verify at Each Step”## After Each File- Build: `npm run build`- Typecheck: `npm run typecheck`- Test: `npm test`