-- 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 15:03:53
-- 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_audit`
--

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

--
-- Estructura de tabla para la tabla `AUDIT`
--

CREATE TABLE `AUDIT` (
  `id` bigint UNSIGNED NOT NULL,
  `ts` datetime NOT NULL,
  `request_token` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `job_token` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `id_company` bigint UNSIGNED DEFAULT NULL,
  `id_branch` bigint UNSIGNED DEFAULT NULL,
  `id_profile` bigint UNSIGNED DEFAULT NULL,
  `app` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `route` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `event_key` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `event_type` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `ip` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `has_error` tinyint(1) NOT NULL DEFAULT '0',
  `error_count` int UNSIGNED NOT NULL DEFAULT '0',
  `last_error_ts` datetime DEFAULT NULL,
  `last_error_code` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `last_error_message` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY RANGE (to_days(`ts`))
(
PARTITION p202602 VALUES LESS THAN (740041) ENGINE=InnoDB,
PARTITION p202603 VALUES LESS THAN (740072) ENGINE=InnoDB,
PARTITION p202604 VALUES LESS THAN (740102) ENGINE=InnoDB
);

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

--
-- Estructura de tabla para la tabla `AUDIT_SQL_LOG`
--

CREATE TABLE `AUDIT_SQL_LOG` (
  `id` bigint UNSIGNED NOT NULL,
  `id_audit` bigint UNSIGNED NOT NULL,
  `ts_audit` datetime NOT NULL,
  `id_sql_log` bigint UNSIGNED NOT NULL,
  `ts_sql_log` datetime NOT NULL,
  `pos` int UNSIGNED NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY RANGE (to_days(`ts_sql_log`))
(
PARTITION p202602 VALUES LESS THAN (740041) ENGINE=InnoDB,
PARTITION p202603 VALUES LESS THAN (740072) ENGINE=InnoDB,
PARTITION p202604 VALUES LESS THAN (740102) ENGINE=InnoDB
);

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

--
-- Estructura de tabla para la tabla `RETENTION`
--

CREATE TABLE `RETENTION` (
  `id` bigint UNSIGNED NOT NULL,
  `table_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `retention_days` int UNSIGNED NOT NULL,
  `is_enabled` tinyint(1) NOT NULL DEFAULT '1',
  `updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `id_user_updated` bigint UNSIGNED DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Estructura de tabla para la tabla `SQL_CATALOG`
--

CREATE TABLE `SQL_CATALOG` (
  `sql_hash` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `sql_template` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `first_seen` datetime NOT NULL,
  `last_seen` datetime NOT NULL,
  `seen_count` bigint UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Estructura de tabla para la tabla `SQL_LOG`
--

CREATE TABLE `SQL_LOG` (
  `id` bigint UNSIGNED NOT NULL,
  `ts` datetime NOT NULL,
  `request_token` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `job_token` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `id_company` bigint UNSIGNED DEFAULT NULL,
  `id_branch` bigint UNSIGNED DEFAULT NULL,
  `id_profile` bigint UNSIGNED DEFAULT NULL,
  `app` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
  `route` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `db_alias` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `db_role` enum('reader','writer') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sql_hash` char(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `params_json` json DEFAULT NULL,
  `duration_ms` int UNSIGNED DEFAULT NULL,
  `row_count` int UNSIGNED DEFAULT NULL,
  `error_code` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `error_message` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ip` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY RANGE (to_days(`ts`))
(
PARTITION p202602 VALUES LESS THAN (740041) ENGINE=InnoDB,
PARTITION p202603 VALUES LESS THAN (740072) ENGINE=InnoDB,
PARTITION p202604 VALUES LESS THAN (740102) ENGINE=InnoDB
);

--
-- Índices para tablas volcadas
--

--
-- Indices de la tabla `AUDIT`
--
ALTER TABLE `AUDIT`
  ADD PRIMARY KEY (`id`,`ts`),
  ADD KEY `idx_ts` (`ts`),
  ADD KEY `idx_request_token_ts` (`request_token`,`ts`),
  ADD KEY `idx_job_token_ts` (`job_token`,`ts`),
  ADD KEY `idx_branch_ts` (`id_branch`,`ts`),
  ADD KEY `idx_profile_ts` (`id_profile`,`ts`),
  ADD KEY `idx_app_ts` (`app`,`ts`),
  ADD KEY `idx_route_ts` (`route`,`ts`),
  ADD KEY `idx_event_key_ts` (`event_key`,`ts`),
  ADD KEY `idx_event_type_ts` (`event_type`,`ts`),
  ADD KEY `idx_audit_has_error_ts` (`has_error`,`ts`),
  ADD KEY `idx_company_ts` (`id_company`,`ts`),
  ADD KEY `idx_company_branch_event_ts` (`id_company`,`id_branch`,`event_key`,`ts`),
  ADD KEY `idx_company_profile_ts` (`id_company`,`id_profile`,`ts`);

--
-- Indices de la tabla `AUDIT_SQL_LOG`
--
ALTER TABLE `AUDIT_SQL_LOG`
  ADD PRIMARY KEY (`id`,`ts_sql_log`),
  ADD KEY `idx_event` (`id_audit`,`ts_audit`),
  ADD KEY `idx_sql` (`id_sql_log`,`ts_sql_log`),
  ADD KEY `idx_event_pos` (`id_audit`,`ts_audit`,`pos`),
  ADD KEY `idx_sql_pos` (`id_sql_log`,`ts_sql_log`,`pos`);

--
-- Indices de la tabla `RETENTION`
--
ALTER TABLE `RETENTION`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_table_name` (`table_name`),
  ADD KEY `idx_enabled` (`is_enabled`);

--
-- Indices de la tabla `SQL_CATALOG`
--
ALTER TABLE `SQL_CATALOG`
  ADD PRIMARY KEY (`sql_hash`),
  ADD KEY `idx_last_seen` (`last_seen`),
  ADD KEY `idx_seen_count` (`seen_count`);

--
-- Indices de la tabla `SQL_LOG`
--
ALTER TABLE `SQL_LOG`
  ADD PRIMARY KEY (`id`,`ts`),
  ADD KEY `idx_ts` (`ts`),
  ADD KEY `idx_request_token_ts` (`request_token`,`ts`),
  ADD KEY `idx_job_token_ts` (`job_token`,`ts`),
  ADD KEY `idx_branch_ts` (`id_branch`,`ts`),
  ADD KEY `idx_profile_ts` (`id_profile`,`ts`),
  ADD KEY `idx_app_ts` (`app`,`ts`),
  ADD KEY `idx_route_ts` (`route`,`ts`),
  ADD KEY `idx_sql_hash_ts` (`sql_hash`,`ts`),
  ADD KEY `idx_db_alias_role_ts` (`db_alias`,`db_role`,`ts`),
  ADD KEY `idx_duration_ts` (`duration_ms`,`ts`),
  ADD KEY `idx_error_code_ts` (`error_code`,`ts`),
  ADD KEY `idx_company_ts` (`id_company`,`ts`),
  ADD KEY `idx_company_duration_ts` (`id_company`,`duration_ms` DESC,`ts`);

--
-- AUTO_INCREMENT de las tablas volcadas
--

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

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

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

--
-- AUTO_INCREMENT de la tabla `SQL_LOG`
--
ALTER TABLE `SQL_LOG`
  MODIFY `id` bigint UNSIGNED 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 */;
