-- phpMyAdmin SQL Dump
-- version 5.2.1deb3
-- https://www.phpmyadmin.net/
--
-- Servidor: galappxy-admin.cluster-co7jnudpcxvn.us-east-1.rds.amazonaws.com:3306
-- Tiempo de generación: 15-02-2026 a las 14:07:48
-- Versión del servidor: 8.0.39
-- Versión de PHP: 8.4.6

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 */;

--
-- Base de datos: `galappxy_core`
--

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `APP`
--

CREATE TABLE `APP` (
  `id` bigint UNSIGNED NOT NULL,
  `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `APP_BUILD`
--

CREATE TABLE `APP_BUILD` (
  `id` bigint UNSIGNED NOT NULL,
  `id_app` bigint UNSIGNED NOT NULL,
  `env` enum('prod','stage','dev') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'prod',
  `mount_type` enum('iframe','webcomponent','native') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'iframe',
  `entry_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tag_name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `default_route` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '/',
  `version` int UNSIGNED NOT NULL DEFAULT '1',
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `APP_SCREEN`
--

CREATE TABLE `APP_SCREEN` (
  `id` bigint UNSIGNED NOT NULL,
  `code` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `id_app` bigint UNSIGNED NOT NULL,
  `path` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `title_default` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRANCH`
--

CREATE TABLE `BRANCH` (
  `id` bigint UNSIGNED NOT NULL,
  `id_company` bigint UNSIGNED NOT NULL,
  `id_region` bigint UNSIGNED DEFAULT NULL,
  `name` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
  `timezone` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `language` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('active','inactive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND`
--

CREATE TABLE `BRAND` (
  `id` bigint UNSIGNED NOT NULL,
  `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_default` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `icon` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `logo` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `theme_config_json` json DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_DOMAIN`
--

CREATE TABLE `BRAND_DOMAIN` (
  `id` bigint UNSIGNED NOT NULL,
  `host` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `id_brand` bigint UNSIGNED NOT NULL,
  `cookie_root` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_MENU`
--

CREATE TABLE `BRAND_MENU` (
  `id` bigint UNSIGNED NOT NULL,
  `id_brand_module` bigint UNSIGNED NOT NULL,
  `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `label_default` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `icon` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort` int UNSIGNED NOT NULL DEFAULT '100',
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_MENU_COMPANY_OVERRIDE`
--

CREATE TABLE `BRAND_MENU_COMPANY_OVERRIDE` (
  `id_company` bigint UNSIGNED NOT NULL,
  `id_menu` bigint UNSIGNED NOT NULL,
  `label` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `icon` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort` int UNSIGNED DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_MODULE`
--

CREATE TABLE `BRAND_MODULE` (
  `id` bigint UNSIGNED NOT NULL,
  `id_brand` bigint UNSIGNED NOT NULL,
  `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_default` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `icon` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `theme_config_json` json DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_MODULE_COMPANY_OVERRIDE`
--

CREATE TABLE `BRAND_MODULE_COMPANY_OVERRIDE` (
  `id_company` bigint UNSIGNED NOT NULL,
  `id_brand_module` bigint UNSIGNED NOT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `sort` int UNSIGNED NOT NULL DEFAULT '100',
  `name` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `theme_config_json` json DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_MODULE_DOMAIN`
--

CREATE TABLE `BRAND_MODULE_DOMAIN` (
  `id` bigint UNSIGNED NOT NULL,
  `host` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `id_brand_module` bigint UNSIGNED NOT NULL,
  `cookie_root` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_MODULE_PROFILE`
--

CREATE TABLE `BRAND_MODULE_PROFILE` (
  `id_profile` bigint UNSIGNED NOT NULL,
  `id_brand_module` bigint UNSIGNED NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_MODULE_ROLE`
--

CREATE TABLE `BRAND_MODULE_ROLE` (
  `id_role` bigint UNSIGNED NOT NULL,
  `id_brand_module` bigint UNSIGNED NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_SCREEN`
--

CREATE TABLE `BRAND_SCREEN` (
  `id_menu` bigint UNSIGNED NOT NULL,
  `id_app_screen` bigint UNSIGNED NOT NULL,
  `label` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `icon` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort` int UNSIGNED NOT NULL DEFAULT '100',
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_SCREEN_COMPANY_OVERRIDE`
--

CREATE TABLE `BRAND_SCREEN_COMPANY_OVERRIDE` (
  `id_company` bigint UNSIGNED NOT NULL,
  `id_app_screen` bigint UNSIGNED NOT NULL,
  `label` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `icon` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort` int UNSIGNED DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_SCREEN_PROFILE`
--

CREATE TABLE `BRAND_SCREEN_PROFILE` (
  `id_profile` bigint UNSIGNED NOT NULL,
  `id_app_screen` bigint UNSIGNED NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `BRAND_SCREEN_ROLE`
--

CREATE TABLE `BRAND_SCREEN_ROLE` (
  `id_role` bigint UNSIGNED NOT NULL,
  `id_app_screen` bigint UNSIGNED NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `COMPANY`
--

CREATE TABLE `COMPANY` (
  `id` bigint UNSIGNED NOT NULL,
  `name` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` enum('active','inactive','suspended') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `timezone` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UTC',
  `language` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'es',
  `role_scope` enum('company','branch') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'company',
  `subscription_scope` enum('company','branch') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'company',
  `id_branch_primary` bigint UNSIGNED DEFAULT NULL,
  `menu_preset` enum('modules_grid','sidebar_3_levels') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'modules_grid',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PERMISSION`
--

CREATE TABLE `PERMISSION` (
  `id` bigint UNSIGNED NOT NULL,
  `code` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PERMISSION_PROFILE`
--

CREATE TABLE `PERMISSION_PROFILE` (
  `id_profile` bigint UNSIGNED NOT NULL,
  `id_app_screen` bigint UNSIGNED NOT NULL,
  `id_permission` bigint UNSIGNED NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PERMISSION_ROLE`
--

CREATE TABLE `PERMISSION_ROLE` (
  `id_role` bigint UNSIGNED NOT NULL,
  `id_app_screen` bigint UNSIGNED NOT NULL,
  `id_permission` bigint UNSIGNED NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PERMISSION_SCREEN`
--

CREATE TABLE `PERMISSION_SCREEN` (
  `id_app_screen` bigint UNSIGNED NOT NULL,
  `id_permission` bigint UNSIGNED NOT NULL,
  `label_default` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PLAN`
--

CREATE TABLE `PLAN` (
  `id` bigint UNSIGNED NOT NULL,
  `id_brand` bigint UNSIGNED NOT NULL,
  `name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `price` decimal(10,2) NOT NULL DEFAULT '0.00',
  `status` enum('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PLAN_PERMISSION`
--

CREATE TABLE `PLAN_PERMISSION` (
  `id_plan` bigint UNSIGNED NOT NULL,
  `id_permission` bigint UNSIGNED NOT NULL,
  `limits_json` json DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PLAN_SUBSCRIPTION`
--

CREATE TABLE `PLAN_SUBSCRIPTION` (
  `id` bigint UNSIGNED NOT NULL,
  `scope_type` enum('company','branch') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `id_company` bigint UNSIGNED NOT NULL,
  `id_branch` bigint UNSIGNED DEFAULT NULL,
  `id_plan` bigint UNSIGNED NOT NULL,
  `status` enum('active','inactive','canceled','expired') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `start_at` datetime NOT NULL,
  `end_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PROFILE`
--

CREATE TABLE `PROFILE` (
  `id` bigint UNSIGNED NOT NULL,
  `id_user` bigint UNSIGNED NOT NULL,
  `id_company` bigint UNSIGNED NOT NULL,
  `id_role` bigint UNSIGNED NOT NULL,
  `id_branch_primary` bigint UNSIGNED NOT NULL,
  `code` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `name` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
  `paternal` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `maternal` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('active','inactive','blocked') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PROFILE_BRANCH`
--

CREATE TABLE `PROFILE_BRANCH` (
  `id_profile` bigint UNSIGNED NOT NULL,
  `id_branch` bigint UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `PROFILE_GROUP`
--

CREATE TABLE `PROFILE_GROUP` (
  `id_profile_owner` bigint UNSIGNED NOT NULL,
  `id_profile_member` bigint UNSIGNED NOT NULL,
  `relation_type` enum('parent_of','guardian_of','other') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'parent_of',
  `status` enum('active','inactive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `REGION`
--

CREATE TABLE `REGION` (
  `id` bigint UNSIGNED NOT NULL,
  `id_company` bigint UNSIGNED NOT NULL,
  `name` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` enum('active','inactive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `ROLE`
--

CREATE TABLE `ROLE` (
  `id` bigint UNSIGNED NOT NULL,
  `id_company` bigint UNSIGNED NOT NULL,
  `id_branch` bigint UNSIGNED NOT NULL,
  `name` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` enum('active','inactive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `USER`
--

CREATE TABLE `USER` (
  `id` bigint UNSIGNED NOT NULL,
  `name` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `paternal` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `maternal` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(190) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `birthdate` date DEFAULT NULL,
  `timezone` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UTC',
  `language` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'es',
  `status` enum('active','inactive','blocked') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Índices para tablas volcadas
--

--
-- Indices de la tabla `APP`
--
ALTER TABLE `APP`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_app_code` (`code`),
  ADD KEY `idx_app_status` (`status`);

--
-- Indices de la tabla `APP_BUILD`
--
ALTER TABLE `APP_BUILD`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_app_build_app_env_version` (`id_app`,`env`,`version`),
  ADD KEY `idx_app_build_app_env` (`id_app`,`env`,`status`);

--
-- Indices de la tabla `APP_SCREEN`
--
ALTER TABLE `APP_SCREEN`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_app_screen_code` (`code`),
  ADD KEY `idx_app_screen_app` (`id_app`,`status`);

--
-- Indices de la tabla `BRANCH`
--
ALTER TABLE `BRANCH`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_branch_company_name` (`id_company`,`name`),
  ADD KEY `idx_branch_company` (`id_company`),
  ADD KEY `idx_branch_region` (`id_region`);

--
-- Indices de la tabla `BRAND`
--
ALTER TABLE `BRAND`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_brand_code` (`code`),
  ADD KEY `idx_brand_status` (`status`);

--
-- Indices de la tabla `BRAND_DOMAIN`
--
ALTER TABLE `BRAND_DOMAIN`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_brand_domain_host` (`host`),
  ADD KEY `idx_brand_domain_brand` (`id_brand`,`status`);

--
-- Indices de la tabla `BRAND_MENU`
--
ALTER TABLE `BRAND_MENU`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_brand_menu_module_code` (`id_brand_module`,`code`),
  ADD KEY `idx_brand_menu_module_sort` (`id_brand_module`,`status`,`sort`);

--
-- Indices de la tabla `BRAND_MENU_COMPANY_OVERRIDE`
--
ALTER TABLE `BRAND_MENU_COMPANY_OVERRIDE`
  ADD PRIMARY KEY (`id_company`,`id_menu`),
  ADD KEY `idx_bmco_menu` (`id_menu`,`status`);

--
-- Indices de la tabla `BRAND_MODULE`
--
ALTER TABLE `BRAND_MODULE`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_brand_module_brand_code` (`id_brand`,`code`),
  ADD KEY `idx_brand_module_brand` (`id_brand`,`status`);

--
-- Indices de la tabla `BRAND_MODULE_COMPANY_OVERRIDE`
--
ALTER TABLE `BRAND_MODULE_COMPANY_OVERRIDE`
  ADD PRIMARY KEY (`id_company`,`id_brand_module`),
  ADD KEY `idx_bmc_company_sort` (`id_company`,`status`,`sort`),
  ADD KEY `idx_bmc_module` (`id_brand_module`,`status`);

--
-- Indices de la tabla `BRAND_MODULE_DOMAIN`
--
ALTER TABLE `BRAND_MODULE_DOMAIN`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_brand_module_domain_host` (`host`),
  ADD KEY `idx_brand_module_domain_module` (`id_brand_module`,`status`);

--
-- Indices de la tabla `BRAND_MODULE_PROFILE`
--
ALTER TABLE `BRAND_MODULE_PROFILE`
  ADD PRIMARY KEY (`id_profile`,`id_brand_module`),
  ADD KEY `idx_bmp_module` (`id_brand_module`,`enabled`);

--
-- Indices de la tabla `BRAND_MODULE_ROLE`
--
ALTER TABLE `BRAND_MODULE_ROLE`
  ADD PRIMARY KEY (`id_role`,`id_brand_module`),
  ADD KEY `idx_bmr_module` (`id_brand_module`,`enabled`);

--
-- Indices de la tabla `BRAND_SCREEN`
--
ALTER TABLE `BRAND_SCREEN`
  ADD PRIMARY KEY (`id_menu`,`id_app_screen`),
  ADD KEY `idx_brand_screen_screen` (`id_app_screen`),
  ADD KEY `idx_brand_screen_menu_sort` (`id_menu`,`status`,`sort`);

--
-- Indices de la tabla `BRAND_SCREEN_COMPANY_OVERRIDE`
--
ALTER TABLE `BRAND_SCREEN_COMPANY_OVERRIDE`
  ADD PRIMARY KEY (`id_company`,`id_app_screen`),
  ADD KEY `idx_bsc_screen` (`id_app_screen`,`status`);

--
-- Indices de la tabla `BRAND_SCREEN_PROFILE`
--
ALTER TABLE `BRAND_SCREEN_PROFILE`
  ADD PRIMARY KEY (`id_profile`,`id_app_screen`),
  ADD KEY `idx_bsp_screen` (`id_app_screen`,`enabled`);

--
-- Indices de la tabla `BRAND_SCREEN_ROLE`
--
ALTER TABLE `BRAND_SCREEN_ROLE`
  ADD PRIMARY KEY (`id_role`,`id_app_screen`),
  ADD KEY `idx_bsr_screen` (`id_app_screen`,`enabled`);

--
-- Indices de la tabla `COMPANY`
--
ALTER TABLE `COMPANY`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_company_status` (`status`),
  ADD KEY `idx_company_primary_branch` (`id_branch_primary`);

--
-- Indices de la tabla `PERMISSION`
--
ALTER TABLE `PERMISSION`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_permission_code` (`code`),
  ADD KEY `idx_permission_status` (`status`);

--
-- Indices de la tabla `PERMISSION_PROFILE`
--
ALTER TABLE `PERMISSION_PROFILE`
  ADD PRIMARY KEY (`id_profile`,`id_app_screen`,`id_permission`),
  ADD KEY `idx_pp_screen` (`id_app_screen`,`enabled`),
  ADD KEY `idx_pp_permission` (`id_permission`,`enabled`),
  ADD KEY `fk_pp_perm_screen` (`id_app_screen`,`id_permission`);

--
-- Indices de la tabla `PERMISSION_ROLE`
--
ALTER TABLE `PERMISSION_ROLE`
  ADD PRIMARY KEY (`id_role`,`id_app_screen`,`id_permission`),
  ADD KEY `idx_pr_screen` (`id_app_screen`,`enabled`),
  ADD KEY `idx_pr_permission` (`id_permission`,`enabled`),
  ADD KEY `fk_pr_perm_screen` (`id_app_screen`,`id_permission`);

--
-- Indices de la tabla `PERMISSION_SCREEN`
--
ALTER TABLE `PERMISSION_SCREEN`
  ADD PRIMARY KEY (`id_app_screen`,`id_permission`),
  ADD KEY `idx_ps_permission` (`id_permission`,`status`);

--
-- Indices de la tabla `PLAN`
--
ALTER TABLE `PLAN`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_plan_brand_name` (`id_brand`,`name`),
  ADD KEY `idx_plan_brand` (`id_brand`,`status`);

--
-- Indices de la tabla `PLAN_PERMISSION`
--
ALTER TABLE `PLAN_PERMISSION`
  ADD PRIMARY KEY (`id_plan`,`id_permission`),
  ADD KEY `idx_plan_permission_permission` (`id_permission`);

--
-- Indices de la tabla `PLAN_SUBSCRIPTION`
--
ALTER TABLE `PLAN_SUBSCRIPTION`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_plsub_company` (`id_company`,`status`,`start_at`),
  ADD KEY `idx_plsub_branch` (`id_branch`,`status`,`start_at`),
  ADD KEY `idx_plsub_plan` (`id_plan`);

--
-- Indices de la tabla `PROFILE`
--
ALTER TABLE `PROFILE`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_profile_user` (`id_user`),
  ADD KEY `idx_profile_company` (`id_company`),
  ADD KEY `idx_profile_role` (`id_role`),
  ADD KEY `idx_profile_branch_primary` (`id_branch_primary`),
  ADD KEY `idx_profile_code` (`code`);

--
-- Indices de la tabla `PROFILE_BRANCH`
--
ALTER TABLE `PROFILE_BRANCH`
  ADD PRIMARY KEY (`id_profile`,`id_branch`),
  ADD KEY `idx_profile_branch_branch` (`id_branch`);

--
-- Indices de la tabla `PROFILE_GROUP`
--
ALTER TABLE `PROFILE_GROUP`
  ADD PRIMARY KEY (`id_profile_owner`,`id_profile_member`),
  ADD KEY `idx_profile_group_member` (`id_profile_member`);

--
-- Indices de la tabla `REGION`
--
ALTER TABLE `REGION`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_region_company_name` (`id_company`,`name`),
  ADD KEY `idx_region_company` (`id_company`);

--
-- Indices de la tabla `ROLE`
--
ALTER TABLE `ROLE`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_role_company_branch_name` (`id_company`,`id_branch`,`name`),
  ADD KEY `idx_role_company` (`id_company`),
  ADD KEY `idx_role_branch` (`id_branch`);

--
-- Indices de la tabla `USER`
--
ALTER TABLE `USER`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_email` (`email`),
  ADD KEY `idx_user_phone` (`phone`),
  ADD KEY `idx_user_status` (`status`);

--
-- AUTO_INCREMENT de las tablas volcadas
--

--
-- AUTO_INCREMENT de la tabla `APP`
--
ALTER TABLE `APP`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `APP_BUILD`
--
ALTER TABLE `APP_BUILD`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `APP_SCREEN`
--
ALTER TABLE `APP_SCREEN`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `BRANCH`
--
ALTER TABLE `BRANCH`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `BRAND`
--
ALTER TABLE `BRAND`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `BRAND_DOMAIN`
--
ALTER TABLE `BRAND_DOMAIN`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `BRAND_MENU`
--
ALTER TABLE `BRAND_MENU`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `BRAND_MODULE`
--
ALTER TABLE `BRAND_MODULE`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `BRAND_MODULE_DOMAIN`
--
ALTER TABLE `BRAND_MODULE_DOMAIN`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `COMPANY`
--
ALTER TABLE `COMPANY`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `PERMISSION`
--
ALTER TABLE `PERMISSION`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `PLAN`
--
ALTER TABLE `PLAN`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `PLAN_SUBSCRIPTION`
--
ALTER TABLE `PLAN_SUBSCRIPTION`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `PROFILE`
--
ALTER TABLE `PROFILE`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `REGION`
--
ALTER TABLE `REGION`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `ROLE`
--
ALTER TABLE `ROLE`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `USER`
--
ALTER TABLE `USER`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- Restricciones para tablas volcadas
--

--
-- Filtros para la tabla `APP_BUILD`
--
ALTER TABLE `APP_BUILD`
  ADD CONSTRAINT `fk_app_build_app` FOREIGN KEY (`id_app`) REFERENCES `APP` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `APP_SCREEN`
--
ALTER TABLE `APP_SCREEN`
  ADD CONSTRAINT `fk_app_screen_app` FOREIGN KEY (`id_app`) REFERENCES `APP` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRANCH`
--
ALTER TABLE `BRANCH`
  ADD CONSTRAINT `fk_branch_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_branch_region` FOREIGN KEY (`id_region`) REFERENCES `REGION` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_DOMAIN`
--
ALTER TABLE `BRAND_DOMAIN`
  ADD CONSTRAINT `fk_brand_domain_brand` FOREIGN KEY (`id_brand`) REFERENCES `BRAND` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_MENU`
--
ALTER TABLE `BRAND_MENU`
  ADD CONSTRAINT `fk_brand_menu_module` FOREIGN KEY (`id_brand_module`) REFERENCES `BRAND_MODULE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_MENU_COMPANY_OVERRIDE`
--
ALTER TABLE `BRAND_MENU_COMPANY_OVERRIDE`
  ADD CONSTRAINT `fk_bmco_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_bmco_menu` FOREIGN KEY (`id_menu`) REFERENCES `BRAND_MENU` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_MODULE`
--
ALTER TABLE `BRAND_MODULE`
  ADD CONSTRAINT `fk_brand_module_brand` FOREIGN KEY (`id_brand`) REFERENCES `BRAND` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_MODULE_COMPANY_OVERRIDE`
--
ALTER TABLE `BRAND_MODULE_COMPANY_OVERRIDE`
  ADD CONSTRAINT `fk_bmc_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_bmc_module` FOREIGN KEY (`id_brand_module`) REFERENCES `BRAND_MODULE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_MODULE_DOMAIN`
--
ALTER TABLE `BRAND_MODULE_DOMAIN`
  ADD CONSTRAINT `fk_brand_module_domain_module` FOREIGN KEY (`id_brand_module`) REFERENCES `BRAND_MODULE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_MODULE_PROFILE`
--
ALTER TABLE `BRAND_MODULE_PROFILE`
  ADD CONSTRAINT `fk_bmp_module` FOREIGN KEY (`id_brand_module`) REFERENCES `BRAND_MODULE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_bmp_profile` FOREIGN KEY (`id_profile`) REFERENCES `PROFILE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_MODULE_ROLE`
--
ALTER TABLE `BRAND_MODULE_ROLE`
  ADD CONSTRAINT `fk_bmr_module` FOREIGN KEY (`id_brand_module`) REFERENCES `BRAND_MODULE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_bmr_role` FOREIGN KEY (`id_role`) REFERENCES `ROLE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_SCREEN`
--
ALTER TABLE `BRAND_SCREEN`
  ADD CONSTRAINT `fk_brand_screen_app_screen` FOREIGN KEY (`id_app_screen`) REFERENCES `APP_SCREEN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_brand_screen_menu` FOREIGN KEY (`id_menu`) REFERENCES `BRAND_MENU` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_SCREEN_COMPANY_OVERRIDE`
--
ALTER TABLE `BRAND_SCREEN_COMPANY_OVERRIDE`
  ADD CONSTRAINT `fk_bsc_app_screen` FOREIGN KEY (`id_app_screen`) REFERENCES `APP_SCREEN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_bsc_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_SCREEN_PROFILE`
--
ALTER TABLE `BRAND_SCREEN_PROFILE`
  ADD CONSTRAINT `fk_bsp_app_screen` FOREIGN KEY (`id_app_screen`) REFERENCES `APP_SCREEN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_bsp_profile` FOREIGN KEY (`id_profile`) REFERENCES `PROFILE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `BRAND_SCREEN_ROLE`
--
ALTER TABLE `BRAND_SCREEN_ROLE`
  ADD CONSTRAINT `fk_bsr_app_screen` FOREIGN KEY (`id_app_screen`) REFERENCES `APP_SCREEN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_bsr_role` FOREIGN KEY (`id_role`) REFERENCES `ROLE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `COMPANY`
--
ALTER TABLE `COMPANY`
  ADD CONSTRAINT `fk_company_branch_primary` FOREIGN KEY (`id_branch_primary`) REFERENCES `BRANCH` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;

--
-- Filtros para la tabla `PERMISSION_PROFILE`
--
ALTER TABLE `PERMISSION_PROFILE`
  ADD CONSTRAINT `fk_pp_app_screen` FOREIGN KEY (`id_app_screen`) REFERENCES `APP_SCREEN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_pp_perm_screen` FOREIGN KEY (`id_app_screen`,`id_permission`) REFERENCES `PERMISSION_SCREEN` (`id_app_screen`, `id_permission`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_pp_permission` FOREIGN KEY (`id_permission`) REFERENCES `PERMISSION` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_pp_profile` FOREIGN KEY (`id_profile`) REFERENCES `PROFILE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `PERMISSION_ROLE`
--
ALTER TABLE `PERMISSION_ROLE`
  ADD CONSTRAINT `fk_pr_app_screen` FOREIGN KEY (`id_app_screen`) REFERENCES `APP_SCREEN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_pr_perm_screen` FOREIGN KEY (`id_app_screen`,`id_permission`) REFERENCES `PERMISSION_SCREEN` (`id_app_screen`, `id_permission`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_pr_permission` FOREIGN KEY (`id_permission`) REFERENCES `PERMISSION` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_pr_role` FOREIGN KEY (`id_role`) REFERENCES `ROLE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `PERMISSION_SCREEN`
--
ALTER TABLE `PERMISSION_SCREEN`
  ADD CONSTRAINT `fk_ps_app_screen` FOREIGN KEY (`id_app_screen`) REFERENCES `APP_SCREEN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_ps_permission` FOREIGN KEY (`id_permission`) REFERENCES `PERMISSION` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `PLAN`
--
ALTER TABLE `PLAN`
  ADD CONSTRAINT `fk_plan_brand` FOREIGN KEY (`id_brand`) REFERENCES `BRAND` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `PLAN_PERMISSION`
--
ALTER TABLE `PLAN_PERMISSION`
  ADD CONSTRAINT `fk_plan_permission_permission` FOREIGN KEY (`id_permission`) REFERENCES `PERMISSION` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_plan_permission_plan` FOREIGN KEY (`id_plan`) REFERENCES `PLAN` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `PLAN_SUBSCRIPTION`
--
ALTER TABLE `PLAN_SUBSCRIPTION`
  ADD CONSTRAINT `fk_plsub_branch` FOREIGN KEY (`id_branch`) REFERENCES `BRANCH` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_plsub_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_plsub_plan` FOREIGN KEY (`id_plan`) REFERENCES `PLAN` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

--
-- Filtros para la tabla `PROFILE`
--
ALTER TABLE `PROFILE`
  ADD CONSTRAINT `fk_profile_branch_primary` FOREIGN KEY (`id_branch_primary`) REFERENCES `BRANCH` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_profile_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_profile_role` FOREIGN KEY (`id_role`) REFERENCES `ROLE` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_profile_user` FOREIGN KEY (`id_user`) REFERENCES `USER` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

--
-- Filtros para la tabla `PROFILE_BRANCH`
--
ALTER TABLE `PROFILE_BRANCH`
  ADD CONSTRAINT `fk_profile_branch_branch` FOREIGN KEY (`id_branch`) REFERENCES `BRANCH` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_profile_branch_profile` FOREIGN KEY (`id_profile`) REFERENCES `PROFILE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `PROFILE_GROUP`
--
ALTER TABLE `PROFILE_GROUP`
  ADD CONSTRAINT `fk_profile_group_member` FOREIGN KEY (`id_profile_member`) REFERENCES `PROFILE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_profile_group_owner` FOREIGN KEY (`id_profile_owner`) REFERENCES `PROFILE` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `REGION`
--
ALTER TABLE `REGION`
  ADD CONSTRAINT `fk_region_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

--
-- Filtros para la tabla `ROLE`
--
ALTER TABLE `ROLE`
  ADD CONSTRAINT `fk_role_branch` FOREIGN KEY (`id_branch`) REFERENCES `BRANCH` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_role_company` FOREIGN KEY (`id_company`) REFERENCES `COMPANY` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
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 */;
