-- 28/04/2016
ALTER TABLE  `tbg_workflows` ADD  `json_grafico` TEXT NULL ;
-- 01/06/2016
ALTER TABLE  `tbg_files` ADD  `deleted` TINYINT( 1 ) NOT NULL DEFAULT  '0';
-- 13/07/2016
ALTER TABLE  `tbg_users` ADD  `is_superadmin` TINYINT( 1 ) NOT NULL DEFAULT  '0';
UPDATE  `tbg_users` SET  `is_superadmin` =  '1' WHERE  `tbg_users`.`id` =1;

-- 19/0/2016
-- Estructura de tabla para la tabla `tbg_customfields_block`
--

CREATE TABLE IF NOT EXISTS `tbg_customfields_block` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `scope` int(4) NOT NULL,
  `key` varchar(255) NOT NULL,
  `parent_key` varchar(255) NOT NULL,
  `order` int(4) NOT NULL DEFAULT '0',
  `is_form` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1:form|0:block',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

ALTER TABLE  `tbg_customfields_block` ADD UNIQUE (
`scope` ,
`key` ,
`parent_key` ,
`is_form`
);

-- 25/07/2016
UPDATE  `tbg_customfields` SET  `is_codigo_unico` =  '0' WHERE  `tbg_customfields`.`id` =17;

-- 01/08/2016
ALTER TABLE  `tbg_customfields` ADD  `decimales` INT( 11 ) NOT NULL DEFAULT  '0';;

-- 08/08/2016

--
-- Estructura de tabla para la tabla `tbg_customfields_code`
--

