What is FK-Ordered Seeding?
Inserting seed rows parent-first so every foreign key finds its target: users before projects, projects before messages. BYOB seeds run in dependency order with ids captured per step for child inserts.
Example
Seeding chat demo data inserts profiles, then projects referencing them, then messages referencing projects; reversing any step trips foreign-key violations on a fresh database.
What people get wrong
Seeding children before parents or hardcoding ids across files. Capture real ids per step and keep the dependency order explicit.
Related terms
Seed Data & Fixtures
Realistic demo rows loaded in foreign-key order, chunked to respect limits. Good seeds make every preview feel like a real product on first load.
Chunked Inserts
Splitting large seed or import batches into bounded chunks that respect statement and payload limits. D1-backed seeding fails on giant multi-row inserts; a few hundred rows per batch sails through.
Migration Tracking Table
The ledger recording which migrations already ran, so deploys apply each exactly once in order. Drizzle and Supabase both maintain one; never edit it by hand unless repairing a failed deploy.
B-Tree Index
The default balanced-tree structure making equality and range lookups fast without scanning every row. Add one where queries filter, join, or sort — then confirm with EXPLAIN before assuming victory.
Composite Index
One index spanning several columns for queries that always filter them together, ordered most-selective first. A three-column composite beats three single-column indexes on the same query shape.
Partial Index
An index covering only rows matching a predicate, such as live subscriptions where status is active. Smaller, faster, and cheaper to maintain than indexing rows queries never touch.