Keeping page changes history. A bit like SO does for revisions

前端 未结 3 1868
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 06:24

I have a CMS system that stores data across tables like this:

Entries Table
+----+-------+------+--------+--------+
| id | title | text | index1 | index2 |
+         


        
3条回答
  •  长情又很酷
    2021-01-02 06:55

    For one of our projects we went the following way:

    Entries Table
    +----+-----------+---------+
    | id | date_from | date_to |
    +----+--------_--+---------+
    
    EntryProperties Table
    +----------+-----------+-------+------+--------+--------+
    | entry_id | date_from | title | text | index1 | index2 |
    +----------+-----------+-------+------+--------+--------+
    

    Pretty much complicated, still allows to keep track of full object's lifecycle. So for querying active entities we were going for:

    SELECT 
    entry_id, title, text, index1, index2
    FROM
    Entities INNER JOIN EntityProperties
    ON Entities.id = EntityProperties.entity_id
    AND Entities.date_to IS NULL
    AND EntityProperties.date_to IS NULL
    

    The only concern was for a situation with entity being removed (so we put a date_to there) and then restored by admin. Using given scheme there's no way to track such kind of tricks.

    Overall downside of any attempt like that is obvious - you've to write tons of TSQL where non-versioned DBs will go for something like select A join B.

提交回复
热议问题