-- phpMyAdmin SQL Dump
-- version 5.2.3
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Jan 06, 2026 at 06:25 PM
-- Server version: 12.1.2-MariaDB-log
-- PHP Version: 8.4.15

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!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 */;

--
-- Database: `aether_dev`
--

-- --------------------------------------------------------

--
-- Table structure for table `event_file`
--

CREATE TABLE `event_file` (
  `id` int(11) NOT NULL,
  `id_random` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `hosted_file_id` int(11) DEFAULT NULL,
  `for_type` varchar(50) DEFAULT NULL,
  `for_id` int(11) DEFAULT NULL,
  `event_id` int(11) DEFAULT NULL COMMENT 'is this needed?',
  `event_session_id` int(11) DEFAULT NULL COMMENT 'is this needed?',
  `event_presentation_id` int(11) DEFAULT NULL COMMENT 'is this needed?',
  `event_presenter_id` int(11) DEFAULT NULL COMMENT 'is this needed?',
  `event_location_id` int(11) DEFAULT NULL COMMENT 'is this needed?',
  `event_track_id` int(11) DEFAULT NULL COMMENT 'is this needed?',
  `event_exhibit_id` int(11) DEFAULT NULL COMMENT 'is this needed?',
  `filename` varchar(255) DEFAULT NULL,
  `extension` varchar(10) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `internal_use` tinyint(1) DEFAULT NULL COMMENT 'hide from non-support people',
  `internal_start_datetime` datetime DEFAULT NULL,
  `internal_end_datetime` datetime DEFAULT NULL,
  `internal_filename` varchar(255) DEFAULT NULL,
  `internal_extension` varchar(10) DEFAULT NULL,
  `open_in_os` varchar(50) DEFAULT NULL COMMENT 'change to open_in: [mac,win,local browser/client,remote browser/client,api,websocket,download]',
  `internal_hide` tinyint(1) DEFAULT NULL,
  `private_use` tinyint(1) DEFAULT NULL,
  `private_start_datetime` datetime DEFAULT NULL,
  `private_end_datetime` datetime DEFAULT NULL,
  `private_filename` varchar(255) DEFAULT NULL,
  `private_extension` varchar(10) DEFAULT NULL,
  `private_hide` tinyint(1) DEFAULT NULL,
  `public_use` tinyint(1) DEFAULT NULL,
  `public_start_datetime` datetime DEFAULT NULL,
  `public_end_datetime` datetime DEFAULT NULL,
  `public_filename` varchar(255) DEFAULT NULL,
  `public_extension` varchar(10) DEFAULT NULL,
  `public_hide` tinyint(1) DEFAULT NULL,
  `lu_file_purpose_id` int(11) DEFAULT NULL,
  `file_purpose` varchar(100) DEFAULT NULL,
  `publish_optout` tinyint(1) DEFAULT NULL,
  `download_start_datetime` datetime DEFAULT NULL,
  `download_end_datetime` datetime DEFAULT NULL,
  `approved` int(11) DEFAULT NULL,
  `approved_on` timestamp NULL DEFAULT NULL,
  `public` tinyint(1) DEFAULT NULL,
  `hide` tinyint(1) DEFAULT NULL,
  `priority` tinyint(1) DEFAULT NULL,
  `sort` int(11) DEFAULT NULL,
  `group` varchar(100) DEFAULT NULL,
  `enable` tinyint(1) NOT NULL DEFAULT 1,
  `enable_after_datetime` datetime DEFAULT NULL,
  `enable_before_datetime` datetime DEFAULT NULL,
  `enable_for_administrator` tinyint(1) NOT NULL DEFAULT 0,
  `enable_for_support` tinyint(1) NOT NULL DEFAULT 0,
  `enable_for_assistant` tinyint(1) NOT NULL DEFAULT 0,
  `enable_for_trusted` tinyint(1) NOT NULL DEFAULT 0,
  `enable_for_authenticated` tinyint(1) NOT NULL DEFAULT 0,
  `status` int(11) DEFAULT NULL,
  `review` tinyint(1) DEFAULT NULL,
  `approve` tinyint(1) DEFAULT NULL,
  `ready` tinyint(1) DEFAULT NULL,
  `ready_datetime` datetime DEFAULT NULL,
  `archive` tinyint(1) DEFAULT NULL,
  `archive_datetime` datetime DEFAULT NULL,
  `enable_for_anonymous` tinyint(1) NOT NULL DEFAULT 0,
  `created_on` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_on` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Triggers `event_file`
--
DELIMITER $$
CREATE TRIGGER `before_insert_event_file` BEFORE INSERT ON `event_file` FOR EACH ROW BEGIN
    BEGIN
        IF (NEW.id_random IS NULL OR NEW.id_random = '' OR LENGTH(NEW.id_random) < 6)
        THEN
            /* SET NEW.id_random = gen_rand_pattern('3C-2N-2N-2N'); */
            /* SET NEW.id_random = gen_rand_pattern('4C-2N-2N-2N'); */
            SET NEW.id_random = gen_rand_str(11, 'URL');
        END IF;
    END;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `before_insert_event_file_fix_ids` BEFORE INSERT ON `event_file` FOR EACH ROW BEGIN
    BEGIN
        IF (NEW.for_type = 'event_location' AND NEW.for_id IS NOT NULL)
        THEN
            SET NEW.event_location_id = NEW.for_id;
            SET NEW.event_id = (SELECT event_id FROM event_location WHERE event_location.id = NEW.for_id);
        END IF;
        
        IF (NEW.for_type = 'event_presenter' AND NEW.for_id IS NOT NULL)
        THEN
            SET NEW.event_presenter_id = NEW.for_id;
            SET NEW.event_presentation_id = (SELECT event_presentation_id FROM event_presenter WHERE event_presenter.id = NEW.for_id);
            SET NEW.event_session_id = (SELECT event_session_id FROM event_presentation WHERE event_presentation.id = NEW.event_presentation_id);
            SET NEW.event_location_id = (SELECT event_location_id FROM event_session WHERE event_session.id = NEW.event_session_id);
            SET NEW.event_id = (SELECT event_id FROM event_session WHERE event_session.id = NEW.event_session_id);
        END IF;
        
        IF (NEW.for_type = 'event_session' AND NEW.for_id IS NOT NULL)
        THEN
            SET NEW.event_session_id = NEW.for_id;
            SET NEW.event_location_id = (SELECT event_location_id FROM event_session WHERE event_session.id = NEW.for_id);
            SET NEW.event_id = (SELECT event_id FROM event_session WHERE event_session.id = NEW.for_id);
        END IF;
    END;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `before_update_event_file` BEFORE UPDATE ON `event_file` FOR EACH ROW BEGIN
    BEGIN
        IF (NEW.id_random IS NULL OR NEW.id_random = '' OR LENGTH(NEW.id_random) < 6)
        THEN
            /* SET NEW.id_random = gen_rand_pattern('3C-2N-2N-2N'); */
            /* SET NEW.id_random = gen_rand_pattern('4C-2N-2N-2N'); */
            SET NEW.id_random = gen_rand_str(11, 'URL');
        END IF;
    END;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `before_update_event_file_fix_ids` BEFORE UPDATE ON `event_file` FOR EACH ROW BEGIN
    BEGIN
        IF (NEW.for_type = 'event_location' AND NEW.for_id IS NOT NULL)
        THEN
            SET NEW.event_location_id = NEW.for_id;
            SET NEW.event_id = (SELECT event_id FROM event_location WHERE event_location.id = NEW.for_id);
        END IF;
        
        IF (NEW.for_type = 'event_presenter' AND NEW.for_id IS NOT NULL)
        THEN
            SET NEW.event_presenter_id = NEW.for_id;
            SET NEW.event_presentation_id = (SELECT event_presentation_id FROM event_presenter WHERE event_presenter.id = NEW.for_id);
            SET NEW.event_session_id = (SELECT event_session_id FROM event_presentation WHERE event_presentation.id = NEW.event_presentation_id);
            SET NEW.event_location_id = (SELECT event_location_id FROM event_session WHERE event_session.id = NEW.event_session_id);
            SET NEW.event_id = (SELECT event_id FROM event_session WHERE event_session.id = NEW.event_session_id);
        END IF;
        
        IF (NEW.for_type = 'event_session' AND NEW.for_id IS NOT NULL)
        THEN
            SET NEW.event_session_id = NEW.for_id;
            SET NEW.event_location_id = (SELECT event_location_id FROM event_session WHERE event_session.id = NEW.for_id);
            SET NEW.event_id = (SELECT event_id FROM event_session WHERE event_session.id = NEW.for_id);
        END IF;
    END;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `event_file_after_delete` AFTER DELETE ON `event_file` FOR EACH ROW BEGIN
    DELETE FROM hosted_file_link WHERE hosted_file_link.hosted_file_id = OLD.hosted_file_id AND hosted_file_link.link_to_type = OLD.for_type AND hosted_file_link.link_to_id = OLD.for_id;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `event_file_after_insert` AFTER INSERT ON `event_file` FOR EACH ROW BEGIN
    INSERT IGNORE INTO hosted_file_link (hosted_file_id, link_to_type, link_to_id) VALUES (NEW.hosted_file_id, NEW.for_type, NEW.for_id);
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `update approved_on` BEFORE UPDATE ON `event_file` FOR EACH ROW IF NEW.approved = 1 THEN SET NEW.approved_on = CURRENT_TIMESTAMP; END IF
$$
DELIMITER ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `event_file`
--
ALTER TABLE `event_file`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_random` (`id_random`),
  ADD UNIQUE KEY `hosted_file_id_for` (`hosted_file_id`,`for_type`,`for_id`),
  ADD KEY `event_session_id` (`event_session_id`),
  ADD KEY `event_id` (`event_id`),
  ADD KEY `hosted_file_id` (`hosted_file_id`),
  ADD KEY `event_presentation_id` (`event_presentation_id`),
  ADD KEY `event_presenter_id` (`event_presenter_id`),
  ADD KEY `event_location_id` (`event_location_id`),
  ADD KEY `created_on` (`created_on`),
  ADD KEY `updated_on` (`updated_on`),
  ADD KEY `event_track_id` (`event_track_id`),
  ADD KEY `event_exhibit_id` (`event_exhibit_id`),
  ADD KEY `hide` (`hide`),
  ADD KEY `enable` (`enable`),
  ADD KEY `sort` (`sort`),
  ADD KEY `priority` (`priority`),
  ADD KEY `for_type` (`for_type`,`for_id`),
  ADD KEY `filename` (`filename`),
  ADD KEY `extension` (`extension`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `event_file`
--
ALTER TABLE `event_file`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;

/*!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 */;
