···11+-- This script should be used and updated whenever a new notification type
22+-- constraint needs to be added.
33+44+BEGIN TRANSACTION;
55+66+ALTER TABLE notifications RENAME TO notifications_old;
77+88+CREATE TABLE notifications (
99+ id INTEGER PRIMARY KEY AUTOINCREMENT,
1010+ recipient_did TEXT NOT NULL,
1111+ actor_did TEXT NOT NULL,
1212+ subject_uri TEXT NOT NULL,
1313+ state TEXT NOT NULL DEFAULT 'unread' CHECK(state IN ('unread', 'read')),
1414+ type TEXT NOT NULL CHECK(type IN ('follow', 'reaction', 'comment')),
1515+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
1616+ FOREIGN KEY (recipient_did) REFERENCES profiles(did) ON DELETE CASCADE,
1717+ FOREIGN KEY (actor_did) REFERENCES profiles(did) ON DELETE CASCADE
1818+);
1919+2020+INSERT INTO notifications (id, recipient_did, actor_did, subject_uri, state, type, created_at)
2121+SELECT id, recipient_did, actor_did, subject_uri, state, type, created_at
2222+FROM notifications_old;
2323+2424+DROP TABLE notifications_old;
2525+2626+COMMIT;