-- phpMyAdmin SQL Dump
-- version 5.1.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Oct 15, 2023 at 03:31 PM
-- Server version: 10.4.21-MariaDB
-- PHP Version: 7.4.25

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

-- Add New Columns to exisiting tables:

ALTER TABLE `posts`
  ADD `no_index` tinyint(4) NOT NULL DEFAULT 0 COMMENT '' AFTER `seo_title`,
  ADD `show_subscribe_preview_first` tinyint(4) NOT NULL DEFAULT 0 AFTER `data_preview`;


ALTER TABLE `purchases`
  MODIFY `purchase_type` TEXT NOT NULL COMMENT 'subscribe / singlepost / donate / order / wallet / form_order';


ALTER TABLE `forms_responses`
 ADD `form_order_id` int(11) NOT NULL DEFAULT 0 AFTER `form_id`;


ALTER TABLE `forms`
  DROP `quantity_limit_for_every_user`,
  DROP `quantity_title_text`,
  DROP `quantity`,
  DROP `price_off`,
  DROP `price`,
  DROP `form_type`,
  ADD `nature` ENUM('normal','form_order','attachable') NOT NULL DEFAULT 'normal' AFTER `status`,
  ADD `init_price` int(11) NOT NULL DEFAULT 0 AFTER `nature`, 
  ADD `init_price_off` int(11) NOT NULL DEFAULT 0 AFTER `init_price`, 
  ADD `price_fallback_title` TINYTEXT NOT NULL AFTER `init_price_off`, 
  ADD `order_first_status` TINYTEXT NOT NULL AFTER `price_fallback_title`,
  ADD `after_pay_auto_log_text` TEXT NOT NULL DEFAULT '' AFTER `order_first_status`,
  ADD `after_pay_auto_log_btn_text` TEXT NOT NULL DEFAULT '' AFTER `after_pay_auto_log_text`,
  ADD `after_pay_auto_log_intent_type` TEXT NOT NULL DEFAULT '' AFTER `after_pay_auto_log_btn_text`,
  ADD `after_pay_auto_log_intent_data` TEXT NOT NULL DEFAULT '' AFTER `after_pay_auto_log_intent_type`;


CREATE TABLE `form_orders` (
  `id` int(11) NOT NULL,
  `app_id` int(11) NOT NULL DEFAULT 0,
  `user_id` int(11) NOT NULL DEFAULT 0,
  `form_response_id` int(11) NOT NULL DEFAULT 0 COMMENT 'first user response to calculate price',
  `purchase_id` int(11) NOT NULL DEFAULT 0,
  `form_id` int(11) NOT NULL DEFAULT 0,
  `what_user_can_reply` enum('none','text','file','text_file') NOT NULL DEFAULT 'none',
  `status` enum('submitted','working','checking','waiting','need_changes','need_resubmit','canceled','finished','refunded','receiving') NOT NULL DEFAULT 'submitted',
  `date_updated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `date` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


CREATE TABLE `form_orders_log` (
  `id` int(11) NOT NULL,
  `app_id` int(11) NOT NULL DEFAULT 0,
  `form_order_id` int(11) NOT NULL DEFAULT 0,
  `user_id` int(11) NOT NULL DEFAULT 0,
  `author_id` int(11) NOT NULL DEFAULT 0,
  `role_label` enum('user','admin','system') NOT NULL DEFAULT 'user',
  `visible_for_user` tinyint(4) NOT NULL DEFAULT 0,
  `response_text` text NOT NULL,
  `response_file` text NOT NULL,
  `response_btn_text` text NOT NULL,
  `response_intent_type` text NOT NULL,
  `response_intent_data` text NOT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;




ALTER TABLE `form_orders`
  ADD PRIMARY KEY (`id`);


ALTER TABLE `form_orders_log`
  ADD PRIMARY KEY (`id`);


ALTER TABLE `form_orders`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,
  AUTO_INCREMENT = 11001;


ALTER TABLE `form_orders_log`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;


COMMIT;