diff --git a/apps/api/src/prisma/migrate.ts b/apps/api/src/prisma/migrate.ts index b989d3bc..4dcc2bb6 100644 --- a/apps/api/src/prisma/migrate.ts +++ b/apps/api/src/prisma/migrate.ts @@ -196,6 +196,19 @@ export async function runMigrations(prisma: PrismaClient): Promise row.name)); + // A database brought up with `prisma migrate deploy` only has rows in + // `_prisma_migrations`. Without this, our runner replays the baseline and + // dies on `type "AdminRole" already exists`. Fresh installs that only use + // this runner never create that table — the query simply fails and we move on. + try { + const prismaApplied = await prisma.$queryRawUnsafe<{ migration_name: string }[]>( + `SELECT migration_name FROM "_prisma_migrations" WHERE finished_at IS NOT NULL`, + ); + for (const row of prismaApplied) appliedNames.add(row.migration_name); + } catch { + // no _prisma_migrations table + } + const applied: string[] = []; for (const file of files) { const legacyName = LEGACY_NAME_ALIASES[file.name];