-- phpMyAdmin SQL Dump
-- version 5.2.3
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Jan 02, 2026 at 10:19 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 `journal_entry`
--

CREATE TABLE `journal_entry` (
  `id` int(11) NOT NULL,
  `id_random` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `journal_id` int(11) NOT NULL,
  `code` varchar(20) DEFAULT NULL,
  `lu_type_id` int(11) DEFAULT NULL,
  `type` varchar(50) DEFAULT NULL,
  `topic_id` int(11) DEFAULT NULL,
  `topic` varchar(50) DEFAULT NULL,
  `activity_id` int(11) DEFAULT NULL,
  `activity` varchar(50) DEFAULT NULL,
  `private` tinyint(1) DEFAULT NULL COMMENT 'implies encryption if possible',
  `public` tinyint(1) DEFAULT NULL,
  `personal` tinyint(1) DEFAULT NULL,
  `professional` tinyint(1) DEFAULT NULL,
  `name` varchar(250) DEFAULT NULL,
  `short_name` varchar(25) DEFAULT NULL,
  `summary` text DEFAULT NULL,
  `content` text DEFAULT NULL,
  `content_html` text DEFAULT NULL,
  `content_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`content_json`)),
  `content_encrypted` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
  `history` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'content history',
  `history_encrypted` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'content history encrypted',
  `passcode_hash` varchar(64) DEFAULT NULL COMMENT 'to match with index',
  `template` tinyint(1) DEFAULT NULL COMMENT 'use as template entry',
  `type_code` varchar(25) DEFAULT NULL,
  `topic_code` varchar(25) DEFAULT NULL,
  `category_code` varchar(25) DEFAULT NULL,
  `tags` varchar(255) DEFAULT NULL COMMENT 'comma delimited list',
  `start_datetime` datetime DEFAULT NULL,
  `end_datetime` datetime DEFAULT NULL,
  `seconds` int(11) DEFAULT NULL,
  `hours` decimal(3,2) DEFAULT NULL,
  `timezone` varchar(50) DEFAULT NULL,
  `location` text DEFAULT NULL COMMENT 'probably an address',
  `latitude` float DEFAULT NULL,
  `longitude` float DEFAULT NULL,
  `billable` tinyint(1) DEFAULT 0,
  `billable_to_id` int(11) DEFAULT NULL,
  `billiable_to` varchar(100) DEFAULT NULL,
  `alert` tinyint(1) DEFAULT NULL,
  `alert_msg` text DEFAULT NULL,
  `data_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`data_json`)),
  `enable` tinyint(1) NOT NULL DEFAULT 1,
  `hide` tinyint(1) DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `archive_on` datetime DEFAULT NULL,
  `archive` tinyint(1) DEFAULT NULL,
  `priority` tinyint(1) DEFAULT NULL,
  `sort` int(11) DEFAULT NULL,
  `group` varchar(100) DEFAULT NULL,
  `default_qry_str` text DEFAULT NULL COMMENT 'for FULLTEXT indexed searches',
  `notes` text DEFAULT NULL,
  `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 `journal_entry`
--
DELIMITER $$
CREATE TRIGGER `before_insert_journal_entry` BEFORE INSERT ON `journal_entry` 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_pattern('3CN-2CN-2CN-2CN');
            /* SET NEW.id_random = gen_rand_str(11, 'URL'); */
        END IF;
		
		SET NEW.default_qry_str = journal_entry_default_qry_str(NEW.id_random, NEW.name, NEW.summary, NEW.content, NEW.history, NEW.category_code, NEW.tags, NEW.alert_msg, NEW.data_json);
    END;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `before_update_journal_entry` BEFORE UPDATE ON `journal_entry` 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_pattern('3CN-2CN-2CN-2CN');
            /* SET NEW.id_random = gen_rand_str(11, 'URL'); */
        END IF;
		
		SET NEW.default_qry_str = journal_entry_default_qry_str(NEW.id_random, NEW.name, NEW.summary, NEW.content, NEW.history, NEW.category_code, NEW.tags, NEW.alert_msg, NEW.data_json);
    END;
END
$$
DELIMITER ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `journal_entry`
--
ALTER TABLE `journal_entry`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_random` (`id_random`),
  ADD KEY `journal_id` (`journal_id`),
  ADD KEY `tags` (`tags`),
  ADD KEY `enable` (`enable`),
  ADD KEY `hide` (`hide`),
  ADD KEY `status` (`status`),
  ADD KEY `priority` (`priority`),
  ADD KEY `archive` (`archive`),
  ADD KEY `sort` (`sort`),
  ADD KEY `group` (`group`),
  ADD KEY `created_on` (`created_on`),
  ADD KEY `updated_on` (`updated_on`),
  ADD KEY `start_datetime` (`start_datetime`),
  ADD KEY `private` (`private`),
  ADD KEY `public` (`public`),
  ADD KEY `personal` (`personal`),
  ADD KEY `professional` (`professional`),
  ADD KEY `name` (`name`);
ALTER TABLE `journal_entry` ADD FULLTEXT KEY `tbl_fulltext_default_qry_str` (`default_qry_str`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `journal_entry`
--
ALTER TABLE `journal_entry`
  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 */;
