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

CREATE TABLE `account` (
  `id` int(11) NOT NULL,
  `id_random` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `code` varchar(50) DEFAULT NULL,
  `name` varchar(200) DEFAULT NULL,
  `short_name` varchar(20) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `enable` tinyint(1) NOT NULL DEFAULT 0,
  `enable_from` datetime DEFAULT NULL,
  `enable_to` datetime 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 `account`
--
DELIMITER $$
CREATE TRIGGER `before_insert_account` BEFORE INSERT ON `account` 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_account` BEFORE UPDATE ON `account` 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 `account`
--
ALTER TABLE `account`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_random` (`id_random`),
  ADD UNIQUE KEY `code` (`code`),
  ADD KEY `enable` (`enable`),
  ADD KEY `name` (`name`),
  ADD KEY `created_on` (`created_on`),
  ADD KEY `updated_on` (`updated_on`);

--
-- AUTO_INCREMENT for dumped tables
--

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