github.com/mmrath/gobase@v0.0.1/apps/db_migration/resources/migrations/10001_notification/up.sql (about) 1 CREATE TABLE notification ( 2 id BIGSERIAL, 3 created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, 4 subject TEXT NOT NULL, 5 notification_type TEXT NOT NULL, 6 from_address TEXT NULL, 7 body_html TEXT NULL, 8 body_plain_text TEXT NULL, 9 CONSTRAINT pk_notification PRIMARY KEY (id), 10 CHECK (body_html IS NOT NULL OR body_plain_text IS NOT NULL) 11 ); 12 13 CREATE TABLE notification_recipient ( 14 id BIGSERIAL , 15 notification_id BIGINT NOT NULL, 16 recipient_type TEXT NOT NULL, 17 name TEXT, 18 address TEXT NOT NULL, 19 CONSTRAINT pk_notification_recipient PRIMARY KEY (id), 20 CONSTRAINT fk_notification_recipient__notification FOREIGN KEY (notification_id) REFERENCES notification (id) 21 ); 22 23 24 CREATE TABLE notification_attachment ( 25 id BIGSERIAL, 26 notification_id BIGINT NOT NULL, 27 name TEXT NOT NULL, 28 data BYTEA NOT NULL, 29 CONSTRAINT pk_notification_attachment PRIMARY KEY (id), 30 CONSTRAINT fk_notification_attachment__notification FOREIGN KEY (notification_id) REFERENCES notification (id) 31 );