Draft version of database table

前端 未结 4 1358
一向
一向 2021-01-19 01:14

I have a database with a report table. This table represents report data, and has constraints. Now the application is used by firemen, and they might have to run off and put

4条回答
  •  死守一世寂寞
    2021-01-19 01:45

    I've thought pretty long and hard about this problem, and here is my answer:

    1. store drafts and their corresponding validated entities in the same table. have a is_draft column

    2. use is_draft=1 to turn off validation in triggers and check constraints, or your ORM validation rules

    3. many of your fields will have to be nullable or have defaults

    this has several advantages:

    1. drafts and their corresponding validated entities are stored in the same table

    2. drafts and their corresponding validated entities have the same id . why is this important?

    imagine you start a quote for a customer. save it. it gets an id. you are looking at it in a web browser /quotes/id/55 . you start editing that quote, remove a required value because it was wrong. you have to go next door to look it up, but you want to save it. the id number should not change.

    it would also be confusing for people if they are collaborating on the same document and its id keeps changing if it moves in and out of a valid state.

提交回复
热议问题