-- 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 `data_store`
--

CREATE TABLE `data_store` (
  `id` int(11) NOT NULL,
  `id_random` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `account_id` int(11) DEFAULT NULL,
  `for_type` varchar(50) DEFAULT NULL,
  `for_id` int(11) DEFAULT NULL,
  `person_id` int(11) DEFAULT NULL COMMENT 'the creator or owner',
  `user_id` int(11) DEFAULT NULL COMMENT 'the creator or owner',
  `code` varchar(75) NOT NULL COMMENT 'adding a record that matches an existing code should always have an account_id',
  `name` varchar(150) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `type` varchar(10) NOT NULL DEFAULT 'html' COMMENT 'html, json, md, text',
  `json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'case sensitive',
  `text` longtext DEFAULT NULL COMMENT 'case insensitive',
  `meta_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`meta_json`)),
  `meta_text` longtext DEFAULT NULL,
  `access_read` varchar(20) DEFAULT NULL COMMENT '''super'', ''administrator'', ''trusted'', ''anonymous''',
  `access_write` varchar(20) DEFAULT NULL COMMENT '''super'', ''administrator'', ''trusted'', ''anonymous''',
  `access_delete` varchar(20) DEFAULT NULL COMMENT '''super'', ''administrator'', ''trusted'', ''anonymous''',
  `enable` tinyint(1) NOT NULL DEFAULT 0,
  `hide` 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 `data_store`
--
DELIMITER $$
CREATE TRIGGER `before_insert_data_store` BEFORE INSERT ON `data_store` 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_data_store` BEFORE UPDATE ON `data_store` 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 ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `data_store`
--
ALTER TABLE `data_store`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_random` (`id_random`),
  ADD KEY `created_on` (`created_on`),
  ADD KEY `updated_on` (`updated_on`),
  ADD KEY `code` (`code`),
  ADD KEY `account_id` (`account_id`),
  ADD KEY `for_type` (`for_type`,`for_id`),
  ADD KEY `enable` (`enable`),
  ADD KEY `priority` (`priority`),
  ADD KEY `sort` (`sort`),
  ADD KEY `group` (`group`),
  ADD KEY `hide` (`hide`),
  ADD KEY `account_id_2` (`account_id`,`for_type`,`for_id`,`code`,`enable`);

--
-- AUTO_INCREMENT for dumped tables
--

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