CREATE TABLE aliases (
  local_part varchar(64) NOT NULL,
  domain varchar(200) NOT NULL,
  recipients text(2000),
  PRIMARY KEY (local_part,domain)
) TYPE=MyISAM
  CHARACTER SET utf8;

CREATE TABLE blacklists (
  address varchar(64) NOT NULL,
  type enum('SENDER','HOSTREJ','REJRCPT') NOT NULL default 'SENDER',
  message varchar(255),
  PRIMARY KEY (address,type)
) TYPE=MyISAM
  CHARACTER SET utf8;

CREATE TABLE callbackdomains (
  domain varchar(200) NOT NULL,
  type enum('NOENV','NOHDR','NORND','NODNS') NOT NULL default 'NOENV',
  PRIMARY KEY (domain,type)
) TYPE=MyISAM
  CHARACTER SET utf8;

CREATE TABLE domains (
  domain varchar(200) NOT NULL,
  type enum('LOCAL','RELAY','VIRTUAL') default 'LOCAL',
  PRIMARY KEY (domain,type)
) TYPE=MyISAM
  CHARACTER SET utf8;

CREATE TABLE hostlists (
  hostname varchar(64) NOT NULL,
  type enum('AVOIDTLS','TRYAUTH','NOCALL') NOT NULL default 'AVOIDTLS',
  PRIMARY KEY (hostname,type)
) TYPE=MyISAM
  CHARACTER SET utf8;

CREATE TABLE userforward (
  local_part varchar(64) NOT NULL,
  domain varchar(200) NOT NULL,
  recipients text(2000),
  PRIMARY KEY (local_part,domain)
) TYPE=MyISAM
  CHARACTER SET utf8;

CREATE TABLE users (
  id varchar(200) NOT NULL,
  name varchar(255),
  user_id int NOT NULL,
  crypt varchar(255),
  passwd varchar(255),
  uid int(10) NOT NULL,
  gid int(10) NOT NULL,
  mbox_host varchar(128) NOT NULL,
  shell varchar(32) NOT NULL,
  home varchar(128) NOT NULL,
  quota tinyint(4),
  active enum('Y','N') NOT NULL default 'Y',
  PRIMARY KEY (id,mbox_host)
) TYPE=MyISAM
  CHARACTER SET utf8;

CREATE TABLE whitelist (
  address varchar(64) NOT NULL,
  PRIMARY KEY (address)
) TYPE=MyISAM
  CHARACTER SET utf8;

ALTER TABLE tbl_resource ADD ukk varchar(255) AFTER org_id;
ALTER TABLE tbl_resource ADD data date AFTER ukk;
ALTER TABLE tbl_resource ADD srvname varchar(100) AFTER data;
ALTER TABLE tbl_resource ADD srvput varchar(255) AFTER srvname;
ALTER TABLE tbl_resource ADD gread text(1000) AFTER srvput;
ALTER TABLE tbl_resource ADD gwrite text(1000) AFTER gread;
ALTER TABLE tbl_resource ADD sppubl varchar(100) AFTER gwrite;
ALTER TABLE tbl_resource ADD srvkvota int(10) AFTER sppubl;
ALTER TABLE tbl_resource ADD size_id int(2) AFTER srvkvota;
ALTER TABLE tbl_resource ADD bakup ENUM('yes','no') NOT NULL DEFAULT 'yes' AFTER size_id;
ALTER TABLE tbl_resource ADD rezim varchar(255) AFTER bakup;
ALTER TABLE tbl_resource ADD bakrazm varchar(255) AFTER rezim;
ALTER TABLE tbl_resource ADD bakprog varchar(255) AFTER bakrazm;

CREATE TABLE tbl_sizes(
      size_id int(2) NOT NULL auto_increment primary key,
      size_name varchar(100)
      )TYPE=MyISAM
      CHARACTER SET utf8;

