mysql - DB Schema for an application -


i've application, need post comments on blog paragraphs, not comment on blogs. paragraphs separated 2 new-line characters.

i'll splitting post received using post.split('\n\n'), saving post , paragraphs in separate tables (blog , paragraphs). whenever new comment received, i'll saving in comments table para_id received.

following db schema i'm planning build.

table blog

-id -title -date 

table paragraphs

-id -para -sequence_no -blog_id(fk) 

table comments

-id -comment -para_id(fk) -date 

the above design has flaw. consider example when post updated, ie, either new paragraph inserted between 2 paragraphs, or paragraph removed. result in distortion of sequence(ordinal number). how handle such use-case?

calculate unique hash value each paragraph , use combination of postid+paragraphhash primary key.

store timestamp along each paragraph. every time user edits post, update timestamp existing paragraphs. easy spot deleted paragraphs.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -