/*M!999999\- enable the sandbox mode */ 

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `tbl_auth`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_auth` (
  `cl_auth_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cl_auth_user` varchar(190) NOT NULL,
  `cl_auth_pass` varchar(255) NOT NULL,
  `cl_auth_right` enum('admin','member') NOT NULL DEFAULT 'member',
  PRIMARY KEY (`cl_auth_id`),
  UNIQUE KEY `cl_auth_user` (`cl_auth_user`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scbanners`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scbanners` (
  `cl_scbanner_id` int(11) NOT NULL AUTO_INCREMENT,
  `cl_scbanner_name` varchar(255) NOT NULL,
  `cl_scbanner_url` text NOT NULL,
  `cl_scbanner_border_color` varchar(20) NOT NULL DEFAULT '#ffae00',
  PRIMARY KEY (`cl_scbanner_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scitemcustom`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scitemcustom` (
  `cl_scitemcustom_id` int(11) NOT NULL AUTO_INCREMENT,
  `cl_scitemcustom_owner_auth_id` int(10) unsigned DEFAULT NULL,
  `cl_scitemcustom_obj_id` int(10) unsigned NOT NULL,
  `cl_scitemcustom_created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`cl_scitemcustom_id`),
  UNIQUE KEY `uq_scitemcustom_owner_obj` (`cl_scitemcustom_owner_auth_id`,`cl_scitemcustom_obj_id`),
  KEY `idx_scitemcustom_obj` (`cl_scitemcustom_obj_id`),
  KEY `idx_scitemcustom_owner` (`cl_scitemcustom_owner_auth_id`),
  CONSTRAINT `fk_scitemcustom_obj` FOREIGN KEY (`cl_scitemcustom_obj_id`) REFERENCES `tbl_scobjs` (`cl_scobjs_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_scitemcustom_owner_auth` FOREIGN KEY (`cl_scitemcustom_owner_auth_id`) REFERENCES `tbl_auth` (`cl_auth_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scitemcustomstat`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scitemcustomstat` (
  `cl_scitemcustomstat_id` int(11) NOT NULL AUTO_INCREMENT,
  `cl_scitemcustomstat_itemcustom_id` int(11) NOT NULL,
  `cl_scitemcustomstat_stat_id` int(11) NOT NULL,
  `cl_scitemcustomstat_sign` enum('+','','-') NOT NULL DEFAULT '+',
  `cl_scitemcustomstat_value` decimal(10,2) NOT NULL DEFAULT 0.00,
  `cl_scitemcustomstat_created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`cl_scitemcustomstat_id`),
  UNIQUE KEY `uq_scitemcustomstat_item_stat` (`cl_scitemcustomstat_itemcustom_id`,`cl_scitemcustomstat_stat_id`),
  KEY `idx_scitemcustomstat_item` (`cl_scitemcustomstat_itemcustom_id`),
  KEY `idx_scitemcustomstat_stat` (`cl_scitemcustomstat_stat_id`),
  CONSTRAINT `fk_scitemcustomstat_item` FOREIGN KEY (`cl_scitemcustomstat_itemcustom_id`) REFERENCES `tbl_scitemcustom` (`cl_scitemcustom_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_scitemcustomstat_stat` FOREIGN KEY (`cl_scitemcustomstat_stat_id`) REFERENCES `tbl_scstatsitem` (`cl_scstatsitem_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scmanufactures`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scmanufactures` (
  `cl_scmanufactures_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cl_scmanufactures_name` varchar(255) NOT NULL,
  PRIMARY KEY (`cl_scmanufactures_id`),
  UNIQUE KEY `cl_scmanufactures_name` (`cl_scmanufactures_name`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scmining`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scmining` (
  `cl_scmining_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cl_scmining_obj_id` int(10) unsigned NOT NULL,
  `cl_scmining_scan_value` int(10) unsigned DEFAULT 0,
  `cl_scmining_max_occurrence` int(10) unsigned DEFAULT 1,
  `cl_scmining_can_manual` tinyint(1) DEFAULT 0,
  `cl_scmining_can_land` tinyint(1) DEFAULT 0,
  `cl_scmining_can_space` tinyint(1) DEFAULT 0,
  PRIMARY KEY (`cl_scmining_id`),
  UNIQUE KEY `cl_scmining_obj_id` (`cl_scmining_obj_id`),
  CONSTRAINT `fk_scmining_obj` FOREIGN KEY (`cl_scmining_obj_id`) REFERENCES `tbl_scobjs` (`cl_scobjs_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scnotifications`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scnotifications` (
  `cl_scnotification_id` int(11) NOT NULL AUTO_INCREMENT,
  `cl_scnotification_webhook_id` int(11) NOT NULL,
  `cl_scnotification_banner_id` int(11) DEFAULT NULL,
  `cl_scnotification_title` varchar(255) NOT NULL DEFAULT '',
  `cl_scnotification_message` text NOT NULL,
  `cl_scnotification_payload` longtext NOT NULL,
  `cl_scnotification_response` longtext DEFAULT NULL,
  `cl_scnotification_success` tinyint(1) NOT NULL DEFAULT 0,
  `cl_scnotification_created_by` varchar(190) NOT NULL,
  `cl_scnotification_created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`cl_scnotification_id`),
  KEY `idx_scnotification_webhook` (`cl_scnotification_webhook_id`),
  KEY `idx_scnotification_banner` (`cl_scnotification_banner_id`),
  CONSTRAINT `fk_scnotification_banner` FOREIGN KEY (`cl_scnotification_banner_id`) REFERENCES `tbl_scbanners` (`cl_scbanner_id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `fk_scnotification_webhook` FOREIGN KEY (`cl_scnotification_webhook_id`) REFERENCES `tbl_scwebhooks` (`cl_scwebhook_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scobjs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scobjs` (
  `cl_scobjs_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cl_scobjs_name` varchar(255) NOT NULL,
  `cl_scobjs_type` varchar(100) DEFAULT NULL,
  `cl_scobjs_subtype` varchar(100) DEFAULT NULL,
  `cl_scobjs_uuid` varchar(100) NOT NULL,
  `cl_scobjs_rarity` varchar(10) DEFAULT '',
  `cl_scobjs_about` text DEFAULT NULL,
  `cl_scobjs_description` text DEFAULT NULL,
  PRIMARY KEY (`cl_scobjs_id`),
  UNIQUE KEY `cl_scobjs_uuid` (`cl_scobjs_uuid`)
) ENGINE=InnoDB AUTO_INCREMENT=18305 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scpreset`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scpreset` (
  `cl_scpreset_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cl_scpreset_manufacture_id` int(10) unsigned DEFAULT NULL,
  `cl_scpreset_vaisseau_id` int(10) unsigned DEFAULT NULL,
  `cl_scpreset_name` varchar(255) NOT NULL,
  `cl_scpreset_manufacturer` varchar(255) NOT NULL,
  `cl_scpreset_description` text DEFAULT NULL,
  `cl_scpreset_link` varchar(255) NOT NULL,
  `cl_scpreset_creator` varchar(255) DEFAULT 'admin',
  PRIMARY KEY (`cl_scpreset_id`),
  KEY `fk_scpreset_manufacture` (`cl_scpreset_manufacture_id`),
  KEY `fk_scpreset_vaisseau` (`cl_scpreset_vaisseau_id`),
  CONSTRAINT `fk_scpreset_manufacture` FOREIGN KEY (`cl_scpreset_manufacture_id`) REFERENCES `tbl_scmanufactures` (`cl_scmanufactures_id`),
  CONSTRAINT `fk_scpreset_vaisseau` FOREIGN KEY (`cl_scpreset_vaisseau_id`) REFERENCES `tbl_scvaisseaux` (`cl_scvaisseaux_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scstatsitem`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scstatsitem` (
  `cl_scstatsitem_id` int(11) NOT NULL AUTO_INCREMENT,
  `cl_scstatsitem_name` varchar(255) NOT NULL,
  `cl_scstatsitem_unit` varchar(10) NOT NULL DEFAULT '%',
  `cl_scstatsitem_created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`cl_scstatsitem_id`),
  UNIQUE KEY `uq_scstatsitem_name` (`cl_scstatsitem_name`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scvaisseaux`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scvaisseaux` (
  `cl_scvaisseaux_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cl_scvaisseaux_name` varchar(255) NOT NULL,
  `cl_scvaisseaux_manufacture_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`cl_scvaisseaux_id`),
  KEY `fk_vaisseaux_manufacture` (`cl_scvaisseaux_manufacture_id`),
  CONSTRAINT `fk_vaisseaux_manufacture` FOREIGN KEY (`cl_scvaisseaux_manufacture_id`) REFERENCES `tbl_scmanufactures` (`cl_scmanufactures_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tbl_scwebhooks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `tbl_scwebhooks` (
  `cl_scwebhook_id` int(11) NOT NULL AUTO_INCREMENT,
  `cl_scwebhook_name` varchar(255) NOT NULL,
  `cl_scwebhook_url` text NOT NULL,
  `cl_scwebhook_image_url` text NOT NULL,
  `cl_scwebhook_border_color` varchar(20) NOT NULL DEFAULT '#ffae00',
  `cl_scwebhook_is_forum` tinyint(1) DEFAULT 0,
  PRIMARY KEY (`cl_scwebhook_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;



CREATE TABLE IF NOT EXISTS tbl_page_access (
    cl_page_access_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    cl_page_key VARCHAR(190) NOT NULL UNIQUE,
    cl_page_file VARCHAR(190) NOT NULL UNIQUE,
    cl_page_label VARCHAR(190) NOT NULL,
    cl_allow_admin TINYINT(1) NOT NULL DEFAULT 1,
    cl_allow_moderator TINYINT(1) NOT NULL DEFAULT 0,
    cl_allow_member TINYINT(1) NOT NULL DEFAULT 0,
    cl_updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS tbl_sccharacters (
    cl_sccharacter_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    cl_sccharacter_owner_auth_id INT UNSIGNED NOT NULL,
    cl_sccharacter_name VARCHAR(190) NOT NULL,
    cl_sccharacter_role VARCHAR(190) NOT NULL DEFAULT '',
    cl_sccharacter_faction VARCHAR(190) NOT NULL DEFAULT '',
    cl_sccharacter_org_rsi_url VARCHAR(255) NOT NULL DEFAULT '',
    cl_sccharacter_player_handle VARCHAR(190) NOT NULL DEFAULT '',
    cl_sccharacter_avatar_url VARCHAR(255) NOT NULL DEFAULT '',
    cl_sccharacter_description TEXT DEFAULT NULL,
    cl_sccharacter_notes TEXT DEFAULT NULL,
    cl_sccharacter_share_token VARCHAR(64) NOT NULL,
    cl_sccharacter_share_enabled TINYINT(1) NOT NULL DEFAULT 0,
    cl_sccharacter_created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    cl_sccharacter_updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_sccharacter_share_token (cl_sccharacter_share_token),
    KEY idx_sccharacter_owner (cl_sccharacter_owner_auth_id),
    KEY idx_sccharacter_name (cl_sccharacter_name),
    CONSTRAINT fk_sccharacter_owner_auth FOREIGN KEY (cl_sccharacter_owner_auth_id)
        REFERENCES tbl_auth (cl_auth_id)
        ON DELETE CASCADE
        ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS tbl_sccharacteritems (
    cl_sccharacteritem_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    cl_sccharacteritem_character_id INT UNSIGNED NOT NULL,
    cl_sccharacteritem_source ENUM('base', 'custom') NOT NULL DEFAULT 'base',
    cl_sccharacteritem_scobjs_id INT UNSIGNED DEFAULT NULL,
    cl_sccharacteritem_scitemcustom_id INT(11) DEFAULT NULL,
    cl_sccharacteritem_slot VARCHAR(120) NOT NULL DEFAULT '',
    cl_sccharacteritem_quantity INT UNSIGNED DEFAULT NULL,
    cl_sccharacteritem_note TEXT DEFAULT NULL,
    cl_sccharacteritem_created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY idx_sccharacteritem_character (cl_sccharacteritem_character_id),
    KEY idx_sccharacteritem_scobjs (cl_sccharacteritem_scobjs_id),
    KEY idx_sccharacteritem_scitemcustom (cl_sccharacteritem_scitemcustom_id),
    CONSTRAINT fk_sccharacteritem_character FOREIGN KEY (cl_sccharacteritem_character_id)
        REFERENCES tbl_sccharacters (cl_sccharacter_id)
        ON DELETE CASCADE
        ON UPDATE CASCADE,
    CONSTRAINT fk_sccharacteritem_scobjs FOREIGN KEY (cl_sccharacteritem_scobjs_id)
        REFERENCES tbl_scobjs (cl_scobjs_id)
        ON DELETE SET NULL
        ON UPDATE CASCADE,
    CONSTRAINT fk_sccharacteritem_scitemcustom FOREIGN KEY (cl_sccharacteritem_scitemcustom_id)
        REFERENCES tbl_scitemcustom (cl_scitemcustom_id)
        ON DELETE SET NULL
        ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
