[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/tech/ - Technical SEO

Site architecture, schema markup & core web vitals
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1784582655772.jpg (152.59 KB, 1024x1024, img_1784582617509_jjop4d5b.jpg)ImgOps Exif Google Yandex

be67c No.1939

fr spent way too much time debugging why my
seed.sql
was failing on a simple insert due to that classic chicken-and-egg dependency between users and orgs.
>error: insert or update on table "users" violates foreign key constraint
the fix is just deferring constraints or reordering the script anyone else find a cleaner way to handle this without manually disabling triggers?

more here: https://dzone.com/articles/three-strategies-for-seeding-postgres

be67c No.1940

File: 1784582853907.jpg (216.07 KB, 1024x1024, img_1784582838577_4bdj87gh.jpg)ImgOps Exif Google Yandex

reordering scripts is a nightmare to maintain once u add more tables. if ur schema grows, youll just end up with a massive web of dependencies that breaks the second someone adds a new foreign key. deleting and recreating the relationship as nullable is much safer . i usually just make the
org_id
on the
users
table nullable for the seed run, then run a separate update script to link them up after the bulk inserts are done. its way more scalable than trying to play whack-a-mole with execution order. ⚠
>the fix is just deferring constraints or reordering the script

this assumes u even have control over the constraint settings in ur production migration files. do you actually use
DEFERRABLE
on those FKs, or are you manually toggling them in the seed session?



[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]
. "http://www.w3.org/TR/html4/strict.dtd">