简体   繁体   中英

Implementing Revisioning with SCD2/4

I'm working on a project that is a sort of bill of materials manager that needs to support revisioning of components. After some research, I've stumbled upon slowly changing dimensions type 2 and type 4 which seems like the most appropriate pattern in this use cases.

However, I'm a little bit confused on a couple of concepts:

CREATE TABLE projects (
  id    INTEGER PRIMARY KEY,
  name  TEXT
)

CREATE TABLE components (
  id           INTEGER PRIMARY KEY,
  name         TEXT,
  project_id   INTEGER,
  CONSTRAINT fk_project FOREIGN KEY (project_id) REFERENCES projects (id)
)

If I wanted to implement SCD Type 2, would the components table have the additional columns for start_date , end_date , active ? Or, would Type 2 be adding a revisions table with the same structure as components with the additional columns and Type 4 having a revisions table and a revisions_history table?

Any help would be greatly appreciated!

You can use temporal_tables

System-period data versioning (also known as transaction time or system time) allows you to specify that old rows are archived into another table (that is called the history table).

https://pgxn.org/dist/temporal_tables/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM