2011-12-30 15:52:59 +01:00
|
|
|
create database if not exists `piler` character set 'utf8';
|
2011-12-07 15:24:52 +01:00
|
|
|
use `piler`;
|
|
|
|
|
|
|
|
|
2011-11-14 15:57:52 +01:00
|
|
|
drop table if exists `sph_counter`;
|
2011-12-05 17:18:03 +01:00
|
|
|
create table if not exists `sph_counter` (
|
2011-11-14 15:57:52 +01:00
|
|
|
`counter_id` int not null,
|
|
|
|
`max_doc_id` int not null,
|
|
|
|
primary key (`counter_id`)
|
|
|
|
);
|
|
|
|
|
2011-12-07 15:24:52 +01:00
|
|
|
|
2011-11-14 15:57:52 +01:00
|
|
|
drop table if exists `sph_index`;
|
2011-12-05 17:18:03 +01:00
|
|
|
create table if not exists `sph_index` (
|
2011-12-03 23:05:00 +01:00
|
|
|
`id` bigint not null,
|
2011-11-14 15:57:52 +01:00
|
|
|
`from` char(255) default null,
|
2012-02-02 15:29:07 +01:00
|
|
|
`to` text(8192) default null,
|
2012-01-14 09:53:26 +01:00
|
|
|
`fromdomain` char(255) default null,
|
|
|
|
`todomain` text(512) default null,
|
2011-11-14 15:57:52 +01:00
|
|
|
`subject` text(512) default null,
|
|
|
|
`arrived` int not null,
|
|
|
|
`sent` int not null,
|
|
|
|
`body` text,
|
|
|
|
`size` int default '0',
|
2012-01-03 00:19:43 +01:00
|
|
|
`direction` int default 0,
|
2011-11-28 14:21:14 +01:00
|
|
|
`attachments` int default 0,
|
2011-12-30 15:52:59 +01:00
|
|
|
`attachment_types` text(512) default null,
|
2011-11-14 15:57:52 +01:00
|
|
|
primary key (`id`)
|
|
|
|
) Engine=InnoDB;
|
|
|
|
|
2011-11-28 14:21:14 +01:00
|
|
|
|
2011-11-14 15:57:52 +01:00
|
|
|
drop table if exists `metadata`;
|
2011-12-05 17:18:03 +01:00
|
|
|
create table if not exists `metadata` (
|
2011-11-14 15:57:52 +01:00
|
|
|
`id` bigint unsigned not null auto_increment,
|
|
|
|
`from` char(255) not null,
|
2012-01-09 23:15:39 +01:00
|
|
|
`fromdomain` char(48) not null,
|
2011-11-14 15:57:52 +01:00
|
|
|
`subject` text(512) default null,
|
2012-01-26 14:35:51 +01:00
|
|
|
`spam` tinyint(1) default 0,
|
2011-11-14 15:57:52 +01:00
|
|
|
`arrived` int not null,
|
|
|
|
`sent` int not null,
|
2011-12-13 17:05:22 +01:00
|
|
|
`deleted` tinyint(1) default 0,
|
2011-11-14 15:57:52 +01:00
|
|
|
`size` int default 0,
|
|
|
|
`hlen` int default 0,
|
2012-01-03 00:19:43 +01:00
|
|
|
`direction` int default 0,
|
2011-11-22 12:31:54 +01:00
|
|
|
`attachments` int default 0,
|
2011-11-14 15:57:52 +01:00
|
|
|
`piler_id` char(36) not null,
|
|
|
|
`message_id` char(128) character set 'latin1' not null,
|
2012-02-10 13:57:04 +01:00
|
|
|
`reference` char(64) character set 'latin1' not null,
|
2011-11-22 12:31:54 +01:00
|
|
|
`digest` char(64) not null,
|
2011-11-14 15:57:52 +01:00
|
|
|
`bodydigest` char(64) not null,
|
2012-01-09 23:15:39 +01:00
|
|
|
`vcode` char(64) default null,
|
2011-11-30 23:42:15 +01:00
|
|
|
primary key (`id`), unique(`message_id`)
|
2011-11-14 15:57:52 +01:00
|
|
|
) Engine=InnoDB;
|
|
|
|
|
|
|
|
create index metadata_idx on metadata(`piler_id`);
|
|
|
|
create index metadata_idx2 on metadata(`message_id`);
|
2012-02-08 23:14:28 +01:00
|
|
|
create index metadata_idx3 on metadata(`reference`);
|
|
|
|
create index metadata_idx4 on metadata(`bodydigest`);
|
|
|
|
create index metadata_idx5 on metadata(`deleted`);
|
|
|
|
create index metadata_idx6 on metadata(`arrived`);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
2011-12-03 23:05:00 +01:00
|
|
|
|
|
|
|
drop table if exists `rcpt`;
|
2011-12-05 17:18:03 +01:00
|
|
|
create table if not exists `rcpt` (
|
2011-12-03 23:05:00 +01:00
|
|
|
`id` bigint unsigned not null,
|
|
|
|
`to` char(64) not null,
|
2012-01-09 23:15:39 +01:00
|
|
|
`todomain` char(48) not null,
|
2011-12-03 23:05:00 +01:00
|
|
|
unique(`id`,`to`)
|
|
|
|
) Engine=InnoDB;
|
|
|
|
|
|
|
|
create index `rcpt_idx` on `rcpt`(`id`);
|
|
|
|
create index `rcpt_idx2` on `rcpt`(`to`);
|
|
|
|
|
|
|
|
|
2011-12-05 17:18:03 +01:00
|
|
|
drop view if exists `messages`;
|
2012-01-09 23:15:39 +01:00
|
|
|
create view `messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`metadata`.`fromdomain` AS `fromdomain`,`rcpt`.`to` AS `to`,`rcpt`.`todomain` AS `todomain`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`direction` AS `direction`, `metadata`.`sent` AS `sent`, `metadata`.`digest` AS `digest`, `metadata`.`bodydigest` AS `bodydigest` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`);
|
2012-01-07 23:26:47 +01:00
|
|
|
|
2011-12-05 17:18:03 +01:00
|
|
|
|
2011-11-19 21:25:44 +01:00
|
|
|
drop table if exists `attachment`;
|
2011-12-05 17:18:03 +01:00
|
|
|
create table if not exists `attachment` (
|
2011-11-19 21:25:44 +01:00
|
|
|
`id` bigint unsigned not null auto_increment,
|
|
|
|
`piler_id` char(36) not null,
|
|
|
|
`attachment_id` int not null,
|
2011-11-28 14:21:14 +01:00
|
|
|
`name` char(64) default null,
|
|
|
|
`type` char(72) default null,
|
2011-11-19 21:25:44 +01:00
|
|
|
`sig` char(64) not null,
|
2011-11-23 12:24:21 +01:00
|
|
|
`size` int default 0,
|
2011-11-19 21:25:44 +01:00
|
|
|
`ptr` int default 0,
|
2011-12-19 23:11:40 +01:00
|
|
|
`deleted` tinyint(1) default 0,
|
2011-11-19 21:25:44 +01:00
|
|
|
primary key (`id`)
|
|
|
|
) Engine=InnoDB;
|
|
|
|
|
|
|
|
create index `attachment_idx` on `attachment`(`piler_id`);
|
|
|
|
create index `attachment_idx2` on `attachment`(`sig`);
|
|
|
|
|
2011-12-03 23:05:00 +01:00
|
|
|
|
2011-12-05 17:18:03 +01:00
|
|
|
drop table if exists `tag`;
|
|
|
|
create table if not exists `tag` (
|
|
|
|
`id` bigint not null unique,
|
2011-12-06 11:29:36 +01:00
|
|
|
`uid` int not null,
|
2011-12-05 17:18:03 +01:00
|
|
|
`tag` char(255) default null
|
2011-12-06 11:29:36 +01:00
|
|
|
) ENGINE=InnoDB;
|
2011-12-05 17:18:03 +01:00
|
|
|
|
|
|
|
|
2011-11-19 21:25:44 +01:00
|
|
|
drop table if exists `archiving_rule`;
|
2011-12-05 17:18:03 +01:00
|
|
|
create table if not exists `archiving_rule` (
|
2011-11-19 21:25:44 +01:00
|
|
|
`id` bigint unsigned not null auto_increment,
|
|
|
|
`from` char(128) default null,
|
|
|
|
`to` char(255) default null,
|
2011-11-22 14:25:51 +01:00
|
|
|
`subject` char(255) default null,
|
2011-11-19 21:25:44 +01:00
|
|
|
`_size` char(2) default null,
|
|
|
|
`size` int default 0,
|
2011-11-23 12:24:21 +01:00
|
|
|
`attachment_type` char(128) default null,
|
|
|
|
`_attachment_size` char(2) default null,
|
|
|
|
`attachment_size` int default 0,
|
2012-01-28 20:52:13 +01:00
|
|
|
primary key (`id`),
|
|
|
|
unique(`from`,`to`,`subject`,`_size`,`size`,`attachment_type`,`_attachment_size`,`attachment_size`)
|
2011-11-23 12:24:21 +01:00
|
|
|
) ENGINE=InnoDB;
|
2011-11-19 21:25:44 +01:00
|
|
|
|
2011-12-06 11:29:36 +01:00
|
|
|
|
|
|
|
drop table if exists `retention_rule`;
|
|
|
|
create table if not exists `retention_rule` (
|
|
|
|
`id` bigint unsigned not null auto_increment,
|
|
|
|
|
|
|
|
`subject` char(255) default null,
|
|
|
|
|
|
|
|
`days` int not null,
|
|
|
|
|
|
|
|
primary key (`id`)
|
|
|
|
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
|
|
|
|
|
2011-11-14 15:57:52 +01:00
|
|
|
drop table if exists `counter`;
|
|
|
|
create table if not exists `counter` (
|
|
|
|
`rcvd` bigint unsigned default 0,
|
|
|
|
`virus` bigint unsigned default 0,
|
2011-12-30 15:52:59 +01:00
|
|
|
`duplicate` bigint unsigned default 0,
|
2011-12-27 20:51:56 +01:00
|
|
|
`ignore` bigint unsigned default 0
|
2012-02-10 13:57:04 +01:00
|
|
|
`size` bigint unsigned default 0
|
2011-11-14 15:57:52 +01:00
|
|
|
) Engine=InnoDB;
|
|
|
|
|
2012-02-10 13:57:04 +01:00
|
|
|
insert into `counter` values(0, 0, 0, 0, 0);
|
2011-11-14 15:57:52 +01:00
|
|
|
|
2011-12-06 11:29:36 +01:00
|
|
|
|
2011-11-30 23:42:15 +01:00
|
|
|
drop table if exists `search`;
|
2011-12-05 17:18:03 +01:00
|
|
|
create table if not exists `search` (
|
2011-11-30 23:42:15 +01:00
|
|
|
`email` char(128) not null,
|
|
|
|
`ts` int default 0,
|
|
|
|
`term` text(512) not null
|
|
|
|
) Engine=InnoDB;
|
|
|
|
|
|
|
|
create index `search_idx` on `search`(`email`);
|
|
|
|
|
|
|
|
|
2011-12-19 23:11:40 +01:00
|
|
|
drop table if exists `user_settings`;
|
|
|
|
create table if not exists `user_settings` (
|
|
|
|
`username` char(64) not null unique,
|
|
|
|
`pagelen` int default 20,
|
|
|
|
`theme` char(8) default 'default',
|
|
|
|
`lang` char(2) default 'en'
|
|
|
|
);
|
|
|
|
|
|
|
|
create index `user_settings_idx` on `user_settings`(`username`);
|
|
|
|
|
2011-12-27 20:51:56 +01:00
|
|
|
|
2012-01-03 00:19:43 +01:00
|
|
|
drop table if exists `user`;
|
2011-12-27 20:51:56 +01:00
|
|
|
create table if not exists `user` (
|
|
|
|
`uid` int unsigned not null primary key,
|
|
|
|
`gid` int unsigned not null,
|
|
|
|
`username` char(64) not null unique,
|
|
|
|
`realname` char(64) default null,
|
|
|
|
`password` char(48) default null,
|
|
|
|
`domain` char(64) default null,
|
|
|
|
`dn` char(255) default '*',
|
|
|
|
`policy_group` int(4) default 0,
|
|
|
|
`isadmin` tinyint default 0
|
|
|
|
) Engine=InnoDB;
|
|
|
|
|
|
|
|
insert into `user` (`uid`, `gid`, `username`, `realname`, `password`, `policy_group`, `isadmin`, `domain`) values (0, 0, 'admin', 'built-in piler admin', '$1$PItc7d$zsUgON3JRrbdGS11t9JQW1', 0, 1, 'local');
|
|
|
|
|
2012-01-03 00:19:43 +01:00
|
|
|
drop table if exists `email`;
|
2011-12-27 20:51:56 +01:00
|
|
|
create table if not exists `email` (
|
|
|
|
`uid` int unsigned not null,
|
|
|
|
`email` char(128) not null primary key
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
|
|
|
|
insert into `email` (`uid`, `email`) values(0, 'admin@local');
|
|
|
|
|
|
|
|
|
|
|
|
create table if not exists `email_groups` (
|
|
|
|
`uid` int unsigned not null,
|
|
|
|
`gid` int unsigned not null,
|
|
|
|
unique key `uid` (`uid`,`gid`),
|
|
|
|
key `email_groups_idx` (`uid`,`gid`)
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
|
|
|
|
|
|
|
|
create table if not exists `remote` (
|
|
|
|
`remotedomain` char(64) not null primary key,
|
|
|
|
`remotehost` char(64) not null,
|
|
|
|
`basedn` char(64) not null,
|
|
|
|
`binddn` char(64) not null,
|
|
|
|
`sitedescription` char(64) default null
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
|
|
|
|
|
2012-01-03 00:19:43 +01:00
|
|
|
drop table if exists `domain`;
|
2011-12-27 20:51:56 +01:00
|
|
|
create table if not exists `domain` (
|
|
|
|
`domain` char(64) not null primary key,
|
|
|
|
`mapped` char(64) not null
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
|
|
|
|
insert into `domain` (`domain`, `mapped`) values('local', 'local');
|
|
|
|
|
2012-01-14 09:53:26 +01:00
|
|
|
|
|
|
|
drop table if exists `audit`;
|
|
|
|
create table if not exists `audit` (
|
|
|
|
`id` bigint unsigned not null auto_increment,
|
|
|
|
`ts` int not null,
|
|
|
|
`email` char(128) not null,
|
|
|
|
`action` int not null,
|
|
|
|
`ipaddr` char(15) not null,
|
|
|
|
`meta_id` bigint unsigned not null,
|
|
|
|
`description` char(255) default null,
|
|
|
|
`vcode` char(64) default null,
|
|
|
|
primary key (`id`)
|
|
|
|
) ENGINE=InnoDB;
|
|
|
|
|
2012-01-26 14:35:51 +01:00
|
|
|
create index `audit_idx` on `audit`(`email`);
|
|
|
|
create index `audit_idx2` on `audit`(`action`);
|
|
|
|
create index `audit_idx3` on `audit`(`ipaddr`);
|
|
|
|
create index `audit_idx4` on `audit`(`ts`);
|
|
|
|
|