-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `iptv_database`
--

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

--
-- Table structure for table `admin`
--

CREATE TABLE `admin` (
  `id` int(11) NOT NULL,
  `user_name` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `admin`
--

INSERT INTO `admin` (`id`, `user_name`, `password`) VALUES
(1, 'Admin', 'Admin!@#');

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

--
-- Table structure for table `admin_tokens`
--

CREATE TABLE `admin_tokens` (
  `token_id` int(11) NOT NULL,
  `admin_id` int(11) DEFAULT NULL,
  `token` text NOT NULL,
  `device_id` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `admin_tokens`
--

INSERT INTO `admin_tokens` (`token_id`, `admin_id`, `token`, `device_id`) VALUES
(2, 1, 'ckxArRLzR3qVVtLTHgmsjq:APA91bFj_hl7rhudPuPna10kACFmX-w33IMpQXqXRAAJRqv8mBUCwAIh41qclGskoaliNIeYovfDyRem8slJCcPaKnzsmUEXCBkgXMbVWeZGe5D7gplI0DM', 'dfd904f52684fb71');

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

--
-- Table structure for table `gmail_app_password`
--

CREATE TABLE `gmail_app_password` (
  `gmail` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `gmail_app_password`
--

INSERT INTO `gmail_app_password` (`gmail`, `password`) VALUES
('starsncontact@gmail.com', 'emijunhugabixcri');

--
-- Triggers `gmail_app_password`
--
DELIMITER $$
CREATE TRIGGER `limit_one_row` BEFORE INSERT ON `gmail_app_password` FOR EACH ROW BEGIN
    DECLARE row_count INT;
    SELECT COUNT(*) INTO row_count FROM gmail_app_password;
    IF row_count >= 1 THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Only one row is allowed in this table.';
    END IF;
END
$$
DELIMITER ;

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

--
-- Table structure for table `selected_plan`
--

CREATE TABLE `selected_plan` (
  `id` int(11) NOT NULL,
  `uid` int(11) NOT NULL,
  `plan_type` enum('Subscription','Trial','','') NOT NULL,
  `plan_duration` varchar(20) NOT NULL,
  `plan_status` enum('Requested','Accepted','Rejected','') NOT NULL DEFAULT 'Requested'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `email` varchar(250) NOT NULL,
  `user_name` varchar(64) NOT NULL,
  `token` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `user_credentials`
--

CREATE TABLE `user_credentials` (
  `id` int(11) NOT NULL,
  `upid` int(11) NOT NULL,
  `acc_username` text NOT NULL,
  `password` text NOT NULL,
  `url` text NOT NULL,
  `is_trial` tinyint(1) NOT NULL,
  `created_at` bigint(20) NOT NULL,
  `exp_date` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `admin`
--
ALTER TABLE `admin`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `admin_tokens`
--
ALTER TABLE `admin_tokens`
  ADD PRIMARY KEY (`token_id`),
  ADD UNIQUE KEY `device_id` (`device_id`) USING HASH,
  ADD KEY `admin_id` (`admin_id`);

--
-- Indexes for table `gmail_app_password`
--
ALTER TABLE `gmail_app_password`
  ADD PRIMARY KEY (`gmail`);

--
-- Indexes for table `selected_plan`
--
ALTER TABLE `selected_plan`
  ADD PRIMARY KEY (`id`),
  ADD KEY `selected_paln_uid_w_user_id` (`uid`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `email` (`email`);

--
-- Indexes for table `user_credentials`
--
ALTER TABLE `user_credentials`
  ADD PRIMARY KEY (`id`),
  ADD KEY `upid_w_plan_id` (`upid`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `admin`
--
ALTER TABLE `admin`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `admin_tokens`
--
ALTER TABLE `admin_tokens`
  MODIFY `token_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `selected_plan`
--
ALTER TABLE `selected_plan`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=15;

--
-- AUTO_INCREMENT for table `user_credentials`
--
ALTER TABLE `user_credentials`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=139;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `admin_tokens`
--
ALTER TABLE `admin_tokens`
  ADD CONSTRAINT `admin_tokens_ibfk_1` FOREIGN KEY (`admin_id`) REFERENCES `admin` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `selected_plan`
--
ALTER TABLE `selected_plan`
  ADD CONSTRAINT `selected_paln_uid_w_user_id` FOREIGN KEY (`uid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Constraints for table `user_credentials`
--
ALTER TABLE `user_credentials`
  ADD CONSTRAINT `upid_w_plan_id` FOREIGN KEY (`upid`) REFERENCES `selected_plan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;

