APNS MySQL Tables

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

Before you get started: You can download this source code here.

NOTE: If you do not have full database privileges, you will need to use our alternate database file. You will NOT need the `apns_device_history` table as it will no longer be used, so you can ignore the instructions below. See Installation: MySQL Database for further information.

There are only three tables you need to create to get Easy APNs up and running. `apns_device_history` is an optional table that should only be installed if you have full database privileges.

Table 1: apns_device_history (optional)

This table keeps track of each time an app is launched. This particular table only gets populated when a device already exists in the apns_devices table. With this data, you can keep track of when the user turned on/off notifications, how often then launch the app... etc. Pretty handy to have in our opinion.

1 CREATE TABLE `apns_device_history` (
2   `pid` int(9) unsigned NOT NULL auto_increment,
3   `appname` varchar(255) NOT NULL,
4   `appversion` varchar(25) default NULL,
5   `deviceuid` char(40) NOT NULL,
6   `devicetoken` char(64) NOT NULL,
7   `devicename` varchar(255) NOT NULL,
8   `devicemodel` varchar(100) NOT NULL,
9   `deviceversion` varchar(25) NOT NULL,
10   `pushbadge` enum('disabled','enabled') default 'disabled',
11   `pushalert` enum('disabled','enabled') default 'disabled',
12   `pushsound` enum('disabled','enabled') default 'disabled',
13   `development` enum('production','sandbox') character set latin1 NOT NULL default 'production',
14   `status` enum('active','uninstalled') NOT NULL default 'active',
15   `archived` datetime NOT NULL,
16   PRIMARY KEY  (`pid`),
17   KEY `devicetoken` (`devicetoken`),
18   KEY `devicename` (`devicename`),
19   KEY `devicemodel` (`devicemodel`),
20   KEY `deviceversion` (`deviceversion`),
21   KEY `pushbadge` (`pushbadge`),
22   KEY `pushalert` (`pushalert`),
23   KEY `pushsound` (`pushsound`),
24   KEY `development` (`development`),
25   KEY `status` (`status`),
26   KEY `appname` (`appname`),
27   KEY `appversion` (`appversion`),
28   KEY `deviceuid` (`deviceuid`),
29   KEY `archived` (`archived`)
30 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Store unique device history';

Table 2: apns_devices (lines 31-48 optional)

This table keeps track of all unique devices registering for push notifications. We also keep track of the applications name and version number in case you are running multiple apps, you can see who is using what.

1 CREATE TABLE `apns_devices` (
2   `pid` int(9) unsigned NOT NULL auto_increment,
3   `appname` varchar(255) NOT NULL,
4   `appversion` varchar(25) default NULL,
5   `deviceuid` char(40) NOT NULL,
6   `devicetoken` char(64) NOT NULL,
7   `devicename` varchar(255) NOT NULL,
8   `devicemodel` varchar(100) NOT NULL,
9   `deviceversion` varchar(25) NOT NULL,
10   `pushbadge` enum('disabled','enabled') default 'disabled',
11   `pushalert` enum('disabled','enabled') default 'disabled',
12   `pushsound` enum('disabled','enabled') default 'disabled',
13   `development` enum('production','sandbox') character set latin1 NOT NULL default 'production',
14   `status` enum('active','uninstalled') NOT NULL default 'active',
15   `created` datetime NOT NULL,
16   `modified` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,
17   PRIMARY KEY  (`pid`),
18   UNIQUE KEY `appname` (`appname`,`appversion`,`deviceuid`),
19   KEY `devicetoken` (`devicetoken`),
20   KEY `devicename` (`devicename`),
21   KEY `devicemodel` (`devicemodel`),
22   KEY `deviceversion` (`deviceversion`),
23   KEY `pushbadge` (`pushbadge`),
24   KEY `pushalert` (`pushalert`),
25   KEY `pushsound` (`pushsound`),
26   KEY `development` (`development`),
27   KEY `status` (`status`),
28   KEY `created` (`created`),
29   KEY `modified` (`modified`)
30 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Store unique devices';
31 DELIMITER ;;
32 CREATE TRIGGER `Archive` BEFORE UPDATE ON `apns_devices` FOR EACH ROW INSERT INTO `apns_device_history` VALUES (
33     NULL,
34     OLD.`appname`,
35     OLD.`appversion`,
36     OLD.`deviceuid`,
37     OLD.`devicetoken`,
38     OLD.`devicename`,
39     OLD.`devicemodel`,
40     OLD.`deviceversion`,
41     OLD.`pushbadge`,
42     OLD.`pushalert`,
43     OLD.`pushsound`,
44     OLD.`development`,
45     OLD.`status`,
46     NOW()
47 );;
48 DELIMITER ;

Table 3: apns_messages

This is where the messages you send to the user will go. By default, Easy APNs is setup to store the messages in queue and not actually deliver them until instructed elsewhere. This is where you would setup a cron job to process the data that still needs to be delivered.

1 CREATE TABLE `apns_messages` (
2   `pid` int(9) unsigned NOT NULL auto_increment,
3   `fk_device` int(9) unsigned NOT NULL,
4   `message` varchar(255) NOT NULL,
5   `delivery` datetime NOT NULL,
6   `status` enum('queued','delivered','failed') character set latin1 NOT NULL default 'queued',
7   `created` datetime NOT NULL,
8   `modified` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,
9   PRIMARY KEY  (`pid`),
10   KEY `fk_device` (`fk_device`),
11   KEY `status` (`status`),
12   KEY `created` (`created`),
13   KEY `modified` (`modified`),
14   KEY `message` (`message`),
15   KEY `delivery` (`delivery`)
16 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Messages to push to APNS';
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
SQL 关系型数据库 MySQL
mysql中lock tables与unlock tables(锁表/解锁)使用总结
mysql中lock tables与unlock tables(锁表/解锁)使用总结
280 0
|
关系型数据库 MySQL 测试技术
MySQL中lock tables和unlock tables浅析
MySQL中lock tables和unlock tables浅析   在MySQL中提供了锁定表(lock tables)和解锁表(unlock tables)的语法功能,ORACLE与SQL Server数据库当中没有这种语法。
1520 0
|
关系型数据库 MySQL 数据库
|
数据库 关系型数据库 MySQL
|
关系型数据库 数据库 MySQL
MySQL LOCK TABLES 与UNLOCK TABLES
1语法 LOCK TABLES tbl_name[[AS] alias] lock_type [, tbl_name [[AS] alias] lock_type] ... lock_type:READ[LOCAL]| [LOW_PRIORITY] WRITE UNLOCK TABLES 2简单使用 一个session只能为自己获取锁和释放锁,不能为其他session获取锁,也不能释放由其他session保持的锁。
834 0
|
11天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)
|
1月前
|
关系型数据库 MySQL 数据库连接
关于MySQL-ODBC的zip包安装方法
关于MySQL-ODBC的zip包安装方法
|
29天前
|
关系型数据库 MySQL 数据库
rds安装数据库客户端工具
安装阿里云RDS的数据库客户端涉及在本地安装对应类型(如MySQL、PostgreSQL)的客户端工具。对于MySQL,可选择MySQL Command-Line Client或图形化工具如Navicat,安装后输入RDS实例的连接参数进行连接。对于PostgreSQL,可以使用`psql`命令行工具或图形化客户端如PgAdmin。首先从阿里云控制台获取连接信息,然后按照官方文档安装客户端,最后配置客户端连接以确保遵循安全指引。
82 1