Recommendations for autosaving drafts?

What is the best strategy for apps that autosave emails before they are sent or keep a blog post until they are completed or officially saved? Would it be better to use a separate table in the database for temporary projects or have a status column that marks the post as a project or is published? I'm not looking for code, just methods, but any other related tips are also welcome, like how often to save, etc.

+5
source share
3 answers

Given that separate tables for drafts and published articles will be essentially duplicated from each other, I am inclined to the same table with a status column to distinguish between the two.

+2

: ( ) . . - - .

, , ( ) / .

+2

...

. - is_draft , . , , ( , ). , , , ?

is_draft = 1, ORM, , . , , , .

: . . set is_draft = 1 . . "" -:)

. . . set is_draft = 0. .

, , , /, .


, . , , , , .

- ( ). php serialize() - , json. , ( - ) :

sql:

create table draft  
id int primary key auto increment,  
entity varchar(64) not null comment 'this way you can find all drafts of say type Email',  
contents longblob not null,  
modified timestamp comment 'this way you can sort by newer drafts'  
modified_by int not null foreign key to user.id comment 'this way you can filter by the user\ drafts'

draft_file :

create table draft_file  
id int primary key auto increment,   
draft_id int not null foreign key to draft.id on delete cascade,  
size int not null comment 'bytes',  
mime_type varchar(64) not null,  
file_name varchar(255) not null,  
contents longblob,  
thumbnail blob comment 'this could be an icon for files/documents' 

, , , . gui , draft_file id, URL- , gui.

(To ). gui , id, .

"". , draft_file email_attachment , .

this allows you to use long-term drafts, add attachments in the gmail style, while maintaining the integrity of your real entity table.

+1
source

All Articles