M
M
makerkz2014-03-31 13:21:28
Database
makerkz, 2014-03-31 13:21:28

How to design a database with status storage?

For example, the site will be dedicated to books. There are authors and books (tables authors and books). The mechanism of action is something like this:
The author creates a book with the status "In writing" (The book is not yet visible to users).
After writing the first chapter, the author sets the status "First chapter written".
After the complete writing of the book, the status "The book is available to users" is set (Accordingly, the book becomes available to users)
Ultimately, the author and users see the full history of status changes. I understand that this is similar to a version control system, but in this case, the point is that there are already a certain number of predefined statuses on which further behavior depends (the book is visible / not visible / available for download). In particular, such a question is of interest, where will the main status of the book be stored? In the record about the book itself, or will the last status of the book be taken from the status history?
If necessary, I will write in more detail.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Snewer, 2014-03-31
@Snewer

As an option, keep two columns in the table: status, status_log. The log can be stored as json.

A
Alexander, 2014-03-31
@Papagatto

in the books table, the status column. When the author changes the status of the book, update the status field. Those. the books table always stores the current status of the book.
Add another historical table hbooks, into which records about changes in the status of a book (by a trigger) will be inserted.

A
afiskon, 2014-04-05
@afiskon

eax.me/database-design

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question