CREATE TABLE IF NOT EXISTS `#__tassos_codesnippets` (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `asset_id` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'FK to the #__assets table.',
  `title` varchar(255) NOT NULL DEFAULT '',
  `alias` varchar(255) NOT NULL DEFAULT '',
  `code` mediumtext NOT NULL,
  `code_type` varchar(10) NOT NULL DEFAULT 'html',
  `insertion_method` varchar(20) NOT NULL DEFAULT 'auto',
  `location` varchar(50) DEFAULT NULL,
  `params` mediumtext,
  `last_error` text DEFAULT NULL,
  `last_error_date` datetime DEFAULT NULL,
  `state` tinyint(4) NOT NULL DEFAULT 0,
  `catid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `created` datetime NOT NULL,
  `created_by` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `modified` datetime NOT NULL,
  `modified_by` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `checked_out` int(10) UNSIGNED DEFAULT NULL,
  `checked_out_time` datetime DEFAULT NULL,
  `ordering` int(11) NOT NULL DEFAULT 0,
  `access` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `language` char(7) NOT NULL DEFAULT '*' COMMENT 'The language code for the snippet.',
  `note` varchar(255) NOT NULL DEFAULT '',
  `publishing_rules` mediumtext,
  PRIMARY KEY (`id`),
  KEY `idx_state` (`state`),
  KEY `idx_catid` (`catid`),
  KEY `idx_access` (`access`),
  KEY `idx_language` (`language`),
  KEY `idx_location` (`location`),
  KEY `idx_checkout` (`checked_out`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Insert default category for the component
INSERT INTO `#__categories` (`extension`, `title`, `alias`, `note`, `description`, `published`, `access`, `params`, `metadesc`, `metakey`, `metadata`, `created_user_id`, `created_time`, `modified_user_id`, `modified_time`, `hits`, `language`, `version`, `lft`, `rgt`, `level`, `path`, `parent_id`)
SELECT 'com_tassoscodesnippets', 'Uncategorised', 'uncategorised', '', '', 1, 1, '{}', '', '', '{}', 0, NOW(), 0, NOW(), 0, '*', 1, 0, 1, 1, 'uncategorised', 1
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `#__categories` WHERE `extension` = 'com_tassoscodesnippets' AND `alias` = 'uncategorised' LIMIT 1
);
