drink-it-cold/sql/migrations/002_push_subscriptions.sql

35 lines
1.5 KiB
MySQL
Raw Permalink Normal View History

-- Web-Push-Abos (VAPID) und Versandprotokoll für Kühlwagen-Erinnerungen.
-- Idempotent: kann auch auf einer bestehenden Installation ausgeführt werden.
CREATE TABLE IF NOT EXISTS push_subscriptions (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id BIGINT UNSIGNED NOT NULL,
endpoint VARCHAR(1000) NOT NULL,
endpoint_hash CHAR(64) NOT NULL,
p256dh VARCHAR(120) NOT NULL,
auth VARCHAR(40) NOT NULL,
user_agent VARCHAR(255) NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
last_success_at DATETIME NULL,
last_error VARCHAR(255) NULL,
PRIMARY KEY (id),
UNIQUE KEY uq_push_endpoint (endpoint_hash),
KEY idx_push_user (user_id, updated_at),
CONSTRAINT fk_push_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS reminder_push_log (
booking_id BIGINT UNSIGNED NOT NULL,
kind ENUM('start_8', 'start_1', 'end_1') NOT NULL,
due_date DATE NOT NULL,
employee_id BIGINT UNSIGNED NULL,
user_id BIGINT UNSIGNED NULL,
sent_at DATETIME NOT NULL,
PRIMARY KEY (booking_id, kind, due_date),
KEY idx_reminder_push_due (due_date),
CONSTRAINT fk_reminder_push_booking FOREIGN KEY (booking_id) REFERENCES bookings (id) ON DELETE CASCADE,
CONSTRAINT fk_reminder_push_employee FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE SET NULL,
CONSTRAINT fk_reminder_push_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;