mirror of https://github.com/MISP/MISP
124 lines
3.7 KiB
SQL
124 lines
3.7 KiB
SQL
-- Copyright (c) 2009 www.cryer.co.uk
|
|
-- Script is free to use provided this copyright header is included.
|
|
drop procedure if exists AddColumnUnlessExists;
|
|
delimiter '//'
|
|
|
|
create procedure AddColumnUnlessExists(
|
|
IN dbName tinytext,
|
|
IN tableName tinytext,
|
|
IN fieldName tinytext,
|
|
IN fieldDef text)
|
|
begin
|
|
IF NOT EXISTS (
|
|
SELECT * FROM information_schema.COLUMNS
|
|
WHERE column_name=fieldName
|
|
and table_name=tableName
|
|
and table_schema=dbName
|
|
)
|
|
THEN
|
|
set @ddl=CONCAT('ALTER TABLE ',dbName,'.',tableName,
|
|
' ADD COLUMN ',fieldName,' ',fieldDef);
|
|
prepare stmt from @ddl;
|
|
execute stmt;
|
|
END IF;
|
|
end;
|
|
//
|
|
|
|
delimiter ';'
|
|
|
|
call AddColumnUnlessExists(Database(), 'roles', 'perm_template', 'TINYINT( 1 ) NOT NULL DEFAULT 0');
|
|
-- --------------------------------------------------------
|
|
|
|
--
|
|
-- Table structure for table `templates`
|
|
--
|
|
|
|
CREATE TABLE IF NOT EXISTS `templates` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`description` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`org` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`share` tinyint(1) NOT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
|
|
|
-- --------------------------------------------------------
|
|
|
|
--
|
|
-- Table structure for table `template_elements`
|
|
--
|
|
|
|
CREATE TABLE IF NOT EXISTS `template_elements` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`template_id` int(11) NOT NULL,
|
|
`position` int(11) NOT NULL,
|
|
`element_definition` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
|
|
|
-- --------------------------------------------------------
|
|
|
|
--
|
|
-- Table structure for table `template_element_attributes`
|
|
--
|
|
|
|
CREATE TABLE IF NOT EXISTS `template_element_attributes` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`template_element_id` int(11) NOT NULL,
|
|
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`to_ids` tinyint(1) NOT NULL DEFAULT '1',
|
|
`category` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`complex` tinyint(1) NOT NULL,
|
|
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`mandatory` tinyint(1) NOT NULL,
|
|
`batch` tinyint(1) NOT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
|
|
|
-- --------------------------------------------------------
|
|
|
|
--
|
|
-- Table structure for table `template_element_files`
|
|
--
|
|
|
|
CREATE TABLE IF NOT EXISTS `template_element_files` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`template_element_id` int(11) NOT NULL,
|
|
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`category` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`malware` tinyint(1) NOT NULL,
|
|
`mandatory` tinyint(1) NOT NULL,
|
|
`batch` tinyint(1) NOT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
|
|
|
-- --------------------------------------------------------
|
|
|
|
--
|
|
-- Table structure for table `template_element_texts`
|
|
--
|
|
|
|
CREATE TABLE IF NOT EXISTS `template_element_texts` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
`template_element_id` int(11) NOT NULL,
|
|
`text` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
|
|
|
-- --------------------------------------------------------
|
|
|
|
--
|
|
-- Table structure for table `template_tags`
|
|
--
|
|
|
|
CREATE TABLE IF NOT EXISTS `template_tags` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`template_id` int(11) NOT NULL,
|
|
`tag_id` int(11) NOT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
|
|