n8n/packages/@n8n/db/AGENTS.md
Michael Drury a04ff92a4f
fix(ai-builder): Don't use autoGenerate for UUID columns for WFB persistence migration (#26558)
Co-authored-by: Tomi Turtiainen <10324676+tomi@users.noreply.github.com>
2026-03-05 10:00:28 +00:00

919 B

AGENTS.md

Extra information specific to the @n8n/db package.

Migration DSL

UUID Primary Keys

Do not use autoGenerate or autoGenerate2 on UUID columns. Both cause TypeORM to emit DEFAULT uuid_generate_v4() in PostgreSQL, which requires the uuid-ossp extension in the public schema. This fails on managed Postgres services like Supabase where the extension lives in a different schema.

Instead, generate UUIDs at the application level:

Migration:

column('id').uuid.primary.notNull,

Entity:

import { randomUUID } from 'node:crypto';
import { BeforeInsert, PrimaryColumn } from '@n8n/typeorm';

@PrimaryColumn('uuid')
id: string;

@BeforeInsert()
generateId() {
  if (!this.id) {
    this.id = randomUUID();
  }
}

autoGenerate / autoGenerate2 are fine for integer columns (they use serial / GENERATED BY DEFAULT AS IDENTITY respectively).