diff options
Diffstat (limited to 'app/Schema/Postgres.php')
-rw-r--r-- | app/Schema/Postgres.php | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index f7263e75..d55297a9 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -6,7 +6,42 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 68; +const VERSION = 69; + +function version_69($pdo) +{ + $pdo->exec(" + CREATE TABLE user_has_unread_notifications ( + id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL, + date_creation BIGINT NOT NULL, + event_name VARCHAR(50) 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 SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL, + notification_type VARCHAR(50), + 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_68($pdo) { |