From 9bc0bffac7c84fc7e7401fef64822cb2f6b7f6b4 Mon Sep 17 00:00:00 2001 From: NW Date: Sat, 8 Aug 2026 13:26:52 +0100 Subject: [PATCH] =?UTF-8?q?fix(db):=20migration=20014=20=E2=80=94=20add=20?= =?UTF-8?q?users.notes=20column=20(Next.js=20admin=20Prisma=20requires=20i?= =?UTF-8?q?t)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prod DB was missing users.notes → /api/users/bulk 500 (Prisma P2022) - Applied to prod; users + lead relations now load correctly --- src/migrations/014_user_notes.js | 19 +++++++++++++++++++ src/migrations/runner.js | 1 + 2 files changed, 20 insertions(+) create mode 100644 src/migrations/014_user_notes.js diff --git a/src/migrations/014_user_notes.js b/src/migrations/014_user_notes.js new file mode 100644 index 0000000..fe55c89 --- /dev/null +++ b/src/migrations/014_user_notes.js @@ -0,0 +1,19 @@ +import logger from '../utils/logger.js'; + +// Migration 014: add notes column to users (required by Next.js admin Prisma schema) +export default async function migration014(db, checkColumnExists) { + if (await checkColumnExists('users', 'notes')) { + logger.info('Migration 014: notes column already exists, skipping'); + return; + } + + await db.runAsync('BEGIN TRANSACTION'); + try { + await db.runAsync(`ALTER TABLE users ADD COLUMN notes TEXT`); + await db.runAsync('COMMIT'); + logger.info('Migration 014: Added notes column to users table'); + } catch (e) { + await db.runAsync('ROLLBACK'); + throw e; + } +} diff --git a/src/migrations/runner.js b/src/migrations/runner.js index 39df6e0..4d1da79 100644 --- a/src/migrations/runner.js +++ b/src/migrations/runner.js @@ -48,6 +48,7 @@ export async function runMigrations() { (await import('./011_active_flags.js')).default, (await import('./012_fix_typos.js')).default, (await import('./013_ai_features.js')).default, + (await import('./014_user_notes.js')).default, ]; for (let i = currentVersion; i < migrations.length; i++) {