pub(crate) mod sql {
pub(crate) const INSERT_NEW: &str = r#"INSERT IGNORE INTO arcature_notifications
(id, notifiable_key, kind, data, created_at)
VALUES (?, ?, ?, ?, ?)"#;
pub(crate) const LIST: &str = r#"SELECT id, kind, data, read_at, created_at
FROM arcature_notifications
WHERE notifiable_key = ?
ORDER BY created_at DESC, id
LIMIT ?"#;
pub(crate) const LIST_UNREAD: &str = r#"SELECT id, kind, data, read_at, created_at
FROM arcature_notifications
WHERE notifiable_key = ? AND read_at IS NULL
ORDER BY created_at DESC, id
LIMIT ?"#;
pub(crate) const COUNT_UNREAD: &str =
"SELECT COUNT(*) FROM arcature_notifications WHERE notifiable_key = ? AND read_at IS NULL";
pub(crate) const MARK_READ: &str = r#"UPDATE arcature_notifications
SET read_at = ?
WHERE notifiable_key = ? AND id = ? AND read_at IS NULL"#;
pub(crate) const MARK_ALL_READ: &str = r#"UPDATE arcature_notifications
SET read_at = ?
WHERE notifiable_key = ? AND read_at IS NULL"#;
pub(crate) const DELETE: &str =
"DELETE FROM arcature_notifications WHERE notifiable_key = ? AND id = ?";
pub(crate) const DELETE_ALL: &str =
"DELETE FROM arcature_notifications WHERE notifiable_key = ?";
pub(crate) const DELETE_READ_BEFORE: &str =
"DELETE FROM arcature_notifications WHERE read_at IS NOT NULL AND read_at < ?";
pub(crate) const CREATE_HISTORY: &str = r#"CREATE TABLE IF NOT EXISTS arcature_notifications_schema_migrations (
version VARCHAR(191) NOT NULL PRIMARY KEY,
applied_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"#;
pub(crate) const COUNT_APPLIED: &str =
"SELECT COUNT(*) FROM arcature_notifications_schema_migrations WHERE version = ?";
pub(crate) const RECORD_APPLIED: &str =
"INSERT IGNORE INTO arcature_notifications_schema_migrations (version) VALUES (?)";
pub(crate) const LOCK: Option<&str> =
Some("SELECT GET_LOCK('arcature_notifications_migrate', 10)");
pub(crate) const UNLOCK: Option<&str> =
Some("SELECT RELEASE_LOCK('arcature_notifications_migrate')");
pub(crate) const SCHEMA: &str = include_str!("../migrations/mysql/0001_notifications.sql");
}