From d67d7c54e65e80d1b484490e42dbecb969aa7686 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 3 Oct 2015 12:09:27 -0400 Subject: Add web notifications --- app/Schema/Sqlite.php | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'app/Schema/Sqlite.php') diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 064d0f3c..633c90a7 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -6,7 +6,42 @@ use Core\Security; use PDO; use Model\Link; -const VERSION = 84; +const VERSION = 85; + +function version_85($pdo) +{ + $pdo->exec(" + CREATE TABLE user_has_unread_notifications ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + date_creation INTEGER NOT NULL, + event_name TEXT NOT NULL, + event_data TEXT NOT NULL, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) + "); + + $pdo->exec(" + CREATE TABLE user_has_notification_types ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + notification_type TEXT, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) + "); + + $pdo->exec('CREATE UNIQUE INDEX user_has_notification_types_user_idx ON user_has_notification_types(user_id, notification_type)'); + + // Migrate people who have notification enabled before + $rq = $pdo->prepare('SELECT id FROM users WHERE notifications_enabled=1'); + $rq->execute(); + $user_ids = $rq->fetchAll(PDO::FETCH_COLUMN, 0); + + foreach ($user_ids as $user_id) { + $rq = $pdo->prepare('INSERT INTO user_has_notification_types (user_id, notification_type) VALUES (?, ?)'); + $rq->execute(array($user_id, 'email')); + } +} function version_84($pdo) { -- cgit v1.2.3