pub(crate) mod sql {
pub(crate) const INSERT_NEW: &str = r#"INSERT INTO arcature_notifications
(id, notifiable_key, kind, data, created_at)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (id) DO NOTHING"#;
pub(crate) const LIST: &str = r#"SELECT id, kind, data, read_at, created_at
FROM arcature_notifications
WHERE notifiable_key = $1
ORDER BY created_at DESC, id
LIMIT $2"#;
pub(crate) const LIST_UNREAD: &str = r#"SELECT id, kind, data, read_at, created_at
FROM arcature_notifications
WHERE notifiable_key = $1 AND read_at IS NULL
ORDER BY created_at DESC, id
LIMIT $2"#;
pub(crate) const COUNT_UNREAD: &str =
"SELECT COUNT(*) FROM arcature_notifications WHERE notifiable_key = $1 AND read_at IS NULL";
pub(crate) const MARK_READ: &str = r#"UPDATE arcature_notifications
SET read_at = $1
WHERE notifiable_key = $2 AND id = $3 AND read_at IS NULL"#;
pub(crate) const MARK_ALL_READ: &str = r#"UPDATE arcature_notifications
SET read_at = $1
WHERE notifiable_key = $2 AND read_at IS NULL"#;
pub(crate) const DELETE: &str =
"DELETE FROM arcature_notifications WHERE notifiable_key = $1 AND id = $2";
pub(crate) const DELETE_ALL: &str =
"DELETE FROM arcature_notifications WHERE notifiable_key = $1";
pub(crate) const DELETE_READ_BEFORE: &str =
"DELETE FROM arcature_notifications WHERE read_at IS NOT NULL AND read_at < $1";
pub(crate) const CREATE_HISTORY: &str = r#"CREATE TABLE IF NOT EXISTS arcature_notifications_schema_migrations (
version TEXT PRIMARY KEY,
applied_at TIMESTAMPTZ NOT NULL DEFAULT now()
)"#;
pub(crate) const COUNT_APPLIED: &str =
"SELECT COUNT(*) FROM arcature_notifications_schema_migrations WHERE version = $1";
pub(crate) const RECORD_APPLIED: &str = "INSERT INTO arcature_notifications_schema_migrations (version) VALUES ($1) ON CONFLICT DO NOTHING";
pub(crate) const LOCK: Option<&str> = Some("SELECT pg_advisory_lock(71420006)");
pub(crate) const UNLOCK: Option<&str> = Some("SELECT pg_advisory_unlock(71420006)");
pub(crate) const SCHEMA: &str = include_str!("../migrations/postgres/0001_notifications.sql");
}