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

CREATE TABLE `person` (
  `id` int(11) NOT NULL,
  `id_random` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `source_code` varchar(25) DEFAULT NULL,
  `external_id` varchar(75) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
  `external_sys_id` varchar(75) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'generated by external system',
  `account_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `organization_id` int(11) DEFAULT NULL,
  `informal_name` varchar(50) DEFAULT NULL COMMENT 'nickname',
  `title_names` varchar(100) DEFAULT NULL COMMENT 'prefix',
  `given_name` varchar(50) NOT NULL DEFAULT '' COMMENT 'first name',
  `middle_name` varchar(50) DEFAULT NULL,
  `family_name` varchar(50) DEFAULT NULL COMMENT 'last name',
  `designations` varchar(175) DEFAULT NULL COMMENT 'designations and suffix',
  `professional_title` varchar(100) DEFAULT NULL COMMENT ' includes degrees and credentials ',
  `full_name` varchar(150) DEFAULT NULL COMMENT 'set by triggers',
  `full_name_override` varchar(150) DEFAULT NULL COMMENT 'was display_name',
  `last_first_name` varchar(50) DEFAULT NULL COMMENT 'set by triggers',
  `informal_full_name` varchar(150) DEFAULT NULL COMMENT 'set by triggers',
  `affiliations` varchar(200) DEFAULT NULL,
  `primary_email` varchar(254) DEFAULT NULL,
  `tagline` text DEFAULT NULL,
  `description` text DEFAULT NULL,
  `biography` text DEFAULT NULL,
  `birth_date` date DEFAULT NULL,
  `death_date` date DEFAULT NULL,
  `lu_gender_id` int(11) DEFAULT NULL,
  `lu_sexuality_id` int(11) DEFAULT NULL,
  `lu_race_id` int(11) DEFAULT NULL,
  `lu_ethnicity_id` int(11) DEFAULT NULL,
  `language_native` varchar(2) DEFAULT NULL,
  `language_primary` varchar(2) DEFAULT NULL,
  `language_secondary` varchar(2) DEFAULT NULL,
  `lu_education_degree_id` int(11) DEFAULT NULL,
  `lu_education_level_id` int(11) DEFAULT NULL,
  `photo_path` varchar(2500) DEFAULT NULL,
  `photo_bg_color` varchar(25) DEFAULT NULL,
  `thumbnail_path` varchar(2500) DEFAULT NULL,
  `thumbnail_bg_color` varchar(25) DEFAULT NULL,
  `email_allowed` tinyint(1) DEFAULT NULL COMMENT 'global opt in or out for person',
  `paper_mail_allowed` tinyint(1) DEFAULT NULL COMMENT 'global opt in or out for person',
  `stripe_customer_id` varchar(50) DEFAULT NULL,
  `allow_auth_key` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'defaults to true',
  `auth_key` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
  `passcode` varchar(25) DEFAULT NULL COMMENT 'for basic access',
  `status` varchar(25) DEFAULT NULL COMMENT 'pending, hold, approved, rejected, banned, retired, deceased',
  `status_id` int(11) DEFAULT NULL COMMENT 'not sure if using yet 2022-03-15',
  `hide` tinyint(1) DEFAULT NULL,
  `priority` tinyint(1) DEFAULT NULL,
  `sort` int(11) DEFAULT NULL,
  `group` varchar(100) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `cfg_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'config options' CHECK (json_valid(`cfg_json`)),
  `data_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`data_json`)),
  `other_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
  `meta_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`meta_json`)),
  `enable` tinyint(1) DEFAULT 1,
  `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 COMMENT='Information that generally does not change often or ever.';

--
-- Triggers `person`
--
DELIMITER $$
CREATE TRIGGER `before_insert_person` BEFORE INSERT ON `person` 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_person_names` BEFORE INSERT ON `person` FOR EACH ROW BEGIN
    SET NEW.full_name = name_for_full_name(NEW.informal_name, NEW.title_names, NEW.given_name, NEW.middle_name, NEW.family_name, NEW.designations);
	
	 SET NEW.last_first_name = name_for_last_first_name(NEW.given_name, NEW.middle_name, NEW.family_name);
   
    SET NEW.informal_full_name = name_for_informal_full_name(NEW.informal_name, NEW.title_names, NEW.given_name, NEW.middle_name, NEW.family_name, NEW.designations);
	
    /*
    IF (NEW.full_name_override IS NULL OR NEW.full_name_override = '')
    THEN
        SET NEW.full_name_override = name_for_display_name(NEW.informal_name, NEW.given_name, NEW.middle_name, NEW.family_name);
    END IF;
	*/
   
   /*
    IF (NEW.informal_full_name_override IS NULL OR NEW.informal_full_name_override = '')
    THEN
        SET NEW.informal_full_name_override = name_for_informal_display_name(NEW.informal_name, NEW.given_name, NEW.middle_name, NEW.family_name);
    END IF;
	*/
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `before_update_person` BEFORE UPDATE ON `person` 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_person_names` BEFORE UPDATE ON `person` FOR EACH ROW BEGIN
    SET NEW.full_name = name_for_full_name(NEW.informal_name, NEW.title_names, NEW.given_name, NEW.middle_name, NEW.family_name, NEW.designations);
    
	SET NEW.last_first_name = name_for_last_first_name(NEW.given_name, NEW.middle_name, NEW.family_name);
   
    SET NEW.informal_full_name = name_for_informal_full_name(NEW.informal_name, NEW.title_names, NEW.given_name, NEW.middle_name, NEW.family_name, NEW.designations);
	
    /*
    IF (NEW.full_name_override IS NULL OR NEW.full_name_override = '')
    THEN
        SET NEW.full_name_override = name_for_display_name(NEW.informal_name, NEW.given_name, NEW.middle_name, NEW.family_name);
    END IF;
	*/
   
    /*
	IF (NEW.informal_full_name_override IS NULL OR NEW.informal_full_name_override = '')
    THEN
        SET NEW.informal_full_name_override = name_for_informal_display_name(NEW.informal_name, NEW.given_name, NEW.middle_name, NEW.family_name);
    END IF;
	*/
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `person_after_delete` AFTER DELETE ON `person` FOR EACH ROW BEGIN
DELETE FROM user WHERE user.id = old.user_id;
DELETE FROM contact WHERE contact.for_id = old.id AND contact.for_type = 'person';
END
$$
DELIMITER ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `person`
--
ALTER TABLE `person`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_random` (`id_random`),
  ADD KEY `account_id` (`account_id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `organization_id` (`organization_id`),
  ADD KEY `created_on` (`created_on`),
  ADD KEY `updated_on` (`updated_on`),
  ADD KEY `external_id` (`external_sys_id`),
  ADD KEY `family_name` (`family_name`),
  ADD KEY `given_name` (`given_name`),
  ADD KEY `enable` (`enable`),
  ADD KEY `priority` (`priority`),
  ADD KEY `sort` (`sort`),
  ADD KEY `group` (`group`);

--
-- AUTO_INCREMENT for dumped tables
--

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