# Create Migration

> Use when: creating a new ElasticSearch database migration file, adding or transforming data at deploy time

- Skill: `opencti-platform/create-migration` (Agent Skill)
- Install (CLI): `npx skillmds@latest add opencti-platform/create-migration`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opencti-platform/create-migration/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: OpenCTI-Platform (https://skillmd.com/u/opencti-platform)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/opencti-platform/create-migration

---


# Create Database Migration

## Prerequisites
- **Description**: Short snake_case description of the change (e.g., `add_description_to_user`).

## Procedure

### Step 1 — Generate Migration File
Use the current timestamp (ms) as prefix.
File: `opencti-platform/opencti-graphql/src/migrations/<timestamp>-<description>.ts`.

### Step 2 — Implement Migration Pattern
Use the standard template with logging and execution context.

```typescript
import { logMigration } from '../config/conf';

const message = '[MIGRATION] <Description>';

export const up = async (next: (error?: Error) => void) => {
  const startTime = Date.now();
  logMigration.info(`${message} > started`);

  // Implementation here
  // usage: const context = executionContext('migration');
  //        await someDomainFunction(context, SYSTEM_USER, args);

  logMigration.info(`${message} > done in ${Date.now() - startTime} ms`);
  next();
   };

export const down = async (next: (error?: Error) => void) => {
  next();
};
```

