Push is recreating constraints every time #2010
Replies: 3 comments
-
I'm trying to figure this out too |
Beta Was this translation helpful? Give feedback.
-
I have the same problem. It also deletes rows from db which is pretty annoying. This happens even when running it multiple times back to back, so the schema is exactly the same. Any solutions/updates on this? Using 'pg' driver for database querying
[✓] Pulling schema from database...
Warning You are about to execute current statements:
ALTER TABLE "lost_announcement" DROP CONSTRAINT "lost_announcement_last_approved_content_revision_id_lost_announ";
ALTER TABLE "lost_announcement" DROP CONSTRAINT "lost_announcement_pending_revision_id_lost_announcement_content";
ALTER TABLE "lost_announcement_content_revision" DROP CONSTRAINT "lost_announcement_content_revision_ann_id_lost_announcement_id_";
ALTER TABLE "lost_announcement_content_revision" DROP CONSTRAINT "lost_announcement_content_revision_reward_currency_code_currenc";
ALTER TABLE "sighting_announcement_content_revision" DROP CONSTRAINT "sighting_announcement_content_revision_ann_id_sighting_announce";
ALTER TABLE "sighting_announcement" DROP CONSTRAINT "sighting_announcement_last_approved_content_revision_id_sightin";
ALTER TABLE "sighting_announcement" DROP CONSTRAINT "sighting_announcement_pending_revision_id_sighting_announcement";
ALTER TABLE "map_entity" ALTER COLUMN "postgis_coordinates" SET DATA TYPE geometry(point);
DO $$ BEGIN
ALTER TABLE "lost_announcement" ADD CONSTRAINT "lost_announcement_last_approved_content_revision_id_lost_announcement_content_revision_revision_id_fk" FOREIGN KEY ("last_approved_content_revision_id") REFERENCES "public"."lost_announcement_content_revision"("revision_id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
ALTER TABLE "lost_announcement" ADD CONSTRAINT "lost_announcement_pending_revision_id_lost_announcement_content_revision_revision_id_fk" FOREIGN KEY ("pending_revision_id") REFERENCES "public"."lost_announcement_content_revision"("revision_id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
ALTER TABLE "lost_announcement_content_revision" ADD CONSTRAINT "lost_announcement_content_revision_ann_id_lost_announcement_id_fk" FOREIGN KEY ("ann_id") REFERENCES "public"."lost_announcement"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
ALTER TABLE "lost_announcement_content_revision" ADD CONSTRAINT "lost_announcement_content_revision_reward_currency_code_currency_code_fk" FOREIGN KEY ("reward_currency_code") REFERENCES "public"."currency"("code") ON DELETE set null ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
ALTER TABLE "sighting_announcement_content_revision" ADD CONSTRAINT "sighting_announcement_content_revision_ann_id_sighting_announcement_id_fk" FOREIGN KEY ("ann_id") REFERENCES "public"."sighting_announcement"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
ALTER TABLE "sighting_announcement" ADD CONSTRAINT "sighting_announcement_last_approved_content_revision_id_sighting_announcement_content_revision_revision_id_fk" FOREIGN KEY ("last_approved_content_revision_id") REFERENCES "public"."sighting_announcement_content_revision"("revision_id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
ALTER TABLE "sighting_announcement" ADD CONSTRAINT "sighting_announcement_pending_revision_id_sighting_announcement_content_revision_revision_id_fk" FOREIGN KEY ("pending_revision_id") REFERENCES "public"."sighting_announcement_content_revision"("revision_id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
❯ No, abort
Yes, I want to execute all statements I've tested it on the following versions, and the issue still happens:
|
Beta Was this translation helpful? Give feedback.
-
Nevermind, I found the solution. The issue was caused by the long constraint names being truncated. To fix it quickly, I updated the table and field names. The specific problem with truncation can be seen in this example (among others): The constraint name Now when I run Using 'pg' driver for database querying
[✓] Pulling schema from database...
Warning You are about to execute the following statements:
ALTER TABLE "map_entity" ALTER COLUMN "postgis_coordinates" SET DATA TYPE geometry(point);
[✓] Changes applied (Note: Ignore postgis_coordinates here, as I save it as geography, but Drizzle currently only supports geometry.) It would be great to have an option to assign custom names to .references() constraints, as mentioned in this comment: #466 (comment) |
Beta Was this translation helpful? Give feedback.
-
Hello, everyone,
Every time I run
drizzle-kit push:pg
it tries to recreate all constraints, even if nothing has changed in the database.Is this behavior expected?
In my schema, I'm using
.references
and 'relations' together for relations.Config file:
Generated code:
Beta Was this translation helpful? Give feedback.
All reactions