SET FOREIGN_KEY_CHECKS = 0;
-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_accounts
CREATE TABLE IF NOT EXISTS `codem_mphone_accounts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` char(50) NOT NULL,
  `appname` char(50) NOT NULL,
  `loginstatus` tinyint(4) NOT NULL,
  `username` char(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_accounts_composite` (`phone_number`,`appname`,`loginstatus`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_accounts: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_albums
CREATE TABLE IF NOT EXISTS `codem_mphone_albums` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` char(50) DEFAULT NULL,
  `name` char(50) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `phone_number` (`phone_number`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_albums: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_bankhistory
CREATE TABLE IF NOT EXISTS `codem_mphone_bankhistory` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` char(50) DEFAULT NULL,
  `target_name` char(50) DEFAULT NULL,
  `action` tinyint(4) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `phone_number` (`phone_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_bankhistory: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_authorized_businesses
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_authorized_businesses` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_name` varchar(50) NOT NULL,
  `job_label` varchar(100) NOT NULL,
  `can_invoice` tinyint(1) NOT NULL,
  `commission_rate` int(11) NOT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_job_name` (`job_name`),
  KEY `idx_job_name` (`job_name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;



-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_authorized_citizens
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_authorized_citizens` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `identifier` varchar(100) NOT NULL,
  `name` varchar(100) NOT NULL,
  `can_invoice` tinyint(1) NOT NULL,
  `created_by` varchar(100) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_identifier` (`identifier`),
  KEY `idx_identifier` (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_authorized_citizens: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_business_settings
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_business_settings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_name` varchar(50) NOT NULL,
  `commission_per_employee` int(11) NOT NULL,
  `can_bill_players` tinyint(1) NOT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_job_name` (`job_name`),
  KEY `idx_job_name` (`job_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_business_settings: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_business_tax_invoices
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_business_tax_invoices` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tax_id` int(11) NOT NULL,
  `job_name` varchar(50) NOT NULL,
  `reason` varchar(255) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `status` enum('unpaid','paid') NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `due_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `paid_at` timestamp NULL DEFAULT NULL,
  `paid_by` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_tax_id` (`tax_id`),
  KEY `idx_job_name` (`job_name`),
  KEY `idx_status` (`status`),
  KEY `idx_due_date` (`due_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_business_tax_invoices: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_citizen_tax_invoices
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_citizen_tax_invoices` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tax_id` int(11) NOT NULL,
  `citizen_id` varchar(50) NOT NULL,
  `reason` varchar(255) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `status` enum('unpaid','paid') NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `due_date` timestamp NOT NULL DEFAULT current_timestamp(),
  `paid_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_tax_id` (`tax_id`),
  KEY `idx_citizen_id` (`citizen_id`),
  KEY `idx_status` (`status`),
  KEY `idx_due_date` (`due_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_citizen_tax_invoices: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_employee_permissions
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_employee_permissions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_name` varchar(50) NOT NULL,
  `employee_identifier` varchar(50) NOT NULL,
  `can_access_business` tinyint(1) NOT NULL,
  `can_create_invoices` tinyint(1) NOT NULL,
  `can_cancel_invoices` tinyint(1) NOT NULL,
  `can_pay_taxes` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_job_employee` (`job_name`,`employee_identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_employee_permissions: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_invoices
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_invoices` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sender_id` varchar(100) NOT NULL,
  `sender_type` enum('individual','business','admin','authorized_citizen') NOT NULL,
  `sender_job` varchar(50) DEFAULT NULL,
  `receiver_id` varchar(100) NOT NULL,
  `items` longtext NOT NULL,
  `due_date` date NOT NULL,
  `status` enum('unpaid','paid','overdue') NOT NULL,
  `subtotal` decimal(10,2) NOT NULL,
  `penalty_applied` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `paid_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_sender_id` (`sender_id`),
  KEY `idx_receiver_id` (`receiver_id`),
  KEY `idx_status` (`status`),
  KEY `idx_due_date` (`due_date`),
  KEY `idx_sender_type` (`sender_type`),
  KEY `idx_sender_job` (`sender_job`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_invoices: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_taxes
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_taxes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tax_type` enum('citizen','business') NOT NULL,
  `reason` varchar(255) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `interval_hours` int(11) NOT NULL,
  `job` varchar(50) DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `is_active` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_tax_type` (`tax_type`),
  KEY `idx_job` (`job`),
  KEY `idx_is_active` (`is_active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_taxes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_billing_tax_last_run
CREATE TABLE IF NOT EXISTS `codem_mphone_billing_tax_last_run` (
  `tax_id` varchar(50) NOT NULL,
  `last_run` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`tax_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_billing_tax_last_run: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_call_channels
CREATE TABLE IF NOT EXISTS `codem_mphone_call_channels` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `call_id` varchar(50) NOT NULL,
  `channel_type` enum('private','group') DEFAULT 'private',
  `caller_phone` varchar(20) NOT NULL,
  `call_status` tinyint(4) NOT NULL,
  `duration` int(11) DEFAULT 0,
  `started_at` datetime DEFAULT NULL,
  `ended_at` datetime DEFAULT NULL,
  `hide_number` tinyint(4) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_call_id` (`call_id`),
  KEY `idx_call_id` (`call_id`),
  KEY `idx_caller` (`caller_phone`),
  KEY `idx_created` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_call_channels: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_call_history
CREATE TABLE IF NOT EXISTS `codem_mphone_call_history` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `call_id` varchar(50) NOT NULL,
  `phone_number` varchar(20) NOT NULL,
  `is_outgoing` tinyint(1) NOT NULL,
  `answer_status` tinyint(4) NOT NULL,
  `joined` tinyint(1) NOT NULL,
  `join_time` datetime DEFAULT NULL,
  `leave_time` datetime DEFAULT NULL,
  `is_deleted` tinyint(1) NOT NULL,
  `is_seen` tinyint(1) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_phone` (`phone_number`),
  KEY `idx_call_id` (`call_id`),
  KEY `idx_deleted` (`is_deleted`),
  CONSTRAINT `fk_call_history_channel` FOREIGN KEY (`call_id`) REFERENCES `codem_mphone_call_channels` (`call_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_call_history: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_contacts
CREATE TABLE IF NOT EXISTS `codem_mphone_contacts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `owner_phone` char(50) NOT NULL,
  `target_phone` char(50) NOT NULL,
  `name` char(50) NOT NULL,
  `block` tinyint(4) DEFAULT NULL,
  `fav` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_contacts_owner_name` (`owner_phone`,`name`),
  KEY `idx_owner_fav` (`fav`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_contacts: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_darkchataccount
CREATE TABLE IF NOT EXISTS `codem_mphone_darkchataccount` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` char(50) DEFAULT NULL,
  `password` char(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_username` (`username`),
  KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_darkchataccount: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_darkchat_channels
CREATE TABLE IF NOT EXISTS `codem_mphone_darkchat_channels` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `chatcode` varchar(8) DEFAULT NULL,
  `last_message_id` bigint(20) unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_darkchat_channels: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_darkchat_members
CREATE TABLE IF NOT EXISTS `codem_mphone_darkchat_members` (
  `channel_id` bigint(20) unsigned NOT NULL,
  `phone_number` varchar(15) NOT NULL,
  `username` varchar(50) NOT NULL,
  `role` enum('member','admin') DEFAULT 'member',
  `last_read_id` bigint(20) unsigned DEFAULT 0,
  `joined_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`channel_id`,`phone_number`),
  KEY `idx_phone` (`phone_number`),
  CONSTRAINT `codem_mphone_darkchat_members_ibfk_1` FOREIGN KEY (`channel_id`) REFERENCES `codem_mphone_darkchat_channels` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_darkchat_members: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_darkchat_messages
CREATE TABLE IF NOT EXISTS `codem_mphone_darkchat_messages` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `channel_id` bigint(20) unsigned NOT NULL,
  `sender_phone` varchar(15) NOT NULL,
  `content` text DEFAULT NULL,
  `type` enum('text','media','audio','file','contact','location') DEFAULT 'text',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `username` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_channel_time` (`channel_id`,`created_at` DESC),
  KEY `idx_sender` (`sender_phone`),
  CONSTRAINT `codem_mphone_darkchat_messages_ibfk_1` FOREIGN KEY (`channel_id`) REFERENCES `codem_mphone_darkchat_channels` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_darkchat_messages: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_data
CREATE TABLE IF NOT EXISTS `codem_mphone_data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `owner` varchar(100) DEFAULT NULL,
  `phone_number` varchar(20) DEFAULT NULL,
  `settings` longtext DEFAULT NULL,
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `setup_finish` tinyint(4) DEFAULT 0,
  `email` char(50) DEFAULT NULL,
  `emailpassword` char(50) DEFAULT NULL,
  `securityanswer` char(50) DEFAULT NULL,
  `ringtones` longtext DEFAULT NULL,
  `myapps` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_phone_number` (`phone_number`),
  KEY `idx_last_update` (`last_update`),
  KEY `idx_settings` (`settings`(768))
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_events
CREATE TABLE IF NOT EXISTS `codem_mphone_events` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `creator_phone` varchar(15) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `background_image` varchar(500) DEFAULT NULL,
  `event_date` datetime NOT NULL,
  `location_name` varchar(255) DEFAULT NULL,
  `location_coords` varchar(100) DEFAULT NULL,
  `status` enum('upcoming','active') NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_creator_phone` (`creator_phone`),
  KEY `idx_event_date` (`event_date` DESC),
  KEY `idx_status` (`status`),
  KEY `idx_created` (`created_at` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_events: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_event_participants
CREATE TABLE IF NOT EXISTS `codem_mphone_event_participants` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) unsigned NOT NULL,
  `participant_phone` varchar(15) NOT NULL,
  `status` enum('going','interested','declined') NOT NULL,
  `response_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `is_notified` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_event_participant` (`event_id`,`participant_phone`),
  KEY `idx_event` (`event_id`),
  KEY `idx_participant_phone` (`participant_phone`),
  KEY `idx_status` (`status`),
  CONSTRAINT `codem_mphone_event_participants_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `codem_mphone_events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_event_participants: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotaccount
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotaccount` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` char(50) DEFAULT NULL,
  `name` char(50) DEFAULT NULL,
  `password` char(50) DEFAULT NULL,
  `badge` tinyint(4) DEFAULT 0,
  `profilephoto` longtext DEFAULT NULL,
  `bio` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_username` (`username`),
  KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotaccount: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotactivities
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotactivities` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `targetusername` varchar(50) NOT NULL,
  `action` varchar(50) NOT NULL,
  `post_id` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_action` (`action`),
  KEY `idx_username` (`username`),
  KEY `idx_targetusername` (`targetusername`),
  KEY `idx_post_id` (`post_id`),
  KEY `idx_created_at` (`created_at`),
  CONSTRAINT `fk_instashotactivities_post` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_instashotpost` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotactivities: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotcommentlikes
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotcommentlikes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `comment_id` int(11) NOT NULL,
  `username` char(50) DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `instashot_uniquecommentlike` (`comment_id`,`username`),
  CONSTRAINT `nil` FOREIGN KEY (`comment_id`) REFERENCES `codem_mphone_instashotcomments` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotcommentlikes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotcomments
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotcomments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) NOT NULL,
  `username` char(50) DEFAULT NULL,
  `comment` longtext DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `instashot_uniquelike` (`post_id`,`username`),
  CONSTRAINT `codem_mphone_instashotcomments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_instashotpost` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotcomments: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotfollows
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotfollows` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `follower` char(50) NOT NULL,
  `following` char(50) NOT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `instashot_uniquefollow` (`follower`,`following`),
  KEY `idx_follower` (`follower`),
  KEY `idx_following` (`following`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotfollows: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotlikes
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotlikes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) NOT NULL,
  `username` char(50) DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `instashot_uniquelike` (`post_id`,`username`),
  CONSTRAINT `codem_mphone_instashotlikes_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_instashotpost` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotlikes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotmessages
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotmessages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sender` varchar(50) NOT NULL,
  `receiver` varchar(50) NOT NULL,
  `content` text NOT NULL,
  `type` enum('text','media','post','profile','story_reply') DEFAULT 'text',
  `date` timestamp NULL DEFAULT current_timestamp(),
  `is_read` tinyint(1) DEFAULT 0,
  `deleted_by` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_sender` (`sender`),
  KEY `idx_receiver` (`receiver`),
  KEY `idx_conversation` (`sender`,`receiver`),
  KEY `idx_date` (`date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotmessages: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotpost
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotpost` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` char(50) DEFAULT NULL,
  `content` longtext DEFAULT NULL,
  `media` longtext DEFAULT NULL,
  `location` varchar(255) DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  `sharecount` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_instashotpost_username` (`username`),
  KEY `idx_instashotpost_date` (`date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotpost: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotstories
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotstories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` char(50) NOT NULL,
  `media` longtext NOT NULL,
  `caption` varchar(500) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `expires_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_story_username` (`username`),
  KEY `idx_story_created_at` (`created_at`),
  KEY `idx_story_expires_at` (`expires_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotstories: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_instashotstory_views
CREATE TABLE IF NOT EXISTS `codem_mphone_instashotstory_views` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `story_id` int(11) NOT NULL,
  `viewer` char(50) NOT NULL,
  `viewed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `story_viewer_unique` (`story_id`,`viewer`),
  KEY `idx_storyview_story_id` (`story_id`),
  KEY `idx_storyview_viewer` (`viewer`),
  CONSTRAINT `fk_storyview_story` FOREIGN KEY (`story_id`) REFERENCES `codem_mphone_instashotstories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_instashotstory_views: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_jobby_announcements
CREATE TABLE IF NOT EXISTS `codem_mphone_jobby_announcements` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `jobname` varchar(50) DEFAULT NULL,
  `title` varchar(100) DEFAULT NULL,
  `content` longtext DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `jobname` (`jobname`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_jobby_announcements: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_jobby_log
CREATE TABLE IF NOT EXISTS `codem_mphone_jobby_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `jobname` varchar(50) DEFAULT NULL,
  `action` varchar(50) DEFAULT NULL,
  `phone_number` varchar(15) NOT NULL,
  `playername` varchar(50) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `jobname` (`jobname`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;



-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_last_phone
CREATE TABLE IF NOT EXISTS `codem_mphone_last_phone` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `owner` varchar(100) DEFAULT NULL,
  `phone_number` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_phone_number` (`phone_number`),
  KEY `idx_owner` (`owner`),
  CONSTRAINT `codem_mphone_last_phone_ibfk_1` FOREIGN KEY (`phone_number`) REFERENCES `codem_mphone_data` (`phone_number`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_last_phone: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_mail
CREATE TABLE IF NOT EXISTS `codem_mphone_mail` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sender_name` varchar(50) DEFAULT NULL,
  `sender_email` varchar(50) DEFAULT NULL,
  `sender_identifier` varchar(50) DEFAULT NULL,
  `sender_icon` longtext DEFAULT NULL,
  `read` tinyint(1) DEFAULT 0,
  `receiver_name` varchar(50) DEFAULT NULL,
  `receiver_email` varchar(50) DEFAULT NULL,
  `receiver_identifier` varchar(50) DEFAULT NULL,
  `receiver_icon` longtext DEFAULT NULL,
  `title` longtext DEFAULT NULL,
  `description` longtext DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  `attachements` longtext DEFAULT NULL,
  `can_reply` tinyint(1) DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `idx_receiver_identifier` (`receiver_identifier`),
  KEY `idx_sender_identifier` (`sender_identifier`),
  KEY `idx_mail_identifiers` (`receiver_identifier`,`sender_identifier`),
  KEY `idx_receiver_email` (`receiver_email`),
  KEY `idx_sender_email` (`sender_email`),
  KEY `idx_mail_emails` (`receiver_email`,`sender_email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_mail: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_mail_replies
CREATE TABLE IF NOT EXISTS `codem_mphone_mail_replies` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mail_id` int(11) NOT NULL,
  `sender_identifier` varchar(50) DEFAULT NULL,
  `sender_name` varchar(50) DEFAULT NULL,
  `sender_icon` longtext DEFAULT NULL,
  `message` longtext DEFAULT NULL,
  `attachments` longtext DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  `is_read_by_sender` tinyint(1) DEFAULT 1,
  `is_read_by_receiver` tinyint(1) DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `idx_mail_id` (`mail_id`),
  KEY `idx_sender_identifier` (`sender_identifier`),
  CONSTRAINT `codem_mphone_mail_replies_ibfk_1` FOREIGN KEY (`mail_id`) REFERENCES `codem_mphone_mail` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_mail_replies: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_map_location_sharing
CREATE TABLE IF NOT EXISTS `codem_mphone_map_location_sharing` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `owner_phone` char(50) NOT NULL,
  `shared_with_phone` char(50) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_sharing` (`owner_phone`,`shared_with_phone`),
  KEY `owner_phone` (`owner_phone`),
  KEY `shared_with_phone` (`shared_with_phone`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_map_location_sharing: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_map_pins
CREATE TABLE IF NOT EXISTS `codem_mphone_map_pins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` char(50) DEFAULT NULL,
  `name` varchar(100) NOT NULL,
  `x` float NOT NULL,
  `y` float NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `phone_number` (`phone_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_map_pins: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_members
CREATE TABLE IF NOT EXISTS `codem_mphone_members` (
  `channel_id` bigint(20) unsigned NOT NULL,
  `phone_number` varchar(15) NOT NULL,
  `role` enum('member','admin') DEFAULT 'member',
  `last_read_id` bigint(20) unsigned DEFAULT 0,
  `last_read_time` timestamp NULL DEFAULT current_timestamp(),
  `is_muted` tinyint(1) DEFAULT 0,
  `is_deleted` tinyint(1) DEFAULT 0,
  `joined_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`channel_id`,`phone_number`),
  KEY `idx_phone` (`phone_number`),
  CONSTRAINT `codem_mphone_members_ibfk_1` FOREIGN KEY (`channel_id`) REFERENCES `codem_mphone_message_channels` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_members: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_messages
CREATE TABLE IF NOT EXISTS `codem_mphone_messages` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `channel_id` bigint(20) unsigned NOT NULL,
  `sender_phone` varchar(15) NOT NULL,
  `content` text DEFAULT NULL,
  `type` enum('text','media','audio','file','audiofile','contact','location','money','notes') DEFAULT 'text',
  `is_deleted` tinyint(1) DEFAULT 0,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `reply_to_id` bigint(20) unsigned DEFAULT NULL,
  `forwarded` tinyint(1) DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `idx_channel_time` (`channel_id`,`created_at` DESC),
  KEY `idx_sender` (`sender_phone`),
  CONSTRAINT `codem_mphone_messages_ibfk_1` FOREIGN KEY (`channel_id`) REFERENCES `codem_mphone_message_channels` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_messages: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_message_channels
CREATE TABLE IF NOT EXISTS `codem_mphone_message_channels` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `type` enum('private','group') DEFAULT 'private',
  `name` varchar(100) DEFAULT NULL,
  `avatar` varchar(255) DEFAULT NULL,
  `last_message` text DEFAULT NULL,
  `last_message_at` timestamp NULL DEFAULT current_timestamp(),
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_last_msg` (`last_message_at` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_message_channels: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_music_likemusic
CREATE TABLE IF NOT EXISTS `codem_mphone_music_likemusic` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `phone_number` varchar(20) DEFAULT NULL,
  `musicdata` longtext DEFAULT NULL,
  `videoid` varchar(50) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_music_like` (`phone_number`,`created_at`),
  KEY `idx_music_videoid` (`videoid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_music_likemusic: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_music_playlists
CREATE TABLE IF NOT EXISTS `codem_mphone_music_playlists` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` varchar(15) NOT NULL,
  `name` char(50) DEFAULT NULL,
  `cover` longtext DEFAULT NULL,
  `likes_count` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_playlist` (`phone_number`,`created_at`),
  KEY `idx_likes` (`likes_count`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_music_playlists: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_music_playlists_music
CREATE TABLE IF NOT EXISTS `codem_mphone_music_playlists_music` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `playlist_id` int(11) NOT NULL,
  `musicdata` longtext DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_playlist` (`playlist_id`,`created_at`),
  CONSTRAINT `codem_mphone_music_playlists_music_ibfk_1` FOREIGN KEY (`playlist_id`) REFERENCES `codem_mphone_music_playlists` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_music_playlists_music: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_music_playlist_likes
CREATE TABLE IF NOT EXISTS `codem_mphone_music_playlist_likes` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `playlist_id` int(11) NOT NULL,
  `phone_number` varchar(20) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_playlist_likes` (`playlist_id`,`phone_number`),
  KEY `idx_user_likes` (`phone_number`),
  CONSTRAINT `fk_playlist_likes_playlist` FOREIGN KEY (`playlist_id`) REFERENCES `codem_mphone_music_playlists` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_music_playlist_likes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_news
CREATE TABLE IF NOT EXISTS `codem_mphone_news` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` varchar(50) NOT NULL,
  `author_name` varchar(100) NOT NULL,
  `title` varchar(255) NOT NULL,
  `content` longtext NOT NULL,
  `media` longtext DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_phone_number` (`phone_number`),
  KEY `idx_created_at` (`created_at`),
  KEY `idx_title` (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_news: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_notes
CREATE TABLE IF NOT EXISTS `codem_mphone_notes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` char(50) DEFAULT NULL,
  `header` char(50) DEFAULT NULL,
  `content` longtext DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `phone_number` (`phone_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_notes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_photos
CREATE TABLE IF NOT EXISTS `codem_mphone_photos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` char(50) DEFAULT NULL,
  `media` longtext DEFAULT NULL,
  `size` float DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  `album_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `phone_number` (`phone_number`),
  KEY `codem_mphone_photos_ibfk_1` (`album_id`),
  CONSTRAINT `codem_mphone_photos_ibfk_1` FOREIGN KEY (`album_id`) REFERENCES `codem_mphone_albums` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_photos: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_sellypost
CREATE TABLE IF NOT EXISTS `codem_mphone_sellypost` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` varchar(20) DEFAULT NULL,
  `playername` char(50) DEFAULT NULL,
  `photos` longtext DEFAULT NULL,
  `title` char(50) DEFAULT NULL,
  `description` longtext DEFAULT NULL,
  `price` bigint(20) DEFAULT NULL,
  `allowcalls` tinyint(1) DEFAULT NULL,
  `allowmessage` tinyint(1) DEFAULT NULL,
  `category` char(50) DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `phone_number` (`phone_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_sellypost: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_thunderaccount
CREATE TABLE IF NOT EXISTS `codem_mphone_thunderaccount` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` varchar(20) DEFAULT NULL,
  `name` char(50) DEFAULT NULL,
  `gender` char(50) DEFAULT NULL,
  `age` char(50) DEFAULT NULL,
  `job` char(50) DEFAULT NULL,
  `interested` char(50) DEFAULT NULL,
  `photos` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_phone_number` (`phone_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_thunderaccount: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_thunder_channels
CREATE TABLE IF NOT EXISTS `codem_mphone_thunder_channels` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `last_message_id` bigint(20) unsigned DEFAULT NULL,
  `last_message` text DEFAULT NULL,
  `last_message_time` timestamp NULL DEFAULT current_timestamp(),
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_thunder_channels: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_thunder_members
CREATE TABLE IF NOT EXISTS `codem_mphone_thunder_members` (
  `channel_id` bigint(20) unsigned NOT NULL,
  `phone_number` varchar(15) NOT NULL,
  `username` varchar(50) NOT NULL,
  `last_read_id` bigint(20) unsigned DEFAULT 0,
  `joined_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`channel_id`,`phone_number`),
  KEY `idx_phone` (`phone_number`),
  CONSTRAINT `codem_mphone_thunder_members_ibfk_1` FOREIGN KEY (`channel_id`) REFERENCES `codem_mphone_thunder_channels` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_thunder_members: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_thunder_messages
CREATE TABLE IF NOT EXISTS `codem_mphone_thunder_messages` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `channel_id` bigint(20) unsigned NOT NULL,
  `sender_phone` varchar(15) NOT NULL,
  `content` text DEFAULT NULL,
  `type` enum('text','media','audio','file','contact','location') DEFAULT 'text',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `username` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_channel_time` (`channel_id`,`created_at` DESC),
  KEY `idx_sender` (`sender_phone`),
  CONSTRAINT `codem_mphone_thunder_messages_ibfk_1` FOREIGN KEY (`channel_id`) REFERENCES `codem_mphone_thunder_channels` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_thunder_messages: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_thunder_swipes
CREATE TABLE IF NOT EXISTS `codem_mphone_thunder_swipes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` varchar(20) DEFAULT NULL,
  `target_phone` varchar(20) DEFAULT NULL,
  `action` varchar(10) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_thunder_swipes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixaccount
CREATE TABLE IF NOT EXISTS `codem_mphone_twixaccount` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` char(50) DEFAULT NULL,
  `name` char(50) DEFAULT NULL,
  `password` char(50) DEFAULT NULL,
  `badge` tinyint(4) DEFAULT 0,
  `profilephoto` longtext DEFAULT NULL,
  `bio` longtext DEFAULT NULL,
  `banner` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_username` (`username`),
  KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixaccount: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixactivities
CREATE TABLE IF NOT EXISTS `codem_mphone_twixactivities` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `username` varchar(255) NOT NULL,
  `targetusername` varchar(255) NOT NULL,
  `action` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_action` (`action`),
  KEY `idx_username` (`username`),
  KEY `idx_targetusername` (`targetusername`),
  KEY `idx_post_id` (`post_id`),
  CONSTRAINT `fk_activities_post` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_twixpost` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixactivities: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixcomments
CREATE TABLE IF NOT EXISTS `codem_mphone_twixcomments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) NOT NULL,
  `parent_comment_id` int(11) DEFAULT NULL,
  `username` varchar(50) NOT NULL,
  `content` text NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `is_deleted` tinyint(4) DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `idx_post_id` (`post_id`),
  KEY `idx_parent_comment` (`parent_comment_id`),
  KEY `idx_username` (`username`),
  KEY `idx_created_at` (`created_at`),
  CONSTRAINT `codem_mphone_twixcomments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_twixpost` (`id`) ON DELETE CASCADE,
  CONSTRAINT `codem_mphone_twixcomments_ibfk_2` FOREIGN KEY (`parent_comment_id`) REFERENCES `codem_mphone_twixcomments` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixcomments: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixcomment_likes
CREATE TABLE IF NOT EXISTS `codem_mphone_twixcomment_likes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `comment_id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_comment_like` (`comment_id`,`username`),
  KEY `idx_comment_id` (`comment_id`),
  KEY `idx_username` (`username`),
  CONSTRAINT `codem_mphone_twixcomment_likes_ibfk_1` FOREIGN KEY (`comment_id`) REFERENCES `codem_mphone_twixcomments` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixcomment_likes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixfollows
CREATE TABLE IF NOT EXISTS `codem_mphone_twixfollows` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `follower_username` varchar(50) NOT NULL,
  `following_username` varchar(50) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_follow` (`follower_username`,`following_username`),
  KEY `idx_follower` (`follower_username`),
  KEY `idx_following` (`following_username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixfollows: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixhashtags
CREATE TABLE IF NOT EXISTS `codem_mphone_twixhashtags` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `hashtag` varchar(100) NOT NULL,
  `post_count` int(11) NOT NULL,
  `last_used` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_hashtag` (`hashtag`),
  KEY `idx_hashtag_trending` (`post_count`,`last_used`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixhashtags: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixlikes
CREATE TABLE IF NOT EXISTS `codem_mphone_twixlikes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) NOT NULL,
  `username` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_like` (`post_id`,`username`),
  CONSTRAINT `fk_likes_post` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_twixpost` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixlikes: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixpost
CREATE TABLE IF NOT EXISTS `codem_mphone_twixpost` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` char(50) DEFAULT NULL,
  `content` longtext DEFAULT NULL,
  `media` longtext DEFAULT NULL,
  `date` timestamp NULL DEFAULT current_timestamp(),
  `quote_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `username` (`username`),
  KEY `idx_twixpost_date` (`date`),
  KEY `idx_quote_id` (`quote_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixpost: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixpost_hashtags
CREATE TABLE IF NOT EXISTS `codem_mphone_twixpost_hashtags` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) NOT NULL,
  `hashtag` varchar(100) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_post_hashtags_post` (`post_id`),
  KEY `idx_post_hashtags_hashtag` (`hashtag`),
  CONSTRAINT `fk_post_hashtags_post` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_twixpost` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixpost_hashtags: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_twixreposts
CREATE TABLE IF NOT EXISTS `codem_mphone_twixreposts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) NOT NULL,
  `username` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_postid_username` (`post_id`,`username`),
  CONSTRAINT `fk_repost_post` FOREIGN KEY (`post_id`) REFERENCES `codem_mphone_twixpost` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table esxlegacy_56d0f8.codem_mphone_twixreposts: ~0 rows (approximately)

-- Dumping structure for table esxlegacy_56d0f8.codem_mphone_voice_recordings
CREATE TABLE IF NOT EXISTS `codem_mphone_voice_recordings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone_number` varchar(20) NOT NULL,
  `name` varchar(255) NOT NULL,
  `url` text NOT NULL,
  `location` varchar(255) NOT NULL,
  `duration` varchar(10) NOT NULL,
  `date` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `phone_number` (`phone_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

SET FOREIGN_KEY_CHECKS = 1;