ALTER TABLE contact_preferences ADD COLUMN pinned boolean NOT NULL DEFAULT false; ALTER TABLE device_envelopes ADD COLUMN counts_as_unread boolean NOT NULL DEFAULT false; CREATE INDEX device_envelopes_unread ON device_envelopes(recipient_device, sender_device, sequence) WHERE counts_as_unread; CREATE TABLE device_contact_seen ( recipient_device uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE, sender_device uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE, sequence bigint NOT NULL CHECK (sequence > 0), PRIMARY KEY (recipient_device, sender_device), CHECK (recipient_device <> sender_device) );