-- phpMyAdmin SQL Dump
-- version 4.9.11
-- https://www.phpmyadmin.net/
--
-- Хост: 127.0.0.1
-- Время создания: Апр 22 2026 г., 14:16
-- Версия сервера: 8.0.13
-- Версия PHP: 5.6.40

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
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 */;

--
-- База данных: `demonx_newvmere`
--

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

--
-- Структура таблицы `album_photos`
--

CREATE TABLE `album_photos` (
  `id` int(10) UNSIGNED NOT NULL,
  `album_id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `file_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `mime` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `size_bytes` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `width` int(10) UNSIGNED DEFAULT NULL,
  `height` int(10) UNSIGNED DEFAULT NULL,
  `caption` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `sort_order` int(10) UNSIGNED 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;

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

--
-- Структура таблицы `app_settings`
--

CREATE TABLE `app_settings` (
  `key_name` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
  `value_text` text COLLATE utf8mb4_unicode_ci,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `audio_playlists`
--

CREATE TABLE `audio_playlists` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `audio_playlist_tracks`
--

CREATE TABLE `audio_playlist_tracks` (
  `playlist_id` int(10) UNSIGNED NOT NULL,
  `track_id` int(10) UNSIGNED NOT NULL,
  `position` int(10) UNSIGNED NOT NULL DEFAULT '1',
  `added_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `audio_tracks`
--

CREATE TABLE `audio_tracks` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `artist` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `album` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `duration_sec` int(10) UNSIGNED DEFAULT NULL,
  `rel_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stored_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mime` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `size_bytes` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `board_ads`
--

CREATE TABLE `board_ads` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `category_id` int(10) UNSIGNED DEFAULT NULL,
  `title` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `price_amount` decimal(12,2) NOT NULL DEFAULT '0.00',
  `currency_code` char(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UAH',
  `contact_name` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `contact_phone` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `contact_email` varchar(190) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `contact_telegram` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_code` char(2) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UA',
  `region_id` int(10) UNSIGNED DEFAULT NULL,
  `region_name` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city_name` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
  `main_image_path` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `main_image_original_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('draft','pending','approved','rejected','archived','deleted') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'draft',
  `payment_status` enum('unpaid','paid') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unpaid',
  `publish_price` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `paid_at` datetime DEFAULT NULL,
  `published_at` datetime DEFAULT NULL,
  `approved_at` datetime DEFAULT NULL,
  `approved_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `rejected_at` datetime DEFAULT NULL,
  `rejected_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `moderation_note` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `total_views` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `unique_views` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `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;

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

--
-- Структура таблицы `board_ad_images`
--

CREATE TABLE `board_ad_images` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `ad_id` bigint(20) UNSIGNED NOT NULL,
  `rel_path` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `mime` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `size_bytes` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `width` int(10) UNSIGNED DEFAULT NULL,
  `height` int(10) UNSIGNED DEFAULT NULL,
  `sort_order` int(10) UNSIGNED NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `board_ad_moderation`
--

CREATE TABLE `board_ad_moderation` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `ad_id` bigint(20) UNSIGNED NOT NULL,
  `admin_user_id` int(10) UNSIGNED DEFAULT NULL,
  `action` enum('created','submitted','approved','rejected','archived','deleted','edited','restored') COLLATE utf8mb4_unicode_ci NOT NULL,
  `note` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `board_ad_viewers`
--

CREATE TABLE `board_ad_viewers` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `ad_id` bigint(20) UNSIGNED NOT NULL,
  `viewer_key` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `viewer_user_id` int(10) UNSIGNED DEFAULT NULL,
  `country_code` char(2) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city_name` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `first_viewed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `last_viewed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `board_categories`
--

CREATE TABLE `board_categories` (
  `id` int(10) UNSIGNED NOT NULL,
  `slug` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_uk` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_ru` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_en` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
  `sort` int(10) UNSIGNED NOT NULL DEFAULT '100',
  `is_active` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `board_regions`
--

CREATE TABLE `board_regions` (
  `id` int(10) UNSIGNED NOT NULL,
  `country_code` char(2) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UA',
  `region_code` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_uk` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_ru` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_en` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
  `sort` int(10) UNSIGNED NOT NULL DEFAULT '100',
  `is_active` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `comments`
--

CREATE TABLE `comments` (
  `id` int(10) UNSIGNED NOT NULL,
  `post_id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `parent_id` int(10) UNSIGNED DEFAULT NULL,
  `body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `comment_attachments`
--

CREATE TABLE `comment_attachments` (
  `id` int(10) UNSIGNED NOT NULL,
  `comment_id` int(10) UNSIGNED NOT NULL,
  `file_type` enum('image','audio','video','file') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mime` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `size_bytes` int(10) UNSIGNED NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `comment_reactions`
--

CREATE TABLE `comment_reactions` (
  `comment_id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `reaction` enum('like','dislike') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `friend_requests`
--

CREATE TABLE `friend_requests` (
  `id` int(10) UNSIGNED NOT NULL,
  `from_user_id` int(10) UNSIGNED NOT NULL,
  `to_user_id` int(10) UNSIGNED NOT NULL,
  `status` enum('pending','accepted','declined','canceled') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',
  `created_at` datetime NOT NULL,
  `responded_at` datetime DEFAULT NULL,
  `accepted_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `game_roulette_transactions`
--

CREATE TABLE `game_roulette_transactions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `delta_chips` int(11) NOT NULL,
  `chips_after` int(11) NOT NULL,
  `event_key` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `op_key` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `note` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `meta_json` longtext COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `game_roulette_wallets`
--

CREATE TABLE `game_roulette_wallets` (
  `user_id` int(10) UNSIGNED NOT NULL,
  `chips_balance` int(11) NOT NULL DEFAULT '0',
  `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;

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

--
-- Структура таблицы `groups`
--

CREATE TABLE `groups` (
  `id` int(10) UNSIGNED NOT NULL,
  `owner_user_id` int(10) UNSIGNED NOT NULL,
  `name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(160) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `topic` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `about` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `avatar_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cover_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `topic_id` int(10) UNSIGNED DEFAULT NULL,
  `is_closed` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `group_links`
--

CREATE TABLE `group_links` (
  `id` int(10) UNSIGNED NOT NULL,
  `group_id` int(10) UNSIGNED NOT NULL,
  `url` varchar(2048) NOT NULL,
  `label` varchar(80) NOT NULL DEFAULT '',
  `sort_order` int(10) UNSIGNED NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

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

--
-- Структура таблицы `group_members`
--

CREATE TABLE `group_members` (
  `group_id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `role` enum('owner','admin','member') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'member',
  `status` enum('active','pending','banned') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `pending_kind` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `group_topics`
--

CREATE TABLE `group_topics` (
  `id` int(10) UNSIGNED NOT NULL,
  `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_uk` varchar(140) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_en` varchar(140) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name_ru` varchar(140) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sort` int(10) UNSIGNED NOT NULL DEFAULT '100'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `link_previews`
--

CREATE TABLE `link_previews` (
  `url_hash` char(40) NOT NULL,
  `url` varchar(2048) NOT NULL,
  `title` varchar(512) NOT NULL DEFAULT '',
  `description` varchar(1024) NOT NULL DEFAULT '',
  `image` varchar(2048) NOT NULL DEFAULT '',
  `site_name` varchar(255) NOT NULL DEFAULT '',
  `fetched_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

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

--
-- Структура таблицы `message_attachments`
--

CREATE TABLE `message_attachments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `message_id` bigint(20) UNSIGNED NOT NULL,
  `rel_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stored_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mime` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `size_bytes` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `message_messages`
--

CREATE TABLE `message_messages` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `thread_id` int(10) UNSIGNED NOT NULL,
  `sender_id` int(10) UNSIGNED NOT NULL,
  `msg_type` enum('user','system') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'user',
  `body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `has_attachments` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `message_threads`
--

CREATE TABLE `message_threads` (
  `id` int(10) UNSIGNED NOT NULL,
  `user1_id` int(10) UNSIGNED NOT NULL,
  `user2_id` int(10) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL,
  `last_message_at` datetime DEFAULT NULL,
  `last_message_id` bigint(20) UNSIGNED DEFAULT NULL,
  `is_closed` tinyint(1) NOT NULL DEFAULT '0',
  `closed_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `closed_at` datetime DEFAULT NULL,
  `user1_last_read_at` datetime DEFAULT NULL,
  `user2_last_read_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `myfiles`
--

CREATE TABLE `myfiles` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `folder_id` int(10) UNSIGNED DEFAULT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stored_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rel_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mime` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `size_bytes` bigint(20) UNSIGNED NOT NULL,
  `is_public` tinyint(1) NOT NULL DEFAULT '0',
  `share_token` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `myfile_folders`
--

CREATE TABLE `myfile_folders` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `parent_id` int(10) UNSIGNED DEFAULT NULL,
  `name` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `myvideos`
--

CREATE TABLE `myvideos` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `title` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stored_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rel_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mime` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `size_bytes` bigint(20) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `notifications`
--

CREATE TABLE `notifications` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `actor_user_id` int(10) UNSIGNED DEFAULT NULL,
  `type` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `entity_type` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `entity_id` bigint(20) UNSIGNED DEFAULT NULL,
  `post_id` bigint(20) UNSIGNED DEFAULT NULL,
  `group_id` int(10) UNSIGNED DEFAULT NULL,
  `message` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `is_read` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL,
  `read_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `notification_email_log`
--

CREATE TABLE `notification_email_log` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `actor_user_id` int(10) UNSIGNED DEFAULT NULL,
  `type` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `entity_type` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `entity_id` bigint(20) UNSIGNED DEFAULT NULL,
  `status` enum('sent','skipped','error') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'sent',
  `reason` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `subject` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dedupe_key` varchar(190) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `error_text` text COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `password_reset_tokens`
--

CREATE TABLE `password_reset_tokens` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `selector` char(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token_hash` char(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `expires_at` datetime NOT NULL,
  `used_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `request_ip` varbinary(16) DEFAULT NULL,
  `request_ua` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `photo_albums`
--

CREATE TABLE `photo_albums` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `title` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `privacy` enum('public','friends','private') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'public',
  `cover_photo_id` int(10) UNSIGNED 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;

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

--
-- Структура таблицы `posts`
--

CREATE TABLE `posts` (
  `id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `group_id` int(10) UNSIGNED DEFAULT NULL,
  `repost_post_id` int(10) UNSIGNED DEFAULT NULL,
  `body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `post_attachments`
--

CREATE TABLE `post_attachments` (
  `id` int(10) UNSIGNED NOT NULL,
  `post_id` int(10) UNSIGNED NOT NULL,
  `file_type` enum('image','audio','video','file') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mime` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `size_bytes` int(10) UNSIGNED NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `post_polls`
--

CREATE TABLE `post_polls` (
  `id` int(10) UNSIGNED NOT NULL,
  `post_id` int(10) UNSIGNED NOT NULL,
  `question` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `post_poll_options`
--

CREATE TABLE `post_poll_options` (
  `id` int(10) UNSIGNED NOT NULL,
  `poll_id` int(10) UNSIGNED NOT NULL,
  `option_text` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sort_order` tinyint(3) UNSIGNED NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `post_poll_votes`
--

CREATE TABLE `post_poll_votes` (
  `poll_id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `option_id` int(10) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `post_reactions`
--

CREATE TABLE `post_reactions` (
  `post_id` int(10) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `reaction` enum('like','dislike') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `reclama_campaigns`
--

CREATE TABLE `reclama_campaigns` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `campaign_type` enum('post','banner') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'post',
  `source_post_id` int(10) UNSIGNED DEFAULT NULL,
  `title` varchar(160) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `target_url` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('draft','pending','approved','rejected','active','paused','finished','canceled') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'draft',
  `moderation_status` enum('none','pending','approved','rejected') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',
  `payment_status` enum('unpaid','reserved','paid','refunded','partial_refund') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unpaid',
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `days_count` smallint(5) UNSIGNED NOT NULL DEFAULT '0',
  `price_per_day` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `total_price` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `desktop_banner_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mobile_banner_path` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `desktop_banner_original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mobile_banner_original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reject_reason` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `approved_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `rejected_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `moderated_at` datetime DEFAULT NULL,
  `paid_at` datetime DEFAULT NULL,
  `launched_at` datetime DEFAULT NULL,
  `paused_at` datetime DEFAULT NULL,
  `finished_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;

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

--
-- Структура таблицы `reclama_campaign_clicks`
--

CREATE TABLE `reclama_campaign_clicks` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `campaign_id` bigint(20) UNSIGNED NOT NULL,
  `viewer_user_id` int(10) UNSIGNED DEFAULT NULL,
  `viewer_session_key` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `device_type` enum('desktop','mobile','tablet','unknown') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unknown',
  `placement` enum('feed','group_feed','profile_feed','other') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'feed',
  `clicked_url` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `clicked_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `reclama_campaign_daily_stats`
--

CREATE TABLE `reclama_campaign_daily_stats` (
  `campaign_id` bigint(20) UNSIGNED NOT NULL,
  `stat_date` date NOT NULL,
  `impressions_count` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `clicks_count` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `unique_viewers_count` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `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;

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

--
-- Структура таблицы `reclama_campaign_impressions`
--

CREATE TABLE `reclama_campaign_impressions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `campaign_id` bigint(20) UNSIGNED NOT NULL,
  `viewer_user_id` int(10) UNSIGNED DEFAULT NULL,
  `viewer_session_key` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `device_type` enum('desktop','mobile','tablet','unknown') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unknown',
  `placement` enum('feed','group_feed','profile_feed','other') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'feed',
  `shown_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `reclama_campaign_moderation`
--

CREATE TABLE `reclama_campaign_moderation` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `campaign_id` bigint(20) UNSIGNED NOT NULL,
  `admin_user_id` int(10) UNSIGNED DEFAULT NULL,
  `action` enum('created','submitted','approved','rejected','paused','resumed','finished','canceled','edited') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `note` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `reclama_campaign_targeting`
--

CREATE TABLE `reclama_campaign_targeting` (
  `campaign_id` bigint(20) UNSIGNED NOT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_codes_json` json DEFAULT NULL,
  `exclude_countries_json` json DEFAULT NULL,
  `city` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `gender` enum('any','m','f') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'any',
  `age_from` tinyint(3) UNSIGNED DEFAULT NULL,
  `age_to` tinyint(3) UNSIGNED DEFAULT NULL,
  `lang_code` enum('any','uk','ru','en') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'any',
  `device_type` enum('all','desktop','mobile') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'all',
  `auth_scope` enum('all','guests','users') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'all',
  `segment_codes_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;

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

--
-- Структура таблицы `security_antispam_flags`
--

CREATE TABLE `security_antispam_flags` (
  `user_id` int(10) UNSIGNED NOT NULL,
  `status` enum('suspect','bot') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'bot',
  `is_manual` tinyint(1) NOT NULL DEFAULT '0',
  `reason_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `reason_text` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `details_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `hit_count` int(10) UNSIGNED NOT NULL DEFAULT '1',
  `first_detected_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `last_detected_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updated_by` int(10) UNSIGNED DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `security_ip_rules`
--

CREATE TABLE `security_ip_rules` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `ip_or_cidr` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `block_login` tinyint(1) NOT NULL DEFAULT '1',
  `block_register` tinyint(1) NOT NULL DEFAULT '1',
  `reason` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by` int(10) UNSIGNED DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `security_login_log`
--

CREATE TABLE `security_login_log` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED DEFAULT NULL,
  `email` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ua` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ok` tinyint(1) NOT NULL DEFAULT '0',
  `reason` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `security_rate_limits`
--

CREATE TABLE `security_rate_limits` (
  `id` int(10) UNSIGNED NOT NULL,
  `scope_type` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `scope_key` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
  `attempts` int(10) UNSIGNED NOT NULL DEFAULT '0',
  `first_at` datetime DEFAULT NULL,
  `last_at` datetime DEFAULT NULL,
  `locked_until` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `seo_change_log`
--

CREATE TABLE `seo_change_log` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `admin_user_id` int(10) UNSIGNED DEFAULT NULL,
  `entity_type` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
  `entity_id` int(10) UNSIGNED DEFAULT NULL,
  `action_key` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `old_value_json` longtext COLLATE utf8mb4_unicode_ci,
  `new_value_json` longtext COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `seo_pages`
--

CREATE TABLE `seo_pages` (
  `id` int(10) UNSIGNED NOT NULL,
  `page_path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `page_title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `meta_description` text COLLATE utf8mb4_unicode_ci,
  `canonical_url` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `og_title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `og_description` text COLLATE utf8mb4_unicode_ci,
  `og_image` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `robots_directive` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'index,follow',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `updated_by_user_id` int(10) UNSIGNED 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;

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

--
-- Структура таблицы `seo_redirects`
--

CREATE TABLE `seo_redirects` (
  `id` int(10) UNSIGNED NOT NULL,
  `old_path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `target_url` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL,
  `http_code` smallint(5) UNSIGNED NOT NULL DEFAULT '301',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `hit_count` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `last_hit_at` datetime DEFAULT NULL,
  `note` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `updated_by_user_id` int(10) UNSIGNED 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;

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

--
-- Структура таблицы `site_pages`
--

CREATE TABLE `site_pages` (
  `id` int(10) UNSIGNED NOT NULL,
  `slug` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `title_uk` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `title_ru` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `title_en` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `body_uk` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `body_ru` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `body_en` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `show_in_footer` tinyint(1) NOT NULL DEFAULT '1',
  `sort_order` int(10) UNSIGNED NOT NULL DEFAULT '100',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_by_user_id` int(10) UNSIGNED DEFAULT NULL,
  `updated_by_user_id` int(10) UNSIGNED 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;

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

--
-- Структура таблицы `traffic_daily_seen`
--

CREATE TABLE `traffic_daily_seen` (
  `day_date` date NOT NULL,
  `is_bot` tinyint(1) NOT NULL DEFAULT '0',
  `entity_key` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `first_seen_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `last_uri` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `traffic_geo_cache`
--

CREATE TABLE `traffic_geo_cache` (
  `ip_hash` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `region_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `source` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `traffic_hits`
--

CREATE TABLE `traffic_hits` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL,
  `ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` int(10) UNSIGNED DEFAULT NULL,
  `session_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `visitor_id` char(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `uri` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `referrer` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ua` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `region_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `is_bot` tinyint(1) NOT NULL DEFAULT '0',
  `bot_name` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `traffic_ip_geo`
--

CREATE TABLE `traffic_ip_geo` (
  `ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `region_name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `region_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lat` decimal(10,6) DEFAULT NULL,
  `lon` decimal(10,6) DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `users`
--

CREATE TABLE `users` (
  `id` int(10) UNSIGNED NOT NULL,
  `email` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `username` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `full_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `gender` enum('f','m') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `birthdate` date DEFAULT NULL,
  `lang` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'uk',
  `pass_hash` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `role` enum('user','admin') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'user',
  `is_active` tinyint(1) NOT NULL DEFAULT '0',
  `activation_token_hash` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `activation_sent_at` datetime DEFAULT NULL,
  `activated_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `first_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `last_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` varchar(140) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `about` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `country` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country_code` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `education` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `workplace` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `birth_date` date DEFAULT NULL,
  `sex` enum('m','f','o') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `website` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `work` varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `languages` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `avatar_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cover_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `last_seen_at` datetime DEFAULT NULL,
  `is_private` tinyint(1) NOT NULL DEFAULT '0',
  `vm_coins_balance` bigint(20) NOT NULL DEFAULT '0',
  `vm_coins_earned_total` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `vm_coins_spent_total` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `vm_coins_updated_at` datetime DEFAULT NULL,
  `vm_ref_code` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `vm_referred_by_user_id` int(11) DEFAULT NULL,
  `vm_ref_applied_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `user_account_restrictions`
--

CREATE TABLE `user_account_restrictions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `posts_blocked_until` datetime DEFAULT NULL,
  `comments_blocked_until` datetime DEFAULT NULL,
  `messages_blocked_until` datetime DEFAULT NULL,
  `is_banned_forever` tinyint(1) NOT NULL DEFAULT '0',
  `reason` text COLLATE utf8mb4_unicode_ci,
  `set_by_user_id` bigint(20) UNSIGNED 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;

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

--
-- Структура таблицы `user_follows`
--

CREATE TABLE `user_follows` (
  `follower_user_id` int(10) UNSIGNED NOT NULL,
  `followee_user_id` int(10) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Структура таблицы `user_notification_settings`
--

CREATE TABLE `user_notification_settings` (
  `user_id` int(10) UNSIGNED NOT NULL,
  `email_enabled` tinyint(1) NOT NULL DEFAULT '1',
  `email_private_message` tinyint(1) NOT NULL DEFAULT '1',
  `email_friend_request` tinyint(1) NOT NULL DEFAULT '1',
  `email_group_invite` tinyint(1) NOT NULL DEFAULT '1',
  `email_group_join_request` tinyint(1) NOT NULL DEFAULT '1',
  `email_comment_reply` tinyint(1) NOT NULL DEFAULT '1',
  `email_post_comment` 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;

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

--
-- Структура таблицы `vm_coin_transactions`
--

CREATE TABLE `vm_coin_transactions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `delta_amount` bigint(20) NOT NULL,
  `balance_after` bigint(20) NOT NULL,
  `event_key` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `entity_type` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `entity_id` bigint(20) UNSIGNED DEFAULT NULL,
  `related_user_id` int(10) UNSIGNED DEFAULT NULL,
  `op_key` varchar(190) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `note` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `meta_json` mediumtext COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Индексы сохранённых таблиц
--

--
-- Индексы таблицы `album_photos`
--
ALTER TABLE `album_photos`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_album_photos_album` (`album_id`),
  ADD KEY `idx_album_photos_user` (`user_id`),
  ADD KEY `idx_album_photos_sort` (`album_id`,`sort_order`,`id`),
  ADD KEY `idx_album_photos_created` (`created_at`);

--
-- Индексы таблицы `app_settings`
--
ALTER TABLE `app_settings`
  ADD PRIMARY KEY (`key_name`);

--
-- Индексы таблицы `audio_playlists`
--
ALTER TABLE `audio_playlists`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_audio_playlists_user` (`user_id`);

--
-- Индексы таблицы `audio_playlist_tracks`
--
ALTER TABLE `audio_playlist_tracks`
  ADD PRIMARY KEY (`playlist_id`,`track_id`),
  ADD KEY `idx_audio_pl_tracks_track` (`track_id`),
  ADD KEY `idx_audio_pl_tracks_pos` (`playlist_id`,`position`);

--
-- Индексы таблицы `audio_tracks`
--
ALTER TABLE `audio_tracks`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_audio_tracks_user` (`user_id`),
  ADD KEY `idx_audio_tracks_created` (`created_at`);

--
-- Индексы таблицы `board_ads`
--
ALTER TABLE `board_ads`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_board_ads_user` (`user_id`),
  ADD KEY `idx_board_ads_status` (`status`),
  ADD KEY `idx_board_ads_country_status` (`country_code`,`status`),
  ADD KEY `idx_board_ads_category_status` (`category_id`,`status`),
  ADD KEY `idx_board_ads_region_status` (`region_id`,`status`),
  ADD KEY `idx_board_ads_published` (`published_at`);

--
-- Индексы таблицы `board_ad_images`
--
ALTER TABLE `board_ad_images`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_board_ad_images_ad` (`ad_id`,`sort_order`);

--
-- Индексы таблицы `board_ad_moderation`
--
ALTER TABLE `board_ad_moderation`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_board_ad_moderation_ad` (`ad_id`,`created_at`),
  ADD KEY `idx_board_ad_moderation_admin` (`admin_user_id`);

--
-- Индексы таблицы `board_ad_viewers`
--
ALTER TABLE `board_ad_viewers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_board_ad_viewers_ad_viewer` (`ad_id`,`viewer_key`),
  ADD KEY `idx_board_ad_viewers_user` (`viewer_user_id`),
  ADD KEY `idx_board_ad_viewers_last_viewed` (`last_viewed_at`);

--
-- Индексы таблицы `board_categories`
--
ALTER TABLE `board_categories`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_board_categories_slug` (`slug`);

--
-- Индексы таблицы `board_regions`
--
ALTER TABLE `board_regions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_board_regions_ccode_rcode` (`country_code`,`region_code`),
  ADD KEY `idx_board_regions_country_sort` (`country_code`,`sort`);

--
-- Индексы таблицы `comments`
--
ALTER TABLE `comments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_c_post` (`post_id`),
  ADD KEY `idx_c_parent` (`parent_id`),
  ADD KEY `idx_c_user` (`user_id`);

--
-- Индексы таблицы `comment_attachments`
--
ALTER TABLE `comment_attachments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_ca_comment` (`comment_id`);

--
-- Индексы таблицы `comment_reactions`
--
ALTER TABLE `comment_reactions`
  ADD PRIMARY KEY (`comment_id`,`user_id`),
  ADD UNIQUE KEY `ux_comment_user` (`comment_id`,`user_id`),
  ADD KEY `idx_cr_comment` (`comment_id`),
  ADD KEY `idx_cr_user` (`user_id`),
  ADD KEY `ix_comment` (`comment_id`);

--
-- Индексы таблицы `friend_requests`
--
ALTER TABLE `friend_requests`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_from_to` (`from_user_id`,`to_user_id`),
  ADD KEY `idx_to_status` (`to_user_id`,`status`),
  ADD KEY `idx_from_status` (`from_user_id`,`status`),
  ADD KEY `idx_status` (`status`);

--
-- Индексы таблицы `game_roulette_transactions`
--
ALTER TABLE `game_roulette_transactions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_game_roulette_transactions_op_key` (`op_key`),
  ADD KEY `idx_game_roulette_transactions_user_id_id` (`user_id`,`id`),
  ADD KEY `idx_game_roulette_transactions_event_key` (`event_key`);

--
-- Индексы таблицы `game_roulette_wallets`
--
ALTER TABLE `game_roulette_wallets`
  ADD PRIMARY KEY (`user_id`),
  ADD KEY `idx_game_roulette_wallets_balance` (`chips_balance`);

--
-- Индексы таблицы `groups`
--
ALTER TABLE `groups`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_groups_slug` (`slug`),
  ADD KEY `idx_groups_owner` (`owner_user_id`),
  ADD KEY `idx_g_topic` (`topic_id`),
  ADD KEY `idx_groups_closed` (`is_closed`);

--
-- Индексы таблицы `group_links`
--
ALTER TABLE `group_links`
  ADD PRIMARY KEY (`id`),
  ADD KEY `group_id` (`group_id`);

--
-- Индексы таблицы `group_members`
--
ALTER TABLE `group_members`
  ADD PRIMARY KEY (`group_id`,`user_id`),
  ADD KEY `idx_gm_user` (`user_id`),
  ADD KEY `idx_gm_group` (`group_id`),
  ADD KEY `idx_group_members_group_status_pending_kind` (`group_id`,`status`,`pending_kind`),
  ADD KEY `idx_group_members_user_status_pending_kind` (`user_id`,`status`,`pending_kind`);

--
-- Индексы таблицы `group_topics`
--
ALTER TABLE `group_topics`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_gt_code` (`code`),
  ADD KEY `idx_gt_sort` (`sort`);

--
-- Индексы таблицы `link_previews`
--
ALTER TABLE `link_previews`
  ADD PRIMARY KEY (`url_hash`),
  ADD KEY `url` (`url`(255)),
  ADD KEY `fetched_at` (`fetched_at`);

--
-- Индексы таблицы `message_attachments`
--
ALTER TABLE `message_attachments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_message_id` (`message_id`);

--
-- Индексы таблицы `message_messages`
--
ALTER TABLE `message_messages`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_thread_id` (`thread_id`,`id`),
  ADD KEY `idx_sender_id` (`sender_id`);

--
-- Индексы таблицы `message_threads`
--
ALTER TABLE `message_threads`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_pair` (`user1_id`,`user2_id`),
  ADD KEY `idx_user1` (`user1_id`),
  ADD KEY `idx_user2` (`user2_id`),
  ADD KEY `idx_last_message_at` (`last_message_at`);

--
-- Индексы таблицы `myfiles`
--
ALTER TABLE `myfiles`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_myfiles_token` (`share_token`),
  ADD KEY `idx_myfiles_user` (`user_id`),
  ADD KEY `idx_myfiles_folder` (`folder_id`);

--
-- Индексы таблицы `myfile_folders`
--
ALTER TABLE `myfile_folders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_mff_user` (`user_id`),
  ADD KEY `idx_mff_parent` (`parent_id`);

--
-- Индексы таблицы `myvideos`
--
ALTER TABLE `myvideos`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_myvideos_user` (`user_id`),
  ADD KEY `idx_myvideos_created` (`created_at`);

--
-- Индексы таблицы `notifications`
--
ALTER TABLE `notifications`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_read_created` (`user_id`,`is_read`,`created_at`),
  ADD KEY `idx_type_entity` (`type`,`entity_type`,`entity_id`),
  ADD KEY `idx_actor_user` (`actor_user_id`),
  ADD KEY `idx_post_id` (`post_id`),
  ADD KEY `idx_group_id` (`group_id`);

--
-- Индексы таблицы `notification_email_log`
--
ALTER TABLE `notification_email_log`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_dedupe_key` (`dedupe_key`),
  ADD KEY `idx_user_type_created` (`user_id`,`type`,`created_at`),
  ADD KEY `idx_actor_type_created` (`actor_user_id`,`type`,`created_at`);

--
-- Индексы таблицы `password_reset_tokens`
--
ALTER TABLE `password_reset_tokens`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_selector` (`selector`),
  ADD KEY `idx_user_id` (`user_id`),
  ADD KEY `idx_expires_at` (`expires_at`),
  ADD KEY `idx_used_at` (`used_at`);

--
-- Индексы таблицы `photo_albums`
--
ALTER TABLE `photo_albums`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_photo_albums_user` (`user_id`),
  ADD KEY `idx_photo_albums_privacy` (`privacy`),
  ADD KEY `idx_photo_albums_created` (`created_at`),
  ADD KEY `idx_photo_albums_cover` (`cover_photo_id`);

--
-- Индексы таблицы `posts`
--
ALTER TABLE `posts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_posts_user` (`user_id`),
  ADD KEY `idx_posts_repost` (`repost_post_id`),
  ADD KEY `idx_posts_group` (`group_id`);

--
-- Индексы таблицы `post_attachments`
--
ALTER TABLE `post_attachments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_pa_post` (`post_id`);

--
-- Индексы таблицы `post_polls`
--
ALTER TABLE `post_polls`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_pp_post` (`post_id`);

--
-- Индексы таблицы `post_poll_options`
--
ALTER TABLE `post_poll_options`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_ppo_poll` (`poll_id`);

--
-- Индексы таблицы `post_poll_votes`
--
ALTER TABLE `post_poll_votes`
  ADD PRIMARY KEY (`poll_id`,`user_id`),
  ADD KEY `idx_ppv_poll` (`poll_id`),
  ADD KEY `idx_ppv_option` (`option_id`),
  ADD KEY `fk_ppv_user` (`user_id`);

--
-- Индексы таблицы `post_reactions`
--
ALTER TABLE `post_reactions`
  ADD PRIMARY KEY (`post_id`,`user_id`),
  ADD UNIQUE KEY `ux_post_user` (`post_id`,`user_id`),
  ADD KEY `idx_pr_post` (`post_id`),
  ADD KEY `idx_pr_user` (`user_id`),
  ADD KEY `ix_post` (`post_id`);

--
-- Индексы таблицы `reclama_campaigns`
--
ALTER TABLE `reclama_campaigns`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_reclama_campaigns_user` (`user_id`),
  ADD KEY `idx_reclama_campaigns_post` (`source_post_id`),
  ADD KEY `idx_reclama_campaigns_status` (`status`),
  ADD KEY `idx_reclama_campaigns_period` (`start_date`,`end_date`),
  ADD KEY `idx_reclama_campaigns_mod_pay` (`moderation_status`,`payment_status`,`status`),
  ADD KEY `fk_reclama_campaigns_approved_by` (`approved_by_user_id`),
  ADD KEY `fk_reclama_campaigns_rejected_by` (`rejected_by_user_id`);

--
-- Индексы таблицы `reclama_campaign_clicks`
--
ALTER TABLE `reclama_campaign_clicks`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_reclama_click_campaign_time` (`campaign_id`,`clicked_at`),
  ADD KEY `idx_reclama_click_user_time` (`viewer_user_id`,`clicked_at`),
  ADD KEY `idx_reclama_click_session_time` (`viewer_session_key`,`clicked_at`);

--
-- Индексы таблицы `reclama_campaign_daily_stats`
--
ALTER TABLE `reclama_campaign_daily_stats`
  ADD PRIMARY KEY (`campaign_id`,`stat_date`),
  ADD KEY `idx_reclama_daily_date` (`stat_date`);

--
-- Индексы таблицы `reclama_campaign_impressions`
--
ALTER TABLE `reclama_campaign_impressions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_reclama_imp_campaign_time` (`campaign_id`,`shown_at`),
  ADD KEY `idx_reclama_imp_user_time` (`viewer_user_id`,`shown_at`),
  ADD KEY `idx_reclama_imp_session_time` (`viewer_session_key`,`shown_at`);

--
-- Индексы таблицы `reclama_campaign_moderation`
--
ALTER TABLE `reclama_campaign_moderation`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_reclama_mod_campaign` (`campaign_id`,`created_at`),
  ADD KEY `idx_reclama_mod_admin` (`admin_user_id`);

--
-- Индексы таблицы `reclama_campaign_targeting`
--
ALTER TABLE `reclama_campaign_targeting`
  ADD PRIMARY KEY (`campaign_id`),
  ADD KEY `idx_reclama_target_country` (`country_code`),
  ADD KEY `idx_reclama_target_city` (`city`),
  ADD KEY `idx_reclama_target_lang` (`lang_code`),
  ADD KEY `idx_reclama_target_device` (`device_type`);

--
-- Индексы таблицы `security_antispam_flags`
--
ALTER TABLE `security_antispam_flags`
  ADD PRIMARY KEY (`user_id`),
  ADD KEY `idx_saf_status` (`status`),
  ADD KEY `idx_saf_last_detected` (`last_detected_at`),
  ADD KEY `idx_saf_updated_by` (`updated_by`);

--
-- Индексы таблицы `security_ip_rules`
--
ALTER TABLE `security_ip_rules`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_ip_or_cidr` (`ip_or_cidr`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_created_by` (`created_by`);

--
-- Индексы таблицы `security_login_log`
--
ALTER TABLE `security_login_log`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_ok_created_at` (`ok`,`created_at`),
  ADD KEY `idx_ip_created_at` (`ip`,`created_at`),
  ADD KEY `idx_user_created_at` (`user_id`,`created_at`);

--
-- Индексы таблицы `security_rate_limits`
--
ALTER TABLE `security_rate_limits`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_scope` (`scope_type`,`scope_key`),
  ADD KEY `idx_locked` (`locked_until`),
  ADD KEY `idx_last` (`last_at`);

--
-- Индексы таблицы `seo_change_log`
--
ALTER TABLE `seo_change_log`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_entity` (`entity_type`,`entity_id`),
  ADD KEY `idx_admin` (`admin_user_id`),
  ADD KEY `idx_created_at` (`created_at`);

--
-- Индексы таблицы `seo_pages`
--
ALTER TABLE `seo_pages`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_page_path` (`page_path`),
  ADD KEY `idx_is_active` (`is_active`);

--
-- Индексы таблицы `seo_redirects`
--
ALTER TABLE `seo_redirects`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_old_path` (`old_path`),
  ADD KEY `idx_is_active` (`is_active`),
  ADD KEY `idx_http_code` (`http_code`);

--
-- Индексы таблицы `site_pages`
--
ALTER TABLE `site_pages`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_site_pages_slug` (`slug`),
  ADD KEY `idx_site_pages_footer` (`show_in_footer`,`is_active`,`sort_order`);

--
-- Индексы таблицы `traffic_daily_seen`
--
ALTER TABLE `traffic_daily_seen`
  ADD PRIMARY KEY (`day_date`,`is_bot`,`entity_key`),
  ADD KEY `idx_first_seen` (`first_seen_at`);

--
-- Индексы таблицы `traffic_geo_cache`
--
ALTER TABLE `traffic_geo_cache`
  ADD PRIMARY KEY (`ip_hash`),
  ADD KEY `idx_cc` (`country_code`),
  ADD KEY `idx_region` (`region_name`),
  ADD KEY `idx_updated` (`updated_at`);

--
-- Индексы таблицы `traffic_hits`
--
ALTER TABLE `traffic_hits`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_th_created` (`created_at`),
  ADD KEY `idx_th_bot` (`is_bot`),
  ADD KEY `idx_th_user` (`user_id`),
  ADD KEY `idx_th_ip` (`ip`),
  ADD KEY `idx_th_country` (`country_code`),
  ADD KEY `idx_th_city` (`city`),
  ADD KEY `idx_th_visitor` (`visitor_id`);

--
-- Индексы таблицы `traffic_ip_geo`
--
ALTER TABLE `traffic_ip_geo`
  ADD PRIMARY KEY (`ip`),
  ADD KEY `idx_country` (`country_code`),
  ADD KEY `idx_region` (`region_name`),
  ADD KEY `idx_updated` (`updated_at`);

--
-- Индексы таблицы `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_users_email` (`email`),
  ADD UNIQUE KEY `uq_users_username` (`username`),
  ADD UNIQUE KEY `uq_users_vm_ref_code` (`vm_ref_code`),
  ADD KEY `idx_users_last_seen_at` (`last_seen_at`),
  ADD KEY `idx_users_country_code` (`country_code`),
  ADD KEY `idx_users_vm_referred_by_user_id` (`vm_referred_by_user_id`);

--
-- Индексы таблицы `user_account_restrictions`
--
ALTER TABLE `user_account_restrictions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_user_id` (`user_id`),
  ADD KEY `idx_posts_until` (`posts_blocked_until`),
  ADD KEY `idx_comments_until` (`comments_blocked_until`),
  ADD KEY `idx_messages_until` (`messages_blocked_until`),
  ADD KEY `idx_forever` (`is_banned_forever`);

--
-- Индексы таблицы `user_follows`
--
ALTER TABLE `user_follows`
  ADD PRIMARY KEY (`follower_user_id`,`followee_user_id`),
  ADD KEY `idx_followee` (`followee_user_id`);

--
-- Индексы таблицы `user_notification_settings`
--
ALTER TABLE `user_notification_settings`
  ADD PRIMARY KEY (`user_id`),
  ADD KEY `idx_email_enabled` (`email_enabled`);

--
-- Индексы таблицы `vm_coin_transactions`
--
ALTER TABLE `vm_coin_transactions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_vm_coin_transactions_op_key` (`op_key`),
  ADD KEY `idx_vm_coin_transactions_user_created` (`user_id`,`created_at`),
  ADD KEY `idx_vm_coin_transactions_event` (`event_key`,`entity_type`,`entity_id`),
  ADD KEY `idx_vm_coin_transactions_related_user` (`related_user_id`);

--
-- AUTO_INCREMENT для сохранённых таблиц
--

--
-- AUTO_INCREMENT для таблицы `album_photos`
--
ALTER TABLE `album_photos`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `audio_playlists`
--
ALTER TABLE `audio_playlists`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `audio_tracks`
--
ALTER TABLE `audio_tracks`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `board_ads`
--
ALTER TABLE `board_ads`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `board_ad_images`
--
ALTER TABLE `board_ad_images`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `board_ad_moderation`
--
ALTER TABLE `board_ad_moderation`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `board_ad_viewers`
--
ALTER TABLE `board_ad_viewers`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `board_categories`
--
ALTER TABLE `board_categories`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `board_regions`
--
ALTER TABLE `board_regions`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `comments`
--
ALTER TABLE `comments`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `comment_attachments`
--
ALTER TABLE `comment_attachments`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `friend_requests`
--
ALTER TABLE `friend_requests`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `game_roulette_transactions`
--
ALTER TABLE `game_roulette_transactions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `groups`
--
ALTER TABLE `groups`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `group_links`
--
ALTER TABLE `group_links`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `group_topics`
--
ALTER TABLE `group_topics`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `message_attachments`
--
ALTER TABLE `message_attachments`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `message_messages`
--
ALTER TABLE `message_messages`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `message_threads`
--
ALTER TABLE `message_threads`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `myfiles`
--
ALTER TABLE `myfiles`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `myfile_folders`
--
ALTER TABLE `myfile_folders`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `myvideos`
--
ALTER TABLE `myvideos`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `notifications`
--
ALTER TABLE `notifications`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `notification_email_log`
--
ALTER TABLE `notification_email_log`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `password_reset_tokens`
--
ALTER TABLE `password_reset_tokens`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `photo_albums`
--
ALTER TABLE `photo_albums`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `posts`
--
ALTER TABLE `posts`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `post_attachments`
--
ALTER TABLE `post_attachments`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `post_polls`
--
ALTER TABLE `post_polls`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `post_poll_options`
--
ALTER TABLE `post_poll_options`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `reclama_campaigns`
--
ALTER TABLE `reclama_campaigns`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `reclama_campaign_clicks`
--
ALTER TABLE `reclama_campaign_clicks`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `reclama_campaign_impressions`
--
ALTER TABLE `reclama_campaign_impressions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `reclama_campaign_moderation`
--
ALTER TABLE `reclama_campaign_moderation`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `security_ip_rules`
--
ALTER TABLE `security_ip_rules`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `security_login_log`
--
ALTER TABLE `security_login_log`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `security_rate_limits`
--
ALTER TABLE `security_rate_limits`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `seo_change_log`
--
ALTER TABLE `seo_change_log`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `seo_pages`
--
ALTER TABLE `seo_pages`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `seo_redirects`
--
ALTER TABLE `seo_redirects`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `site_pages`
--
ALTER TABLE `site_pages`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `traffic_hits`
--
ALTER TABLE `traffic_hits`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `users`
--
ALTER TABLE `users`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `user_account_restrictions`
--
ALTER TABLE `user_account_restrictions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT для таблицы `vm_coin_transactions`
--
ALTER TABLE `vm_coin_transactions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- Ограничения внешнего ключа сохраненных таблиц
--

--
-- Ограничения внешнего ключа таблицы `audio_playlists`
--
ALTER TABLE `audio_playlists`
  ADD CONSTRAINT `fk_audio_playlists_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `audio_playlist_tracks`
--
ALTER TABLE `audio_playlist_tracks`
  ADD CONSTRAINT `fk_audio_pl_tracks_playlist` FOREIGN KEY (`playlist_id`) REFERENCES `audio_playlists` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_audio_pl_tracks_track` FOREIGN KEY (`track_id`) REFERENCES `audio_tracks` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `audio_tracks`
--
ALTER TABLE `audio_tracks`
  ADD CONSTRAINT `fk_audio_tracks_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `comments`
--
ALTER TABLE `comments`
  ADD CONSTRAINT `fk_c_parent` FOREIGN KEY (`parent_id`) REFERENCES `comments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_c_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_c_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `comment_attachments`
--
ALTER TABLE `comment_attachments`
  ADD CONSTRAINT `fk_ca_comment` FOREIGN KEY (`comment_id`) REFERENCES `comments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `comment_reactions`
--
ALTER TABLE `comment_reactions`
  ADD CONSTRAINT `fk_cr_comment` FOREIGN KEY (`comment_id`) REFERENCES `comments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_cr_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `friend_requests`
--
ALTER TABLE `friend_requests`
  ADD CONSTRAINT `fk_friendreq_from_user` FOREIGN KEY (`from_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_friendreq_to_user` FOREIGN KEY (`to_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `groups`
--
ALTER TABLE `groups`
  ADD CONSTRAINT `fk_groups_owner` FOREIGN KEY (`owner_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_groups_topic` FOREIGN KEY (`topic_id`) REFERENCES `group_topics` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `group_links`
--
ALTER TABLE `group_links`
  ADD CONSTRAINT `fk_group_links_group` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `group_members`
--
ALTER TABLE `group_members`
  ADD CONSTRAINT `fk_gm_group` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_gm_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `myfiles`
--
ALTER TABLE `myfiles`
  ADD CONSTRAINT `fk_myfiles_folder` FOREIGN KEY (`folder_id`) REFERENCES `myfile_folders` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_myfiles_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `myfile_folders`
--
ALTER TABLE `myfile_folders`
  ADD CONSTRAINT `fk_mff_parent` FOREIGN KEY (`parent_id`) REFERENCES `myfile_folders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_mff_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `myvideos`
--
ALTER TABLE `myvideos`
  ADD CONSTRAINT `fk_myvideos_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `password_reset_tokens`
--
ALTER TABLE `password_reset_tokens`
  ADD CONSTRAINT `fk_password_reset_tokens_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `posts`
--
ALTER TABLE `posts`
  ADD CONSTRAINT `fk_posts_group` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_posts_repost` FOREIGN KEY (`repost_post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_posts_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `post_attachments`
--
ALTER TABLE `post_attachments`
  ADD CONSTRAINT `fk_pa_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `post_polls`
--
ALTER TABLE `post_polls`
  ADD CONSTRAINT `fk_pp_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `post_poll_options`
--
ALTER TABLE `post_poll_options`
  ADD CONSTRAINT `fk_ppo_poll` FOREIGN KEY (`poll_id`) REFERENCES `post_polls` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `post_poll_votes`
--
ALTER TABLE `post_poll_votes`
  ADD CONSTRAINT `fk_ppv_option` FOREIGN KEY (`option_id`) REFERENCES `post_poll_options` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_ppv_poll` FOREIGN KEY (`poll_id`) REFERENCES `post_polls` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_ppv_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `post_reactions`
--
ALTER TABLE `post_reactions`
  ADD CONSTRAINT `fk_pr_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_pr_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `reclama_campaigns`
--
ALTER TABLE `reclama_campaigns`
  ADD CONSTRAINT `fk_reclama_campaigns_approved_by` FOREIGN KEY (`approved_by_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_reclama_campaigns_post` FOREIGN KEY (`source_post_id`) REFERENCES `posts` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_reclama_campaigns_rejected_by` FOREIGN KEY (`rejected_by_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_reclama_campaigns_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `reclama_campaign_clicks`
--
ALTER TABLE `reclama_campaign_clicks`
  ADD CONSTRAINT `fk_reclama_click_campaign` FOREIGN KEY (`campaign_id`) REFERENCES `reclama_campaigns` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_reclama_click_user` FOREIGN KEY (`viewer_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL;

--
-- Ограничения внешнего ключа таблицы `reclama_campaign_daily_stats`
--
ALTER TABLE `reclama_campaign_daily_stats`
  ADD CONSTRAINT `fk_reclama_daily_campaign` FOREIGN KEY (`campaign_id`) REFERENCES `reclama_campaigns` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `reclama_campaign_impressions`
--
ALTER TABLE `reclama_campaign_impressions`
  ADD CONSTRAINT `fk_reclama_imp_campaign` FOREIGN KEY (`campaign_id`) REFERENCES `reclama_campaigns` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_reclama_imp_user` FOREIGN KEY (`viewer_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL;

--
-- Ограничения внешнего ключа таблицы `reclama_campaign_moderation`
--
ALTER TABLE `reclama_campaign_moderation`
  ADD CONSTRAINT `fk_reclama_mod_admin` FOREIGN KEY (`admin_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_reclama_mod_campaign` FOREIGN KEY (`campaign_id`) REFERENCES `reclama_campaigns` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `reclama_campaign_targeting`
--
ALTER TABLE `reclama_campaign_targeting`
  ADD CONSTRAINT `fk_reclama_target_campaign` FOREIGN KEY (`campaign_id`) REFERENCES `reclama_campaigns` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `security_ip_rules`
--
ALTER TABLE `security_ip_rules`
  ADD CONSTRAINT `fk_security_ip_rules_user` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `security_login_log`
--
ALTER TABLE `security_login_log`
  ADD CONSTRAINT `fk_security_login_log_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;

--
-- Ограничения внешнего ключа таблицы `user_follows`
--
ALTER TABLE `user_follows`
  ADD CONSTRAINT `fk_follows_followee` FOREIGN KEY (`followee_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_follows_follower` FOREIGN KEY (`follower_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Ограничения внешнего ключа таблицы `vm_coin_transactions`
--
ALTER TABLE `vm_coin_transactions`
  ADD CONSTRAINT `fk_vm_coin_transactions_related_user` FOREIGN KEY (`related_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_vm_coin_transactions_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE 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 */;
