Database design for email messaging system

后端 未结 9 879
情书的邮戳
情书的邮戳 2021-01-29 22:58

I want to make an email messaging system like gmail have. I would like to have following option: Starred, Trash, Spam, Draft, Read, Unread. Right now I have the below following

相关标签:
9条回答
  • 2021-01-29 23:48
    CREATE TABLE `mails` (  
      `message_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,  
      `message` varchar(10000) NOT NULL DEFAULT '',  
      `file` longblob,  
      `mailingdate` varchar(40) DEFAULT NULL,  
      `starred_status` int(10) unsigned NOT NULL DEFAULT '0',  
      `sender_email` varchar(200) NOT NULL DEFAULT '',  
      `reciever_email` varchar(200) NOT NULL DEFAULT '',  
      `inbox_status` int(10) unsigned NOT NULL DEFAULT '0',   
      `sent_status` int(10) unsigned NOT NULL DEFAULT '0',  
      `draft_status` int(10) unsigned NOT NULL DEFAULT '0',  
      `trash_status` int(10) unsigned NOT NULL DEFAULT '0',  
      `subject` varchar(200) DEFAULT NULL,  
      `read_status` int(10) unsigned NOT NULL DEFAULT '0',  
      `delete_status` int(10) unsigned NOT NULL DEFAULT '0',  
      PRIMARY KEY (`message_id`)  
    )
    

    You can use this table for storing the mails and manipulate the queries according to mail boxes. I am avoiding rest of the tables like user details and login details table. You can make them according to your need.

    0 讨论(0)
  • 2021-01-29 23:53

    If you're doing document-orientated work, I suggest taking a look at CouchDB. It is schema-less, meaning issues like this disappear.

    Let's take a look at the example: A sends a message to B, and it's deleted by B.

    You would have a single instance of the document, with recipients listed as an attribute of the email. As users delete messages, you either remove them from the recipients list or add them to a list of deleted_by or whatever you choose.

    It's a much different approach to data than what you're used to, but may be highly beneficial to take some time to consider.

    0 讨论(0)
  • 2021-01-29 23:55

    If I were you I would set two flags one for sender and other one for receiver if both flags are true then message should be deleted from database otherwise keep that in database but hide it from who deleted it.

    Do same thing for trash. You may want to run cron or check manually if both sender and receiver delete the message then remove it from database.

    0 讨论(0)
提交回复
热议问题