fix(prisma): skip migrations already applied by prisma migrate deploy
The custom runner only tracks its own table, so a database brought up with `prisma migrate deploy` looked empty to it and the baseline was replayed — failing on "type AdminRole already exists". Read applied names from `_prisma_migrations` too (a no-op when that table does not exist). Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
e79afddd76
commit
33e9f85f41
@@ -196,6 +196,19 @@ export async function runMigrations(prisma: PrismaClient): Promise<MigrationResu
|
|||||||
);
|
);
|
||||||
const appliedNames = new Set(alreadyApplied.map((row) => row.name));
|
const appliedNames = new Set(alreadyApplied.map((row) => 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[] = [];
|
const applied: string[] = [];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const legacyName = LEGACY_NAME_ALIASES[file.name];
|
const legacyName = LEGACY_NAME_ALIASES[file.name];
|
||||||
|
|||||||
Reference in New Issue
Block a user