CREATE TABLE IF NOT EXISTS `tbg_customfields_code` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_key` varchar(255) NOT NULL,
  `scope` int(4) NOT NULL,
  `order` int(4) NOT NULL DEFAULT '0',
  `key` varchar(255) NOT NULL,
  `type_key` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1:key|2:separator|3:isAutoincrement',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- 09/05/16 => 18/08/2016
--
-- Estructura de tabla para la tabla `tbg_report`
--
CREATE TABLE IF NOT EXISTS `tbg_report` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `uid` int(11) NOT NULL DEFAULT '0',
  `fields` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ALTER TABLE `tbg_report` ADD `issuetypes` INT( 11 ) NOT NULL DEFAULT '0';

ALTER TABLE `tbg_report` ADD `scope` INT( 4 ) NOT NULL DEFAULT '0';

-- 22.08.2016
ALTER TABLE `tbg_customfields` ADD `cantidad_decimales` VARCHAR( 100 ) NULL ;

-- 21/09/2016
ALTER TABLE  `tbg_issuecustomfields` 
ADD  `block_id` INT( 4 ) NOT NULL DEFAULT  '0',
ADD  `form_id` INT( 4 ) NOT NULL DEFAULT  '0';

-- 22/09/2016
ALTER TABLE  `tbg_issuefiles` 
ADD  `block_id` INT( 4 ) NOT NULL DEFAULT  '0',
ADD  `form_id` INT( 4 ) NOT NULL DEFAULT  '0';

-- 29/09/2016

--
-- Estructura de tabla para la tabla `tbg_customfields_table`
--

CREATE TABLE IF NOT EXISTS `tbg_customfields_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `scope` int(4) NOT NULL,
  `key` varchar(255) NOT NULL,
  `parent_key` varchar(255) NOT NULL,
  `order` int(4) NOT NULL DEFAULT '0',
  `is_table` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1:table|0:table double',
  PRIMARY KEY (`id`),
  UNIQUE KEY `scope` (`scope`,`key`,`parent_key`,`is_table`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;

--
-- Estructura de tabla para la tabla `tbg_issuecustomfields`
--


CREATE TABLE IF NOT EXISTS `tbg_issuecustomfieldstable` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `scope` int(10) unsigned DEFAULT '0',
  `issue_id` int(10) unsigned DEFAULT '0',
  `customfields_id` int(10) unsigned DEFAULT '0',
  `customfieldoption_id` int(10) unsigned DEFAULT '0',
  `option_value` text,
  `table_id` int(11) NOT NULL DEFAULT '0',
  `block_id` int(4) NOT NULL DEFAULT '0',
  `form_id` int(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;
ALTER TABLE  `tbg_issuecustomfieldstable` ADD  `fila` INT( 3 ) NOT NULL DEFAULT  '0';

-- 04/10/2016
ALTER TABLE  `tbg_issues` CHANGE  `numero_adquisicion`  `numero_adquisicion` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ;

ALTER TABLE  `tbg_customfields` CHANGE  `description`  `description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
CHANGE  `instructions`  `instructions` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
CHANGE  `name`  `name` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
CHANGE  `itemdata`  `itemdata` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ;

-- 05/10/2016
ALTER TABLE  `tbg_report` ADD  `project_id` INT( 10 ) NOT NULL DEFAULT  '0';

-- 04/11/2016
ALTER TABLE  `tbg_customfields_table` ADD  `is_autosuma` TINYINT( 1 ) NOT NULL DEFAULT  '0';

-- 14/12/2016
--
-- Estructura de tabla para la tabla `tbg_issuecustomfieldsforms`
--

CREATE TABLE IF NOT EXISTS `tbg_issuecustomfieldsforms` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `scope` int(10) unsigned DEFAULT '0',
  `issue_id` int(10) unsigned DEFAULT '0',
  `customfields_id` int(10) unsigned DEFAULT '0',
  `customfieldoption_id` int(10) unsigned DEFAULT '0',
  `option_value` text,
  `table_id` int(11) NOT NULL DEFAULT '0',
  `block_id` int(4) NOT NULL DEFAULT '0',
  `form_id` int(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8  ;

--
-- Estructura de tabla para la tabla `tbg_issueforms`
--

CREATE TABLE IF NOT EXISTS `tbg_issueforms` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `scope` int(3) unsigned DEFAULT '0',
  `issue_id` int(10) unsigned DEFAULT '0',
  `order` int(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

-- 15/12/2016
ALTER TABLE  `tbg_issuecustomfieldsforms` ADD  `form_multiple_id` INT( 11 ) NOT NULL DEFAULT  '0';
ALTER TABLE  `tbg_issuecustomfieldstable` ADD  `form_multiple_id` INT( 11 ) NOT NULL DEFAULT  '0';

ALTER TABLE  `tbg_issueforms` ADD  `form_multiple_key` VARCHAR( 255 ) NULL DEFAULT NULL ;

-- 19/12/2016
ALTER TABLE  `tbg_issuefiles` ADD  `form_multiple_id` INT( 11 ) NOT NULL DEFAULT  '0';

-- 03/01/2017
ALTER TABLE  `tbg_issueforms` ADD  `posted` DATETIME NULL DEFAULT NULL , ADD  `last_updated` DATETIME NULL DEFAULT NULL ;

-- 03/01/2017
-- para cada SCOPE modificar el id del scope

INSERT INTO  `tbg_customfields` (
`description` ,
`instructions` ,
`name` ,
`itemtype` ,
`itemdata` ,
`sort_order` ,
`key` ,
`scope` ,
`id` ,
`is_numeric` ,
`is_file_multiple` ,
`is_codigo_unico` ,
`is_dependiente` ,
`decimales` ,
`cantidad_decimales`
)
VALUES (
'Número',  '',  'numero de formulario',  '2',  'form_multiple_numero',  '0',  'formmultiplenumero',  '1',  '0',  '0',  '1',  '0',  '0',  '0',  '0'
);

-- 23/01/2017
ALTER TABLE  `tbg_issuecustomfields` ADD INDEX (  `issue_id` ,  `customfields_id` ,  `customfieldoption_id` ,  `block_id` ,  `form_id` ) ;

-- 25/01/2017
ALTER TABLE  `tbg_customfieldoptions` ADD INDEX (  `customfield_id` ,  `parent_id` ) ;
