@@ -295,21 +295,26 @@ CREATE TABLE thread
295
295
-- Each message has both a text_body (plain text) and body (formatted/rich text).
296
296
CREATE TABLE message
297
297
(
298
- message_id VARCHAR (255 ) NOT NULL , -- Unique identifier for the message
299
- thread_id VARCHAR (255 ) NOT NULL , -- Thread this message belongs to
300
- text_body TEXT NOT NULL , -- Plain text content of the message
301
- markdown_body TEXT NOT NULL , -- Rich text/formatted content of the message
302
- html_body TEXT NOT NULL , -- Rich text/formatted html content of the message
303
- customer_id VARCHAR (255 ) NULL , -- Customer who sent the message (if from customer)
304
- member_id VARCHAR (255 ) NULL , -- Member who sent the message (if from member)
305
- channel VARCHAR (255 ) NOT NULL , -- Communication channel used (email, chat, etc)
306
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
307
- updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
308
-
298
+ message_id VARCHAR (255 ) NOT NULL , -- Unique identifier for the message
299
+ thread_id VARCHAR (255 ) NOT NULL , -- Thread this message belongs to
300
+ text_body TEXT NOT NULL , -- Plain text content of the message
301
+ markdown_body TEXT NOT NULL , -- Rich text/formatted content of the message
302
+ html_body TEXT NOT NULL , -- Rich text/formatted HTML content of the message
303
+ customer_id VARCHAR (255 ) NULL , -- Customer who sent the message (if from customer)
304
+ member_id VARCHAR (255 ) NULL , -- Member who sent the message (if from member)
305
+ channel VARCHAR (255 ) NOT NULL , -- Communication channel used (email, chat, etc)
306
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP , -- Timestamp when the message was created
307
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP , -- Timestamp when the message was last updated
308
+
309
+ -- Defining the primary key for the table
309
310
CONSTRAINT message_message_id_pkey PRIMARY KEY (message_id),
311
+
312
+ -- Foreign key constraints
310
313
CONSTRAINT message_thread_id_fkey FOREIGN KEY (thread_id) REFERENCES thread (thread_id),
311
314
CONSTRAINT message_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES customer (customer_id),
312
315
CONSTRAINT message_member_id_fkey FOREIGN KEY (member_id) REFERENCES member (member_id),
316
+
317
+ -- Check constraint to enforce valid sender (only one of customer_id or member_id can be set)
313
318
CONSTRAINT message_sender_check CHECK (
314
319
(customer_id IS NULL AND member_id IS NOT NULL ) OR
315
320
(customer_id IS NOT NULL AND member_id IS NULL )
@@ -327,7 +332,7 @@ CREATE TABLE message_attachment
327
332
spam BOOLEAN NOT NULL DEFAULT FALSE,
328
333
has_error BOOLEAN NOT NULL DEFAULT FALSE,
329
334
error TEXT NOT NULL ,
330
- md5_has VARCHAR (511 ) NOT NULL ,
335
+ md5_hash VARCHAR (511 ) NOT NULL ,
331
336
created_at timestamp DEFAULT CURRENT_TIMESTAMP ,
332
337
updated_at timestamp DEFAULT CURRENT_TIMESTAMP ,
333
338
0 commit comments