CREATE TABLE system_accounts (
  id_account int(11) NOT NULL auto_increment,
  name tinytext NOT NULL,
  pass tinytext NOT NULL,
  PRIMARY KEY  (id_account)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
INSERT INTO system_accounts VALUES(1, 'root', '63a9f0ea7bb98050796b649e85481845');
INSERT INTO system_accounts VALUES(2, 'admin', '21232f297a57a5a743894a0e4a801fc3');

ALTER TABLE system_arch_clients RENAME powercounter_arch_clients;
ALTER TABLE system_arch_clients_month RENAME powercounter_arch_clients_month;
ALTER TABLE system_arch_clients_week RENAME powercounter_arch_clients_week;
ALTER TABLE system_arch_deep RENAME powercounter_arch_deep;
ALTER TABLE system_arch_deep_month RENAME powercounter_arch_deep_month;
ALTER TABLE system_arch_deep_week RENAME powercounter_arch_deep_week;
ALTER TABLE system_arch_enterpoint RENAME powercounter_arch_enterpoint;
ALTER TABLE system_arch_enterpoint_month RENAME powercounter_arch_enterpoint_month;
ALTER TABLE system_arch_enterpoint_week RENAME powercounter_arch_enterpoint_week;
ALTER TABLE system_arch_hits RENAME powercounter_arch_hits;
ALTER TABLE system_arch_hits_month RENAME powercounter_arch_hits_month;
ALTER TABLE system_arch_hits_week RENAME powercounter_arch_hits_week;
ALTER TABLE system_arch_ip RENAME powercounter_arch_ip;
ALTER TABLE system_arch_ip_month RENAME powercounter_arch_ip_month;
ALTER TABLE system_arch_ip_week RENAME powercounter_arch_ip_week;
ALTER TABLE system_arch_num_searchquery RENAME powercounter_arch_num_searchquery;
ALTER TABLE system_arch_num_searchquery_week RENAME powercounter_arch_num_searchquery_week;
ALTER TABLE system_arch_num_searchquery_month RENAME powercounter_arch_num_searchquery_month;
ALTER TABLE system_arch_refferer RENAME powercounter_arch_refferer;
ALTER TABLE system_arch_refferer_month RENAME powercounter_arch_refferer_month;
ALTER TABLE system_arch_refferer_week RENAME powercounter_arch_refferer_week;
ALTER TABLE system_arch_robots RENAME powercounter_arch_robots;
ALTER TABLE system_arch_robots_month RENAME powercounter_arch_robots_month;
ALTER TABLE system_arch_robots_week RENAME powercounter_arch_robots_week;
ALTER TABLE system_arch_searchquery RENAME powercounter_arch_searchquery;
ALTER TABLE system_arch_searchquery_month RENAME powercounter_arch_searchquery_month;
ALTER TABLE system_arch_searchquery_week RENAME powercounter_arch_searchquery_week;
ALTER TABLE system_arch_time RENAME powercounter_arch_time;
ALTER TABLE system_arch_time_month RENAME powercounter_arch_time_month;
ALTER TABLE system_arch_time_temp RENAME powercounter_arch_time_temp;
ALTER TABLE system_arch_time_week RENAME powercounter_arch_time_week;
ALTER TABLE system_cities RENAME powercounter_cities;
ALTER TABLE system_ip_compact RENAME powercounter_ip_compact;
ALTER TABLE system_regions RENAME powercounter_regions;
ALTER TABLE system_ip RENAME powercounter_ip;
ALTER TABLE system_pages RENAME powercounter_pages;
ALTER TABLE system_refferer RENAME powercounter_refferer;
ALTER TABLE system_searchquerys RENAME powercounter_searchquerys;
ALTER TABLE system_thits RENAME powercounter_thits;

ALTER TABLE powercounter_arch_clients CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_clients_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_deep CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_deep_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_enterpoint CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_enterpoint_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_hits CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_hits_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_ip CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_ip_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_num_searchquery CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_num_searchquery_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_refferer CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_refferer_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_robots CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_robots_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_searchquery CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_searchquery_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_time CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_time_month CHANGE putdate putdate DATE NOT NULL DEFAULT '0000-00-00';

ALTER TABLE powercounter_arch_hits_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_clients_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_deep_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_enterpoint_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_ip_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_num_searchquery_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_refferer_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_robots_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_searchquery_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
ALTER TABLE powercounter_arch_time_week CHANGE putdate_begin putdate_begin DATE NOT NULL DEFAULT '0000-00-00',
CHANGE putdate_end putdate_end DATE NOT NULL DEFAULT '0000-00-00';
