CREATE TABLE IF NOT EXISTS `assistant_action` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `action_id` varchar(255) NOT NULL,
  `title` varchar(255) NOT NULL,
  `config` text NOT NULL,
  `action_class` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `action_id` (`action_id`),
  KEY `title` (`title`)
);

CREATE TABLE IF NOT EXISTS `assistant_action_user_group` (
  `action_id` int(11) NOT NULL,
  `user_group_id` int(11) NOT NULL,
  PRIMARY KEY (`user_group_id`,`action_id`)
);

ALTER TABLE assistant_action
	ADD column `dependent` tinyint(4),
	ADD column `sort` int(10) unsigned NOT NULL DEFAULT 1;

RENAME TABLE `assistant_action_user_group` TO `assistant_action_user_role`;
ALTER TABLE `assistant_action_user_role` DROP PRIMARY KEY;
ALTER TABLE `assistant_action_user_role` DROP COLUMN `user_group_id`;
ALTER TABLE `assistant_action_user_role` ADD COLUMN `user_role_id` INT NOT NULL DEFAULT 0;

CREATE TABLE IF NOT EXISTS `assistant_master` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `status` tinyint(4) NOT NULL DEFAULT 0,
  `title` varchar(255) NOT NULL,
  `comment` varchar(255) DEFAULT NULL,
  `config` text NOT NULL,
  `sort` int(10) unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `title` (`title`)
);

CREATE TABLE IF NOT EXISTS `assistant_master_user_role` (
  `master_id` int(11) NOT NULL,
  `user_role_id` int(11) NOT NULL DEFAULT 0
);


CREATE TABLE IF NOT EXISTS `assistant_master_action` (
  `master_id` int(11) NOT NULL,
  `action_id` int(11) NOT NULL DEFAULT 0
);

ALTER TABLE `assistant_action` MODIFY `dependent` int(11) NOT NULL DEFAULT 0;
ALTER TABLE `assistant_master` ADD COLUMN `icon_data` BLOB;

-- #BLOCK#
DELETE FROM script_event_type WHERE mid="p$mid";
INSERT INTO script_event_type (mid, event_id, event_mode, title) VALUES ("p$mid", 'ru.bitel.bgbilling.plugins.assistant.server.event.AssistantActionsListEvent', 0, 'Список доступных действий');
-- #ENDB#
