CREATE DATABASE IF NOT EXISTS `otoup` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `otoup`;
CREATE TABLE `users` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`name` varchar(255) NOT NULL,`email` varchar(255) NOT NULL,`email_verified_at` timestamp NULL,`password` varchar(255) NOT NULL,`is_admin` tinyint(1) NOT NULL DEFAULT 0,`remember_token` varchar(100) DEFAULT NULL,`created_at` timestamp NULL,`updated_at` timestamp NULL,PRIMARY KEY (`id`),UNIQUE KEY `users_email_unique` (`email`));
CREATE TABLE `password_reset_tokens` (`email` varchar(255) NOT NULL,`token` varchar(255) NOT NULL,`created_at` timestamp NULL,PRIMARY KEY (`email`));
CREATE TABLE `sessions` (`id` varchar(255) NOT NULL,`user_id` bigint unsigned DEFAULT NULL,`ip_address` varchar(45) DEFAULT NULL,`user_agent` text,`payload` longtext NOT NULL,`last_activity` int NOT NULL,PRIMARY KEY (`id`),KEY `sessions_user_id_index` (`user_id`),KEY `sessions_last_activity_index` (`last_activity`));
CREATE TABLE `cache` (`key` varchar(255) NOT NULL,`value` mediumtext NOT NULL,`expiration` int NOT NULL,PRIMARY KEY (`key`)); CREATE TABLE `cache_locks` (`key` varchar(255) NOT NULL,`owner` varchar(255) NOT NULL,`expiration` int NOT NULL,PRIMARY KEY (`key`));
CREATE TABLE `categories` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`name` varchar(100) NOT NULL,`slug` varchar(120) NOT NULL,`description` varchar(500) DEFAULT NULL,`status` enum('draft','published') NOT NULL DEFAULT 'published',`created_at` timestamp NULL,`updated_at` timestamp NULL,PRIMARY KEY (`id`),UNIQUE KEY `categories_slug_unique` (`slug`));
CREATE TABLE `tools` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`name` varchar(120) NOT NULL,`slug` varchar(140) NOT NULL,`category_id` bigint unsigned DEFAULT NULL,`version` varchar(30) NOT NULL DEFAULT '1.0.0',`status` enum('draft','published','disabled') NOT NULL DEFAULT 'draft',`tool_type` enum('html','laravel','api') NOT NULL DEFAULT 'html',`content_path` varchar(255) DEFAULT NULL,`seo_title` varchar(255) DEFAULT NULL,`meta_description` varchar(500) DEFAULT NULL,`canonical_url` varchar(500) DEFAULT NULL,`og_image` varchar(500) DEFAULT NULL,`ads_enabled` tinyint(1) NOT NULL DEFAULT 1,`analytics_enabled` tinyint(1) NOT NULL DEFAULT 1,`faq_json` json DEFAULT NULL,`created_at` timestamp NULL,`updated_at` timestamp NULL,PRIMARY KEY (`id`),UNIQUE KEY `tools_slug_unique` (`slug`),KEY `tools_category_id_foreign` (`category_id`),CONSTRAINT `tools_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL);
CREATE TABLE `advertisements` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`name` varchar(120) NOT NULL,`type` enum('adsense','html','image','text') NOT NULL DEFAULT 'adsense',`placement` enum('top','before_tool','after_tool','sidebar','footer') NOT NULL DEFAULT 'after_tool',`content` longtext,`status` tinyint(1) NOT NULL DEFAULT 1,`priority` int unsigned NOT NULL DEFAULT 0,`created_at` timestamp NULL,`updated_at` timestamp NULL,PRIMARY KEY (`id`));
CREATE TABLE `site_settings` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`key` varchar(255) NOT NULL,`value` longtext,`type` varchar(30) NOT NULL DEFAULT 'string',`created_at` timestamp NULL,`updated_at` timestamp NULL,PRIMARY KEY (`id`),UNIQUE KEY `site_settings_key_unique` (`key`));
CREATE TABLE `activity_logs` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`user_id` bigint unsigned DEFAULT NULL,`action` varchar(100) NOT NULL,`subject_type` varchar(255) DEFAULT NULL,`subject_id` bigint unsigned DEFAULT NULL,`ip_address` varchar(45) DEFAULT NULL,`user_agent` text,`meta` json DEFAULT NULL,`created_at` timestamp NULL,`updated_at` timestamp NULL,PRIMARY KEY (`id`),KEY `activity_logs_user_id_foreign` (`user_id`),CONSTRAINT `activity_logs_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL);
CREATE TABLE `jobs` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`queue` varchar(255) NOT NULL,`payload` longtext NOT NULL,`attempts` tinyint unsigned NOT NULL,`reserved_at` int unsigned DEFAULT NULL,`available_at` int unsigned NOT NULL,`created_at` int unsigned NOT NULL,PRIMARY KEY (`id`),KEY `jobs_queue_index` (`queue`));
CREATE TABLE `job_batches` (`id` varchar(255) NOT NULL,`name` varchar(255) NOT NULL,`total_jobs` int NOT NULL,`pending_jobs` int NOT NULL,`failed_jobs` int NOT NULL,`failed_job_ids` longtext NOT NULL,`options` mediumtext,`cancelled_at` int DEFAULT NULL,`created_at` int NOT NULL,`finished_at` int DEFAULT NULL,PRIMARY KEY (`id`));
CREATE TABLE `failed_jobs` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`uuid` varchar(255) NOT NULL,`connection` text NOT NULL,`queue` text NOT NULL,`payload` longtext NOT NULL,`exception` longtext NOT NULL,`failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`));
