I'm using PostgreSQL and designing a relational database schema for an application where I want to store both system-defined (built-in) data and user-defined (custom) data in several tables, e.g.:
Product Categories
id | name | organisation_id |
---|---|---|
0 | Vegetables | 068fd6a5-1c93-493f-9ffc-93a52de02aa8 |
1 | Dairy | 068fd6a5-1c93-493f-9ffc-93a52de02aa8 |
The system-defined data is pre-populated and should be immutable by users, while the user-defined data can be created, modified, and deleted by users. I need to be able to query system and user data separately, and would like clients to remain dumb.
I've considered the following approaches:
- Add a boolean column (e.g.
is_system
) to indicate whether the data is system-defined or user-defined, but given an incredibly low percentage of records will be system-defined, I'm not sure if this is a good idea. - Use separate tables for system-defined and user-defined data, even if the structure is almost identical. These feels wrong to me as the data is essentially the same.
- Add a 'system-owned' organisation and identify system-defined data using its ID. Clients would need to be less dumb, because they now have an ID to remember if they want to query system data.
Which approach is generally recommended? Are there any other strategies I should consider?
Thanks for your insights.