diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 59da11a92..6dcb990e3 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -1329,6 +1329,24 @@ CREATE TABLE `Events_Tags` ( CONSTRAINT `Events_Tags_ibfk_2` FOREIGN KEY (`EventId`) REFERENCES `Events` (`Id`) ON DELETE CASCADE ) ENGINE=@ZM_MYSQL_ENGINE@; +CREATE TABLE `Notifications` ( + `Id` int unsigned NOT NULL AUTO_INCREMENT, + `UserId` int unsigned NOT NULL, + `Token` varchar(512) NOT NULL, + `Platform` enum('android','ios','web') NOT NULL, + `MonitorList` text DEFAULT NULL, + `Interval` int unsigned NOT NULL DEFAULT 0, + `PushState` enum('enabled','disabled') NOT NULL DEFAULT 'enabled', + `AppVersion` varchar(32) DEFAULT NULL, + `BadgeCount` int NOT NULL DEFAULT 0, + `LastNotifiedAt` datetime DEFAULT NULL, + `CreatedOn` datetime DEFAULT NULL, + `UpdatedOn` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`Id`), + UNIQUE KEY `Notifications_Token_idx` (`Token`), + KEY `Notifications_UserId_idx` (`UserId`) +) ENGINE=@ZM_MYSQL_ENGINE@; + source @PKGDATADIR@/db/Object_Types.sql -- We generally don't alter triggers, we drop and re-create them, so let's keep them in a separate file that we can just source in update scripts. source @PKGDATADIR@/db/triggers.sql diff --git a/db/zm_update-1.39.2.sql b/db/zm_update-1.39.2.sql new file mode 100644 index 000000000..dbe5482a8 --- /dev/null +++ b/db/zm_update-1.39.2.sql @@ -0,0 +1,30 @@ +-- +-- Add Notifications table for FCM push token registration +-- + +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'Notifications' + AND table_schema = DATABASE()) > 0, + "SELECT 'Notifications table already exists'", + "CREATE TABLE `Notifications` ( + `Id` int unsigned NOT NULL AUTO_INCREMENT, + `UserId` int unsigned NOT NULL, + `Token` varchar(512) NOT NULL, + `Platform` enum('android','ios','web') NOT NULL, + `MonitorList` text DEFAULT NULL, + `Interval` int unsigned NOT NULL DEFAULT 0, + `PushState` enum('enabled','disabled') NOT NULL DEFAULT 'enabled', + `AppVersion` varchar(32) DEFAULT NULL, + `BadgeCount` int NOT NULL DEFAULT 0, + `LastNotifiedAt` datetime DEFAULT NULL, + `CreatedOn` datetime DEFAULT NULL, + `UpdatedOn` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`Id`), + UNIQUE KEY `Notifications_Token_idx` (`Token`), + KEY `Notifications_UserId_idx` (`UserId`) + ) ENGINE=InnoDB" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; +DEALLOCATE PREPARE stmt;