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

CREATE TABLE `journal` (
  `id` int(11) NOT NULL,
  `id_random` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `account_id` int(11) DEFAULT NULL,
  `person_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `type_code` varchar(25) DEFAULT NULL,
  `default_private` tinyint(1) DEFAULT NULL COMMENT 'default to private',
  `default_public` tinyint(1) DEFAULT NULL COMMENT 'default to public',
  `default_personal` tinyint(1) DEFAULT NULL COMMENT 'default to personal',
  `default_professional` tinyint(1) DEFAULT NULL COMMENT 'default to professional',
  `private_passcode` varchar(20) DEFAULT NULL COMMENT 'passcode to show private entries',
  `public_passcode` varchar(20) DEFAULT NULL COMMENT 'passcode to show only public entries',
  `name` varchar(250) NOT NULL,
  `short_name` varchar(25) DEFAULT NULL,
  `summary` text DEFAULT NULL,
  `outline` text DEFAULT NULL,
  `description` text DEFAULT NULL,
  `description_html` text DEFAULT NULL,
  `description_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`description_json`)),
  `alert` tinyint(1) DEFAULT NULL,
  `alert_msg` text DEFAULT NULL,
  `allow_auth` tinyint(1) NOT NULL DEFAULT 0,
  `auth_key` varchar(25) DEFAULT NULL,
  `passcode` varchar(25) DEFAULT NULL,
  `passcode_timeout` int(11) NOT NULL DEFAULT 300 COMMENT 'in seconds',
  `cfg_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`cfg_json`)),
  `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,
  `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`
--
DELIMITER $$
CREATE TRIGGER `before_insert_journal` BEFORE INSERT ON `journal` 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_default_qry_str(NEW.id_random, NEW.name, NEW.summary, NEW.description); */
    END;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `before_update_journal` BEFORE UPDATE ON `journal` 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_default_qry_str(NEW.id_random, NEW.name, NEW.summary, NEW.description); */
    END;
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `journal_after_delete` AFTER DELETE ON `journal` FOR EACH ROW BEGIN
    DELETE FROM journal_entry WHERE journal_entry.journal_id = OLD.id;
END
$$
DELIMITER ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `journal`
--
ALTER TABLE `journal`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_random` (`id_random`),
  ADD KEY `account_id` (`account_id`);

--
-- AUTO_INCREMENT for dumped tables
--

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