We are building a tool to track the prices of products over time, and using Postgres as our RDBMS. It is important that product attributes can be changed, and that the history of an product's attributes be preserved forever. Here is a schema we designed based on OpenStreetMap's internal schema:
We have a 'products' table on the left storing every version of every product, and a 'current_products' table on the right storing only the most recent version of each product. Every time we want to change a store, we:
- create an entry in changesets
- read the latest entry of the product in 'products', increment version by one, and create another entry with the changes
- delete the corresponding entry in 'current_products' and create a new one with the changes and the latest version number from 'products'
We want to enforce as many business rules in the database engine as possible rather than relying on our software to keep things consistent, and this schema feels pretty "off", so we welcome any suggestions. Thanks in advance!
Edit: Revised the schema based on bbaird'sa response from @bbaird . Also decided to include versioning of stores and users. Tied products, stores, and users together with price table.