CREATE TABLE IF NOT EXISTS `zd_userquery` (
  `id` mediumint(8) unsigned NOT NULL auto_increment,
  `account` char(30) NOT NULL,
  `module` varchar(30) NOT NULL,
  `title` varchar(90) NOT NULL,
  `form` text NOT NULL,
  `sql` text NOT NULL,
  `shortcut` enum('0','1') NOT NULL DEFAULT '0',
  `common` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY  (`id`),
  KEY `account` (`account`),
  KEY `module` (`module`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `zd_datasource` ADD `acl` enum('open','private') NOT NULL default 'open' AFTER `name`;
ALTER TABLE `zd_datasource` ADD `whitelist` text NOT NULL AFTER `acl`;
ALTER TABLE `zd_datasource` ADD `desc` mediumtext NOT NULL AFTER `whitelist`;

CREATE TABLE IF NOT EXISTS `zd_acl` (
  `id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `account` char(30) NOT NULL,
  `objectType` char(30) NOT NULL,
  `objectID` mediumint(9) NOT NULL DEFAULT '0',
  `type` char(40) NOT NULL DEFAULT 'whitelist',
  `source` char(30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `zd_userview`;
CREATE TABLE IF NOT EXISTS `zd_userview` (
  `account` char(30) NOT NULL,
  `projects` mediumtext NOT NULL,
  `datasources` mediumtext NOT NULL,
  UNIQUE KEY `account` (`account`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

ALTER TABLE `zd_project` ADD `acl` enum('open','private') NOT NULL default 'open' AFTER `name`;
ALTER TABLE `zd_project` ADD `whitelist` text NOT NULL AFTER `acl`;
