mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
fix: lookup the primary key constraint name before dropping it (#20221)
This commit is contained in:
parent
c63f805cb4
commit
7f2e4f85f8
1 changed files with 17 additions and 3 deletions
|
|
@ -1,9 +1,23 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
await sql`ALTER TABLE "geodata_places" DROP CONSTRAINT IF EXISTS "PK_c29918988912ef4036f3d7fbff4";`.execute(db);
|
await sql`
|
||||||
await sql`ALTER TABLE "geodata_places" DROP CONSTRAINT IF EXISTS "geodata_places_pkey"`.execute(db);
|
DO $$
|
||||||
await sql`ALTER TABLE "geodata_places" DROP CONSTRAINT IF EXISTS "geodata_places_tmp_pkey"`.execute(db);
|
DECLARE
|
||||||
|
constraint_name text;
|
||||||
|
BEGIN
|
||||||
|
SELECT con.conname
|
||||||
|
INTO constraint_name
|
||||||
|
FROM pg_catalog.pg_constraint con
|
||||||
|
JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
|
||||||
|
WHERE rel.relname = 'geodata_places' AND con.contype = 'p';
|
||||||
|
|
||||||
|
IF constraint_name IS NOT NULL THEN
|
||||||
|
EXECUTE 'ALTER TABLE "geodata_places" DROP CONSTRAINT "' || constraint_name || '"';
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
`.execute(db);
|
||||||
await sql`ALTER TABLE "geodata_places" ADD CONSTRAINT "geodata_places_pkey" PRIMARY KEY ("id");`.execute(db);
|
await sql`ALTER TABLE "geodata_places" ADD CONSTRAINT "geodata_places_pkey" PRIMARY KEY ("id");`.execute(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue