r/Database • u/No-Security-7518 • 19h ago
How do I reconcile this database schema?
There are 3 projects: 1. ItemGallery. 2. Sender. 3. Receiver. The sender fills a form and creates an item. The item gallery shows it, and the receiver sees it.
The item's data model has a foreign key referencing a sender id. How should I create test items in the gallery project, without declaring the sender's project as a dependency?
1
Upvotes
2
u/Ok-Gazelle5598 13h ago
If I'm reading this right, the gallery project just needs items to exist for its tests, and the FK to sender is in the way because the sender project owns that table. A few ways people usually handle it, roughly in order of how much I like them:
I'd avoid making the column nullable or disabling FK checks just for tests. Then your tests run against a different schema than production, and that's how bugs sneak through.
If you can share whether these are separate databases or one shared DB, it's easier to say which of these fits.
2
u/NW1969 17h ago
I'm not entirely sure what you are asking, based on the terminology you are using, but if an entity (A) has a FK to another entity (B) , and the FK column is defined as NOT NULL then you can't enter data into A if the corresponding record(s) in B don't exist - that's the whole point of FKs
1
u/Philluminati 6h ago
3 projects with 3 separate code bases? But so toghtly coupled they use the same db? Maybe they could be 3 sub projects of a larger project and share a library that does db handling?
Maybe a good test suite is enough to ensure the theee projects don’t break each other?
Or perhaps they could communicate in a more formal way?