CREATE DATABASE IF NOT EXISTS `apns_mobilemail` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `apns_mobilemail`;

CREATE TABLE IF NOT EXISTS `devices` (
  `id` int(11) NOT NULL COMMENT 'entry id',
  `aps_account_id` varchar(36) NOT NULL COMMENT 'APNS Account Id',
  `aps_device_token` varchar(64) NOT NULL COMMENT 'APNS Device Token',
  `last_registration` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last time account/device registered'
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='List of registered accounts and devices';

CREATE TABLE IF NOT EXISTS `mailboxes` (
  `id` int(11) NOT NULL COMMENT 'entry id',
  `device` int(11) NOT NULL COMMENT 'Associated account/device',
  `user` varchar(256) NOT NULL COMMENT 'Mailbox owner',
  `mailbox` varchar(256) NOT NULL COMMENT 'Mailbox name'
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='List of subscribed mailboxes';

ALTER TABLE `devices`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `mailboxes`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `devices`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'entry id';

ALTER TABLE `mailboxes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'entry id';
