-- In-app notifications (issue #94); mailed_at prepares the #95 digests. CREATE TABLE "notifications" ( "id" TEXT NOT NULL, "user_id" TEXT NOT NULL, "type" TEXT NOT NULL, "payload" JSONB NOT NULL, "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "read_at" TIMESTAMP(3), "mailed_at" TIMESTAMP(3), CONSTRAINT "notifications_pkey" PRIMARY KEY ("id") ); CREATE INDEX "notifications_user_id_read_at_created_at_idx" ON "notifications"("user_id", "read_at", "created_at"); ALTER TABLE "notifications" ADD CONSTRAINT "notifications_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;