---
name: opencti-platform-create-migration
description: "Use when: creating a new ElasticSearch database migration file, adding or transforming data at deploy time"
license: "NOASSERTION"
metadata:
  decimalai-skill-id: "1818d026-7869-4fee-aafa-f5d329b97fda"
  decimalai-version-id: "ea7c3038-18b4-4300-9ed5-f3f9604f3b1b"
  decimalai-version: "1"
  decimalai-body-sha256: "fa5348f9239905c721a9886a460e256fe252fd7a03b321834745a1796f3e3a92"
  decimalai-name: "opencti-platform/create-migration"
  decimalai-format: "1"
  decimalai-invocation: "model"
  decimalai-category: "coding"
  decimalai-source: "https://app.decimal.ai/s/opencti-platform-create-migration@1/SKILL.md"
---
# 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();
};
```
