text: 
  SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  SET FOREIGN_KEY_CHECKS=0;
  
  DROP TABLE IF EXISTS `#__sales_order_status`;
  CREATE TABLE `#__sales_order_status` (
    `status` varchar(32) NOT NULL COMMENT 'Status',
    `label` varchar(128) NOT NULL COMMENT 'Label',
    PRIMARY KEY (`status`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Order Status Table';
  
  INSERT INTO `#__sales_order_status` VALUES ('canceled', 'Canceled');
  INSERT INTO `#__sales_order_status` VALUES ('closed', 'Closed');
  INSERT INTO `#__sales_order_status` VALUES ('complete', 'Complete');
  INSERT INTO `#__sales_order_status` VALUES ('fraud', 'Suspected Fraud');
  INSERT INTO `#__sales_order_status` VALUES ('holded', 'On Hold');
  INSERT INTO `#__sales_order_status` VALUES ('payment_review', 'Payment Review');
  INSERT INTO `#__sales_order_status` VALUES ('paypal_canceled_reversal', 'PayPal Canceled Reversal');
  INSERT INTO `#__sales_order_status` VALUES ('paypal_reversed', 'PayPal Reversed');
  INSERT INTO `#__sales_order_status` VALUES ('pending', 'Pending');
  INSERT INTO `#__sales_order_status` VALUES ('pending_payment', 'Pending Payment');
  INSERT INTO `#__sales_order_status` VALUES ('pending_paypal', 'Pending PayPal');
  INSERT INTO `#__sales_order_status` VALUES ('processing', 'Processing');
  
  DROP TABLE IF EXISTS `#__sales_order_status_label`;
  CREATE TABLE `#__sales_order_status_label` (
    `status` varchar(32) NOT NULL COMMENT 'Status',
    `store_id` smallint(5) unsigned NOT NULL COMMENT 'Store Id',
    `label` varchar(128) NOT NULL COMMENT 'Label',
    PRIMARY KEY (`status`,`store_id`),
    KEY `SALES_ORDER_STATUS_LABEL_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_ORDER_STATUS_LABEL_STATUS_SALES_ORDER_STATUS_STATUS` FOREIGN KEY (`status`) REFERENCES `#__sales_order_status` (`status`) ON DELETE CASCADE,
    CONSTRAINT `SALES_ORDER_STATUS_LABEL_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Order Status Label Table';
  
  DROP TABLE IF EXISTS `#__sales_order_status_state`;
  CREATE TABLE `#__sales_order_status_state` (
    `status` varchar(32) NOT NULL COMMENT 'Status',
    `state` varchar(32) NOT NULL COMMENT 'Label',
    `is_default` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is Default',
    `visible_on_front` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Visible on front',
    PRIMARY KEY (`status`,`state`),
    CONSTRAINT `SALES_ORDER_STATUS_STATE_STATUS_SALES_ORDER_STATUS_STATUS` FOREIGN KEY (`status`) REFERENCES `#__sales_order_status` (`status`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Order Status Table';
  
  INSERT INTO `#__sales_order_status_state` VALUES ('canceled', 'canceled', '1', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('closed', 'closed', '1', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('complete', 'complete', '1', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('fraud', 'payment_review', '0', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('fraud', 'processing', '0', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('holded', 'holded', '1', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('payment_review', 'payment_review', '1', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('pending', 'new', '1', '1');
  INSERT INTO `#__sales_order_status_state` VALUES ('pending_payment', 'pending_payment', '1', '0');
  INSERT INTO `#__sales_order_status_state` VALUES ('processing', 'processing', '1', '1');
  
  DROP TABLE IF EXISTS `#__sales_order`;
  CREATE TABLE `#__sales_order` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `state` varchar(32) DEFAULT NULL COMMENT 'State',
    `status` varchar(32) DEFAULT NULL COMMENT 'Status',
    `coupon_code` varchar(255) DEFAULT NULL COMMENT 'Coupon Code',
    `protect_code` varchar(255) DEFAULT NULL COMMENT 'Protect Code',
    `shipping_description` varchar(255) DEFAULT NULL COMMENT 'Shipping Description',
    `is_virtual` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Virtual',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `customer_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Id',
    `base_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Amount',
    `base_discount_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Canceled',
    `base_discount_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Invoiced',
    `base_discount_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Refunded',
    `base_grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Base Grand Total',
    `base_shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Amount',
    `base_shipping_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Canceled',
    `base_shipping_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Invoiced',
    `base_shipping_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Refunded',
    `base_shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Tax Amount',
    `base_shipping_tax_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Tax Refunded',
    `base_subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal',
    `base_subtotal_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal Canceled',
    `base_subtotal_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal Invoiced',
    `base_subtotal_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal Refunded',
    `base_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Amount',
    `base_tax_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Canceled',
    `base_tax_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Invoiced',
    `base_tax_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Refunded',
    `base_to_global_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Global Rate',
    `base_to_order_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Order Rate',
    `base_total_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Canceled',
    `base_total_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Invoiced',
    `base_total_invoiced_cost` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Invoiced Cost',
    `base_total_offline_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Offline Refunded',
    `base_total_online_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Online Refunded',
    `base_total_paid` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Paid',
    `base_total_qty_ordered` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Qty Ordered',
    `base_total_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Refunded',
    `discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Amount',
    `discount_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Discount Canceled',
    `discount_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Discount Invoiced',
    `discount_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Discount Refunded',
    `grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Grand Total',
    `shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Amount',
    `shipping_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Canceled',
    `shipping_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Invoiced',
    `shipping_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Refunded',
    `shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Tax Amount',
    `shipping_tax_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Tax Refunded',
    `store_to_base_rate` decimal(12,4) DEFAULT NULL COMMENT 'Store To Base Rate',
    `store_to_order_rate` decimal(12,4) DEFAULT NULL COMMENT 'Store To Order Rate',
    `subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal',
    `subtotal_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal Canceled',
    `subtotal_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal Invoiced',
    `subtotal_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal Refunded',
    `tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Tax Amount',
    `tax_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Tax Canceled',
    `tax_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Tax Invoiced',
    `tax_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Tax Refunded',
    `total_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Total Canceled',
    `total_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Total Invoiced',
    `total_offline_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Total Offline Refunded',
    `total_online_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Total Online Refunded',
    `total_paid` decimal(12,4) DEFAULT NULL COMMENT 'Total Paid',
    `total_qty_ordered` decimal(12,4) DEFAULT NULL COMMENT 'Total Qty Ordered',
    `total_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Total Refunded',
    `can_ship_partially` smallint(5) unsigned DEFAULT NULL COMMENT 'Can Ship Partially',
    `can_ship_partially_item` smallint(5) unsigned DEFAULT NULL COMMENT 'Can Ship Partially Item',
    `customer_is_guest` smallint(5) unsigned DEFAULT NULL COMMENT 'Customer Is Guest',
    `customer_note_notify` smallint(5) unsigned DEFAULT NULL COMMENT 'Customer Note Notify',
    `billing_address_id` int(11) DEFAULT NULL COMMENT 'Billing Address Id',
    `customer_group_id` smallint(6) DEFAULT NULL COMMENT 'Customer Group Id',
    `edit_increment` int(11) DEFAULT NULL COMMENT 'Edit Increment',
    `email_sent` smallint(5) unsigned DEFAULT NULL COMMENT 'Email Sent',
    `send_email` smallint(5) unsigned DEFAULT NULL COMMENT 'Send Email',
    `forced_shipment_with_invoice` smallint(5) unsigned DEFAULT NULL COMMENT 'Forced Do Shipment With Invoice',
    `payment_auth_expiration` int(11) DEFAULT NULL COMMENT 'Payment Authorization Expiration',
    `quote_address_id` int(11) DEFAULT NULL COMMENT 'Quote Address Id',
    `quote_id` int(11) DEFAULT NULL COMMENT 'Quote Id',
    `shipping_address_id` int(11) DEFAULT NULL COMMENT 'Shipping Address Id',
    `adjustment_negative` decimal(12,4) DEFAULT NULL COMMENT 'Adjustment Negative',
    `adjustment_positive` decimal(12,4) DEFAULT NULL COMMENT 'Adjustment Positive',
    `base_adjustment_negative` decimal(12,4) DEFAULT NULL COMMENT 'Base Adjustment Negative',
    `base_adjustment_positive` decimal(12,4) DEFAULT NULL COMMENT 'Base Adjustment Positive',
    `base_shipping_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Discount Amount',
    `base_subtotal_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal Incl Tax',
    `base_total_due` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Due',
    `payment_authorization_amount` decimal(12,4) DEFAULT NULL COMMENT 'Payment Authorization Amount',
    `shipping_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Discount Amount',
    `subtotal_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal Incl Tax',
    `total_due` decimal(12,4) DEFAULT NULL COMMENT 'Total Due',
    `weight` decimal(12,4) DEFAULT NULL COMMENT 'Weight',
    `customer_dob` datetime DEFAULT NULL COMMENT 'Customer Dob',
    `increment_id` varchar(32) DEFAULT NULL COMMENT 'Increment Id',
    `applied_rule_ids` varchar(128) DEFAULT NULL COMMENT 'Applied Rule Ids',
    `base_currency_code` varchar(3) DEFAULT NULL COMMENT 'Base Currency Code',
    `customer_email` varchar(128) DEFAULT NULL COMMENT 'Customer Email',
    `customer_firstname` varchar(128) DEFAULT NULL COMMENT 'Customer Firstname',
    `customer_lastname` varchar(128) DEFAULT NULL COMMENT 'Customer Lastname',
    `customer_middlename` varchar(128) DEFAULT NULL COMMENT 'Customer Middlename',
    `customer_prefix` varchar(32) DEFAULT NULL COMMENT 'Customer Prefix',
    `customer_suffix` varchar(32) DEFAULT NULL COMMENT 'Customer Suffix',
    `customer_taxvat` varchar(32) DEFAULT NULL COMMENT 'Customer Taxvat',
    `discount_description` varchar(255) DEFAULT NULL COMMENT 'Discount Description',
    `ext_customer_id` varchar(32) DEFAULT NULL COMMENT 'Ext Customer Id',
    `ext_order_id` varchar(32) DEFAULT NULL COMMENT 'Ext Order Id',
    `global_currency_code` varchar(3) DEFAULT NULL COMMENT 'Global Currency Code',
    `hold_before_state` varchar(32) DEFAULT NULL COMMENT 'Hold Before State',
    `hold_before_status` varchar(32) DEFAULT NULL COMMENT 'Hold Before Status',
    `order_currency_code` varchar(3) DEFAULT NULL COMMENT 'Order Currency Code',
    `original_increment_id` varchar(32) DEFAULT NULL COMMENT 'Original Increment Id',
    `relation_child_id` varchar(32) DEFAULT NULL COMMENT 'Relation Child Id',
    `relation_child_real_id` varchar(32) DEFAULT NULL COMMENT 'Relation Child Real Id',
    `relation_parent_id` varchar(32) DEFAULT NULL COMMENT 'Relation Parent Id',
    `relation_parent_real_id` varchar(32) DEFAULT NULL COMMENT 'Relation Parent Real Id',
    `remote_ip` varchar(32) DEFAULT NULL COMMENT 'Remote Ip',
    `shipping_method` varchar(32) DEFAULT NULL COMMENT 'Shipping Method',
    `store_currency_code` varchar(3) DEFAULT NULL COMMENT 'Store Currency Code',
    `store_name` varchar(32) DEFAULT NULL COMMENT 'Store Name',
    `x_forwarded_for` varchar(32) DEFAULT NULL COMMENT 'X Forwarded For',
    `customer_note` text COMMENT 'Customer Note',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `total_item_count` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Total Item Count',
    `customer_gender` int(11) DEFAULT NULL COMMENT 'Customer Gender',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `shipping_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Discount Tax Compensation Amount',
    `base_shipping_discount_tax_compensation_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Discount Tax Compensation Amount',
    `discount_tax_compensation_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Invoiced',
    `base_discount_tax_compensation_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Invoiced',
    `discount_tax_compensation_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Refunded',
    `base_discount_tax_compensation_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Refunded',
    `shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Incl Tax',
    `base_shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Incl Tax',
    `coupon_rule_name` varchar(255) DEFAULT NULL COMMENT 'Coupon Sales Rule Name',
    `paypal_ipn_customer_notified` int(11) DEFAULT '0' COMMENT 'Paypal Ipn Customer Notified',
    `gift_message_id` int(11) DEFAULT NULL COMMENT 'Gift Message Id',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_ORDER_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_ORDER_STATUS` (`status`),
    KEY `SALES_ORDER_STATE` (`state`),
    KEY `SALES_ORDER_STORE_ID` (`store_id`),
    KEY `SALES_ORDER_CREATED_AT` (`created_at`),
    KEY `SALES_ORDER_CUSTOMER_ID` (`customer_id`),
    KEY `SALES_ORDER_EXT_ORDER_ID` (`ext_order_id`),
    KEY `SALES_ORDER_QUOTE_ID` (`quote_id`),
    KEY `SALES_ORDER_UPDATED_AT` (`updated_at`),
    KEY `SALES_ORDER_SEND_EMAIL` (`send_email`),
    KEY `SALES_ORDER_EMAIL_SENT` (`email_sent`),
    CONSTRAINT `SALES_ORDER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `#__customer_entity` (`entity_id`) ON DELETE SET NULL,
    CONSTRAINT `SALES_ORDER_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Order';
  
  DROP TABLE IF EXISTS `#__sales_order_address`;
  CREATE TABLE `#__sales_order_address` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned DEFAULT NULL COMMENT 'Parent Id',
    `customer_address_id` int(11) DEFAULT NULL COMMENT 'Customer Address Id',
    `quote_address_id` int(11) DEFAULT NULL COMMENT 'Quote Address Id',
    `region_id` int(11) DEFAULT NULL COMMENT 'Region Id',
    `customer_id` int(11) DEFAULT NULL COMMENT 'Customer Id',
    `fax` varchar(255) DEFAULT NULL COMMENT 'Fax',
    `region` varchar(255) DEFAULT NULL COMMENT 'Region',
    `postcode` varchar(255) DEFAULT NULL COMMENT 'Postcode',
    `lastname` varchar(255) DEFAULT NULL COMMENT 'Lastname',
    `street` varchar(255) DEFAULT NULL COMMENT 'Street',
    `city` varchar(255) DEFAULT NULL COMMENT 'City',
    `email` varchar(255) DEFAULT NULL COMMENT 'Email',
    `telephone` varchar(255) DEFAULT NULL COMMENT 'Phone Number',
    `country_id` varchar(2) DEFAULT NULL COMMENT 'Country Id',
    `firstname` varchar(255) DEFAULT NULL COMMENT 'Firstname',
    `address_type` varchar(255) DEFAULT NULL COMMENT 'Address Type',
    `prefix` varchar(255) DEFAULT NULL COMMENT 'Prefix',
    `middlename` varchar(255) DEFAULT NULL COMMENT 'Middlename',
    `suffix` varchar(255) DEFAULT NULL COMMENT 'Suffix',
    `company` varchar(255) DEFAULT NULL COMMENT 'Company',
    `vat_id` text COMMENT 'Vat Id',
    `vat_is_valid` smallint(6) DEFAULT NULL COMMENT 'Vat Is Valid',
    `vat_request_id` text COMMENT 'Vat Request Id',
    `vat_request_date` text COMMENT 'Vat Request Date',
    `vat_request_success` smallint(6) DEFAULT NULL COMMENT 'Vat Request Success',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_ORDER_ADDRESS_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_ORDER_ADDRESS_PARENT_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Order Address';
  
  DROP TABLE IF EXISTS `#__sales_order_grid`;
  CREATE TABLE `#__sales_order_grid` (
    `entity_id` int(10) unsigned NOT NULL COMMENT 'Entity Id',
    `status` varchar(32) DEFAULT NULL COMMENT 'Status',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `store_name` varchar(255) DEFAULT NULL COMMENT 'Store Name',
    `customer_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Id',
    `base_grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Base Grand Total',
    `base_total_paid` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Paid',
    `grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Grand Total',
    `total_paid` decimal(12,4) DEFAULT NULL COMMENT 'Total Paid',
    `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
    `base_currency_code` varchar(3) DEFAULT NULL COMMENT 'Base Currency Code',
    `order_currency_code` varchar(255) DEFAULT NULL COMMENT 'Order Currency Code',
    `shipping_name` varchar(255) DEFAULT NULL COMMENT 'Shipping Name',
    `billing_name` varchar(255) DEFAULT NULL COMMENT 'Billing Name',
    `created_at` timestamp NULL DEFAULT NULL COMMENT 'Created At',
    `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Updated At',
    `billing_address` varchar(255) DEFAULT NULL COMMENT 'Billing Address',
    `shipping_address` varchar(255) DEFAULT NULL COMMENT 'Shipping Address',
    `shipping_information` varchar(255) DEFAULT NULL COMMENT 'Shipping Method Name',
    `customer_email` varchar(255) DEFAULT NULL COMMENT 'Customer Email',
    `customer_group` varchar(255) DEFAULT NULL COMMENT 'Customer Group',
    `subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal',
    `shipping_and_handling` decimal(12,4) DEFAULT NULL COMMENT 'Shipping and handling amount',
    `customer_name` varchar(255) DEFAULT NULL COMMENT 'Customer Name',
    `payment_method` varchar(255) DEFAULT NULL COMMENT 'Payment Method',
    `total_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Total Refunded',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_ORDER_GRID_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_ORDER_GRID_STATUS` (`status`),
    KEY `SALES_ORDER_GRID_STORE_ID` (`store_id`),
    KEY `SALES_ORDER_GRID_BASE_GRAND_TOTAL` (`base_grand_total`),
    KEY `SALES_ORDER_GRID_BASE_TOTAL_PAID` (`base_total_paid`),
    KEY `SALES_ORDER_GRID_GRAND_TOTAL` (`grand_total`),
    KEY `SALES_ORDER_GRID_TOTAL_PAID` (`total_paid`),
    KEY `SALES_ORDER_GRID_SHIPPING_NAME` (`shipping_name`),
    KEY `SALES_ORDER_GRID_BILLING_NAME` (`billing_name`),
    KEY `SALES_ORDER_GRID_CREATED_AT` (`created_at`),
    KEY `SALES_ORDER_GRID_CUSTOMER_ID` (`customer_id`),
    KEY `SALES_ORDER_GRID_UPDATED_AT` (`updated_at`),
    FULLTEXT KEY `FTI_65B9E9925EC58F0C7C2E2F6379C233E7` (`increment_id`,`billing_name`,`shipping_name`,`shipping_address`,`billing_address`,`customer_name`,`customer_email`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Order Grid';
  
  DROP TABLE IF EXISTS `#__sales_order_item`;
  CREATE TABLE `#__sales_order_item` (
    `item_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Item Id',
    `order_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Order Id',
    `parent_item_id` int(10) unsigned DEFAULT NULL COMMENT 'Parent Item Id',
    `quote_item_id` int(10) unsigned DEFAULT NULL COMMENT 'Quote Item Id',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `product_id` int(10) unsigned DEFAULT NULL COMMENT 'Product Id',
    `product_type` varchar(255) DEFAULT NULL COMMENT 'Product Type',
    `product_options` text COMMENT 'Product Options',
    `weight` decimal(12,4) DEFAULT '0.0000' COMMENT 'Weight',
    `is_virtual` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Virtual',
    `sku` varchar(255) DEFAULT NULL COMMENT 'Sku',
    `name` varchar(255) DEFAULT NULL COMMENT 'Name',
    `description` text COMMENT 'Description',
    `applied_rule_ids` text COMMENT 'Applied Rule Ids',
    `additional_data` text COMMENT 'Additional Data',
    `is_qty_decimal` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Qty Decimal',
    `no_discount` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'No Discount',
    `qty_backordered` decimal(12,4) DEFAULT '0.0000' COMMENT 'Qty Backordered',
    `qty_canceled` decimal(12,4) DEFAULT '0.0000' COMMENT 'Qty Canceled',
    `qty_invoiced` decimal(12,4) DEFAULT '0.0000' COMMENT 'Qty Invoiced',
    `qty_ordered` decimal(12,4) DEFAULT '0.0000' COMMENT 'Qty Ordered',
    `qty_refunded` decimal(12,4) DEFAULT '0.0000' COMMENT 'Qty Refunded',
    `qty_shipped` decimal(12,4) DEFAULT '0.0000' COMMENT 'Qty Shipped',
    `base_cost` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Cost',
    `price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Price',
    `base_price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Price',
    `original_price` decimal(12,4) DEFAULT NULL COMMENT 'Original Price',
    `base_original_price` decimal(12,4) DEFAULT NULL COMMENT 'Base Original Price',
    `tax_percent` decimal(12,4) DEFAULT '0.0000' COMMENT 'Tax Percent',
    `tax_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Tax Amount',
    `base_tax_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Tax Amount',
    `tax_invoiced` decimal(12,4) DEFAULT '0.0000' COMMENT 'Tax Invoiced',
    `base_tax_invoiced` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Tax Invoiced',
    `discount_percent` decimal(12,4) DEFAULT '0.0000' COMMENT 'Discount Percent',
    `discount_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Discount Amount',
    `base_discount_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Discount Amount',
    `discount_invoiced` decimal(12,4) DEFAULT '0.0000' COMMENT 'Discount Invoiced',
    `base_discount_invoiced` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Discount Invoiced',
    `amount_refunded` decimal(12,4) DEFAULT '0.0000' COMMENT 'Amount Refunded',
    `base_amount_refunded` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Amount Refunded',
    `row_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Row Total',
    `base_row_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Row Total',
    `row_invoiced` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Row Invoiced',
    `base_row_invoiced` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Row Invoiced',
    `row_weight` decimal(12,4) DEFAULT '0.0000' COMMENT 'Row Weight',
    `base_tax_before_discount` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Before Discount',
    `tax_before_discount` decimal(12,4) DEFAULT NULL COMMENT 'Tax Before Discount',
    `ext_order_item_id` varchar(255) DEFAULT NULL COMMENT 'Ext Order Item Id',
    `locked_do_invoice` smallint(5) unsigned DEFAULT NULL COMMENT 'Locked Do Invoice',
    `locked_do_ship` smallint(5) unsigned DEFAULT NULL COMMENT 'Locked Do Ship',
    `price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Price Incl Tax',
    `base_price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Price Incl Tax',
    `row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Row Total Incl Tax',
    `base_row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Row Total Incl Tax',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `discount_tax_compensation_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Invoiced',
    `base_discount_tax_compensation_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Invoiced',
    `discount_tax_compensation_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Refunded',
    `base_discount_tax_compensation_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Refunded',
    `tax_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Tax Canceled',
    `discount_tax_compensation_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Canceled',
    `tax_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Tax Refunded',
    `base_tax_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Refunded',
    `discount_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Discount Refunded',
    `base_discount_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Refunded',
    `free_shipping` smallint(6) DEFAULT NULL,
    `gift_message_id` int(11) DEFAULT NULL COMMENT 'Gift Message Id',
    `gift_message_available` int(11) DEFAULT NULL COMMENT 'Gift Message Available',
    `weee_tax_applied` text COMMENT 'Weee Tax Applied',
    `weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Amount',
    `weee_tax_applied_row_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Row Amount',
    `weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Disposition',
    `weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Row Disposition',
    `base_weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Amount',
    `base_weee_tax_applied_row_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Row Amnt',
    `base_weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Disposition',
    `base_weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Row Disposition',
    PRIMARY KEY (`item_id`),
    KEY `SALES_ORDER_ITEM_ORDER_ID` (`order_id`),
    KEY `SALES_ORDER_ITEM_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_ORDER_ITEM_ORDER_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`order_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_ORDER_ITEM_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Order Item';
  
  DROP TABLE IF EXISTS `#__sales_order_status_history`;
  CREATE TABLE `#__sales_order_status_history` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `is_customer_notified` int(11) DEFAULT NULL COMMENT 'Is Customer Notified',
    `is_visible_on_front` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is Visible On Front',
    `comment` text COMMENT 'Comment',
    `status` varchar(32) DEFAULT NULL COMMENT 'Status',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `entity_name` varchar(32) DEFAULT NULL COMMENT 'Shows what entity history is bind to.',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_ORDER_STATUS_HISTORY_PARENT_ID` (`parent_id`),
    KEY `SALES_ORDER_STATUS_HISTORY_CREATED_AT` (`created_at`),
    CONSTRAINT `SALES_ORDER_STATUS_HISTORY_PARENT_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Order Status History';
  
  DROP TABLE IF EXISTS `#__sales_order_tax`;
  CREATE TABLE `#__sales_order_tax` (
    `tax_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Tax Id',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `code` varchar(255) DEFAULT NULL COMMENT 'Code',
    `title` varchar(255) DEFAULT NULL COMMENT 'Title',
    `percent` decimal(12,4) DEFAULT NULL COMMENT 'Percent',
    `amount` decimal(12,4) DEFAULT NULL COMMENT 'Amount',
    `priority` int(11) NOT NULL COMMENT 'Priority',
    `position` int(11) NOT NULL COMMENT 'Position',
    `base_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount',
    `process` smallint(6) NOT NULL COMMENT 'Process',
    `base_real_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Real Amount',
    PRIMARY KEY (`tax_id`),
    KEY `SALES_ORDER_TAX_ORDER_ID_PRIORITY_POSITION` (`order_id`,`priority`,`position`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Order Tax Table';
  
  DROP TABLE IF EXISTS `#__sales_order_tax_item`;
  CREATE TABLE `#__sales_order_tax_item` (
    `tax_item_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Tax Item Id',
    `tax_id` int(10) unsigned NOT NULL COMMENT 'Tax Id',
    `item_id` int(10) unsigned DEFAULT NULL COMMENT 'Item Id',
    `tax_percent` decimal(12,4) NOT NULL COMMENT 'Real Tax Percent For Item',
    `amount` decimal(12,4) NOT NULL COMMENT 'Tax amount for the item and tax rate',
    `base_amount` decimal(12,4) NOT NULL COMMENT 'Base tax amount for the item and tax rate',
    `real_amount` decimal(12,4) NOT NULL COMMENT 'Real tax amount for the item and tax rate',
    `real_base_amount` decimal(12,4) NOT NULL COMMENT 'Real base tax amount for the item and tax rate',
    `associated_item_id` int(10) unsigned DEFAULT NULL COMMENT 'Id of the associated item',
    `taxable_item_type` varchar(32) NOT NULL COMMENT 'Type of the taxable item',
    PRIMARY KEY (`tax_item_id`),
    UNIQUE KEY `SALES_ORDER_TAX_ITEM_TAX_ID_ITEM_ID` (`tax_id`,`item_id`),
    KEY `SALES_ORDER_TAX_ITEM_ITEM_ID` (`item_id`),
    KEY `SALES_ORDER_TAX_ITEM_ASSOCIATED_ITEM_ID_SALES_ORDER_ITEM_ITEM_ID` (`associated_item_id`),
    CONSTRAINT `SALES_ORDER_TAX_ITEM_ASSOCIATED_ITEM_ID_SALES_ORDER_ITEM_ITEM_ID` FOREIGN KEY (`associated_item_id`) REFERENCES `#__sales_order_item` (`item_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_ORDER_TAX_ITEM_ITEM_ID_SALES_ORDER_ITEM_ITEM_ID` FOREIGN KEY (`item_id`) REFERENCES `#__sales_order_item` (`item_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_ORDER_TAX_ITEM_TAX_ID_SALES_ORDER_TAX_TAX_ID` FOREIGN KEY (`tax_id`) REFERENCES `#__sales_order_tax` (`tax_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Order Tax Item';
  
  DROP TABLE IF EXISTS `#__sales_order_aggregated_created`;
  CREATE TABLE `#__sales_order_aggregated_created` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) NOT NULL COMMENT 'Order Status',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `total_qty_ordered` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Qty Ordered',
    `total_qty_invoiced` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Qty Invoiced',
    `total_income_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Income Amount',
    `total_revenue_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Revenue Amount',
    `total_profit_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Profit Amount',
    `total_invoiced_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Invoiced Amount',
    `total_canceled_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Canceled Amount',
    `total_paid_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Paid Amount',
    `total_refunded_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Refunded Amount',
    `total_tax_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Tax Amount',
    `total_tax_amount_actual` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Tax Amount Actual',
    `total_shipping_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Shipping Amount',
    `total_shipping_amount_actual` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Shipping Amount Actual',
    `total_discount_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Discount Amount',
    `total_discount_amount_actual` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Discount Amount Actual',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_ORDER_AGGREGATED_CREATED_PERIOD_STORE_ID_ORDER_STATUS` (`period`,`store_id`,`order_status`),
    KEY `SALES_ORDER_AGGREGATED_CREATED_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_ORDER_AGGREGATED_CREATED_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Order Aggregated Created';
  
  DROP TABLE IF EXISTS `#__sales_order_aggregated_updated`;
  CREATE TABLE `#__sales_order_aggregated_updated` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) NOT NULL COMMENT 'Order Status',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `total_qty_ordered` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Qty Ordered',
    `total_qty_invoiced` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Qty Invoiced',
    `total_income_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Income Amount',
    `total_revenue_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Revenue Amount',
    `total_profit_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Profit Amount',
    `total_invoiced_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Invoiced Amount',
    `total_canceled_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Canceled Amount',
    `total_paid_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Paid Amount',
    `total_refunded_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Refunded Amount',
    `total_tax_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Tax Amount',
    `total_tax_amount_actual` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Tax Amount Actual',
    `total_shipping_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Shipping Amount',
    `total_shipping_amount_actual` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Shipping Amount Actual',
    `total_discount_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Discount Amount',
    `total_discount_amount_actual` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Total Discount Amount Actual',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_ORDER_AGGREGATED_UPDATED_PERIOD_STORE_ID_ORDER_STATUS` (`period`,`store_id`,`order_status`),
    KEY `SALES_ORDER_AGGREGATED_UPDATED_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_ORDER_AGGREGATED_UPDATED_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Order Aggregated Updated';
  
  DROP TABLE IF EXISTS `#__quote`;
  CREATE TABLE `#__quote` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `converted_at` timestamp NULL DEFAULT NULL COMMENT 'Converted At',
    `is_active` smallint(5) unsigned DEFAULT '1' COMMENT 'Is Active',
    `is_virtual` smallint(5) unsigned DEFAULT '0' COMMENT 'Is Virtual',
    `is_multi_shipping` smallint(5) unsigned DEFAULT '0' COMMENT 'Is Multi Shipping',
    `items_count` int(10) unsigned DEFAULT '0' COMMENT 'Items Count',
    `items_qty` decimal(12,4) DEFAULT '0.0000' COMMENT 'Items Qty',
    `orig_order_id` int(10) unsigned DEFAULT '0' COMMENT 'Orig Order Id',
    `store_to_base_rate` decimal(12,4) DEFAULT '0.0000' COMMENT 'Store To Base Rate',
    `store_to_quote_rate` decimal(12,4) DEFAULT '0.0000' COMMENT 'Store To Quote Rate',
    `base_currency_code` varchar(255) DEFAULT NULL COMMENT 'Base Currency Code',
    `store_currency_code` varchar(255) DEFAULT NULL COMMENT 'Store Currency Code',
    `quote_currency_code` varchar(255) DEFAULT NULL COMMENT 'Quote Currency Code',
    `grand_total` decimal(12,4) DEFAULT '0.0000' COMMENT 'Grand Total',
    `base_grand_total` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Grand Total',
    `checkout_method` varchar(255) DEFAULT NULL COMMENT 'Checkout Method',
    `customer_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Id',
    `customer_tax_class_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Tax Class Id',
    `customer_group_id` int(10) unsigned DEFAULT '0' COMMENT 'Customer Group Id',
    `customer_email` varchar(255) DEFAULT NULL COMMENT 'Customer Email',
    `customer_prefix` varchar(40) DEFAULT NULL COMMENT 'Customer Prefix',
    `customer_firstname` varchar(255) DEFAULT NULL COMMENT 'Customer Firstname',
    `customer_middlename` varchar(40) DEFAULT NULL COMMENT 'Customer Middlename',
    `customer_lastname` varchar(255) DEFAULT NULL COMMENT 'Customer Lastname',
    `customer_suffix` varchar(40) DEFAULT NULL COMMENT 'Customer Suffix',
    `customer_dob` datetime DEFAULT NULL COMMENT 'Customer Dob',
    `customer_note` varchar(255) DEFAULT NULL COMMENT 'Customer Note',
    `customer_note_notify` smallint(5) unsigned DEFAULT '1' COMMENT 'Customer Note Notify',
    `customer_is_guest` smallint(5) unsigned DEFAULT '0' COMMENT 'Customer Is Guest',
    `remote_ip` varchar(32) DEFAULT NULL COMMENT 'Remote Ip',
    `applied_rule_ids` varchar(255) DEFAULT NULL COMMENT 'Applied Rule Ids',
    `reserved_order_id` varchar(64) DEFAULT NULL COMMENT 'Reserved Order Id',
    `password_hash` varchar(255) DEFAULT NULL COMMENT 'Password Hash',
    `coupon_code` varchar(255) DEFAULT NULL COMMENT 'Coupon Code',
    `global_currency_code` varchar(255) DEFAULT NULL COMMENT 'Global Currency Code',
    `base_to_global_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Global Rate',
    `base_to_quote_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Quote Rate',
    `customer_taxvat` varchar(255) DEFAULT NULL COMMENT 'Customer Taxvat',
    `customer_gender` varchar(255) DEFAULT NULL COMMENT 'Customer Gender',
    `subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal',
    `base_subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal',
    `subtotal_with_discount` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal With Discount',
    `base_subtotal_with_discount` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal With Discount',
    `is_changed` int(10) unsigned DEFAULT NULL COMMENT 'Is Changed',
    `trigger_recollect` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Trigger Recollect',
    `ext_shipping_info` text COMMENT 'Ext Shipping Info',
    `is_persistent` smallint(5) unsigned DEFAULT '0' COMMENT 'Is Quote Persistent',
    `gift_message_id` int(11) DEFAULT NULL COMMENT 'Gift Message Id',
    PRIMARY KEY (`entity_id`),
    KEY `QUOTE_CUSTOMER_ID_STORE_ID_IS_ACTIVE` (`customer_id`,`store_id`,`is_active`),
    KEY `QUOTE_STORE_ID` (`store_id`),
    CONSTRAINT `QUOTE_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Quote';
  
  DROP TABLE IF EXISTS `#__quote_address`;
  CREATE TABLE `#__quote_address` (
    `address_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Address Id',
    `quote_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Quote Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `customer_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Id',
    `save_in_address_book` smallint(6) DEFAULT '0' COMMENT 'Save In Address Book',
    `customer_address_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Address Id',
    `address_type` varchar(10) DEFAULT NULL COMMENT 'Address Type',
    `email` varchar(255) DEFAULT NULL COMMENT 'Email',
    `prefix` varchar(40) DEFAULT NULL COMMENT 'Prefix',
    `firstname` varchar(20) DEFAULT NULL COMMENT 'Firstname',
    `middlename` varchar(20) DEFAULT NULL COMMENT 'Middlename',
    `lastname` varchar(20) DEFAULT NULL COMMENT 'Lastname',
    `suffix` varchar(40) DEFAULT NULL COMMENT 'Suffix',
    `company` varchar(255) DEFAULT NULL COMMENT 'Company',
    `street` varchar(40) DEFAULT NULL COMMENT 'Street',
    `city` varchar(40) DEFAULT NULL COMMENT 'City',
    `region` varchar(40) DEFAULT NULL COMMENT 'Region',
    `region_id` int(10) unsigned DEFAULT NULL COMMENT 'Region Id',
    `postcode` varchar(20) DEFAULT NULL COMMENT 'Postcode',
    `country_id` varchar(30) DEFAULT NULL COMMENT 'Country Id',
    `telephone` varchar(20) DEFAULT NULL COMMENT 'Phone Number',
    `fax` varchar(20) DEFAULT NULL COMMENT 'Fax',
    `same_as_billing` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Same As Billing',
    `collect_shipping_rates` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Collect Shipping Rates',
    `shipping_method` varchar(40) DEFAULT NULL COMMENT 'Shipping Method',
    `shipping_description` varchar(255) DEFAULT NULL COMMENT 'Shipping Description',
    `weight` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Weight',
    `subtotal` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Subtotal',
    `base_subtotal` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Subtotal',
    `subtotal_with_discount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Subtotal With Discount',
    `base_subtotal_with_discount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Subtotal With Discount',
    `tax_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Tax Amount',
    `base_tax_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Tax Amount',
    `shipping_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Shipping Amount',
    `base_shipping_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Shipping Amount',
    `shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Tax Amount',
    `base_shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Tax Amount',
    `discount_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Discount Amount',
    `base_discount_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Discount Amount',
    `grand_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Grand Total',
    `base_grand_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Grand Total',
    `customer_notes` text COMMENT 'Customer Notes',
    `applied_taxes` text COMMENT 'Applied Taxes',
    `discount_description` varchar(255) DEFAULT NULL COMMENT 'Discount Description',
    `shipping_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Discount Amount',
    `base_shipping_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Discount Amount',
    `subtotal_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal Incl Tax',
    `base_subtotal_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal Total Incl Tax',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `shipping_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Discount Tax Compensation Amount',
    `base_shipping_discount_tax_compensation_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Discount Tax Compensation Amount',
    `shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Incl Tax',
    `base_shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Incl Tax',
    `free_shipping` smallint(6) DEFAULT NULL,
    `vat_id` text COMMENT 'Vat Id',
    `vat_is_valid` smallint(6) DEFAULT NULL COMMENT 'Vat Is Valid',
    `vat_request_id` text COMMENT 'Vat Request Id',
    `vat_request_date` text COMMENT 'Vat Request Date',
    `vat_request_success` smallint(6) DEFAULT NULL COMMENT 'Vat Request Success',
    `gift_message_id` int(11) DEFAULT NULL COMMENT 'Gift Message Id',
    PRIMARY KEY (`address_id`),
    KEY `QUOTE_ADDRESS_QUOTE_ID` (`quote_id`),
    CONSTRAINT `QUOTE_ADDRESS_QUOTE_ID_QUOTE_ENTITY_ID` FOREIGN KEY (`quote_id`) REFERENCES `#__quote` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Quote Address';
  
  DROP TABLE IF EXISTS `#__quote_address_item`;
  CREATE TABLE `#__quote_address_item` (
    `address_item_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Address Item Id',
    `parent_item_id` int(10) unsigned DEFAULT NULL COMMENT 'Parent Item Id',
    `quote_address_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Quote Address Id',
    `quote_item_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Quote Item Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `applied_rule_ids` text COMMENT 'Applied Rule Ids',
    `additional_data` text COMMENT 'Additional Data',
    `weight` decimal(12,4) DEFAULT '0.0000' COMMENT 'Weight',
    `qty` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Qty',
    `discount_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Discount Amount',
    `tax_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Tax Amount',
    `row_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Row Total',
    `base_row_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Row Total',
    `row_total_with_discount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Row Total With Discount',
    `base_discount_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Discount Amount',
    `base_tax_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Tax Amount',
    `row_weight` decimal(12,4) DEFAULT '0.0000' COMMENT 'Row Weight',
    `product_id` int(10) unsigned DEFAULT NULL COMMENT 'Product Id',
    `super_product_id` int(10) unsigned DEFAULT NULL COMMENT 'Super Product Id',
    `parent_product_id` int(10) unsigned DEFAULT NULL COMMENT 'Parent Product Id',
    `sku` varchar(255) DEFAULT NULL COMMENT 'Sku',
    `image` varchar(255) DEFAULT NULL COMMENT 'Image',
    `name` varchar(255) DEFAULT NULL COMMENT 'Name',
    `description` text COMMENT 'Description',
    `is_qty_decimal` int(10) unsigned DEFAULT NULL COMMENT 'Is Qty Decimal',
    `price` decimal(12,4) DEFAULT NULL COMMENT 'Price',
    `discount_percent` decimal(12,4) DEFAULT NULL COMMENT 'Discount Percent',
    `no_discount` int(10) unsigned DEFAULT NULL COMMENT 'No Discount',
    `tax_percent` decimal(12,4) DEFAULT NULL COMMENT 'Tax Percent',
    `base_price` decimal(12,4) DEFAULT NULL COMMENT 'Base Price',
    `base_cost` decimal(12,4) DEFAULT NULL COMMENT 'Base Cost',
    `price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Price Incl Tax',
    `base_price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Price Incl Tax',
    `row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Row Total Incl Tax',
    `base_row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Row Total Incl Tax',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `free_shipping` int(11) DEFAULT NULL,
    `gift_message_id` int(11) DEFAULT NULL COMMENT 'Gift Message Id',
    PRIMARY KEY (`address_item_id`),
    KEY `QUOTE_ADDRESS_ITEM_QUOTE_ADDRESS_ID` (`quote_address_id`),
    KEY `QUOTE_ADDRESS_ITEM_PARENT_ITEM_ID` (`parent_item_id`),
    KEY `QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID` (`quote_item_id`),
    CONSTRAINT `QUOTE_ADDRESS_ITEM_QUOTE_ADDRESS_ID_QUOTE_ADDRESS_ADDRESS_ID` FOREIGN KEY (`quote_address_id`) REFERENCES `#__quote_address` (`address_id`) ON DELETE CASCADE,
    CONSTRAINT `QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID_QUOTE_ITEM_ITEM_ID` FOREIGN KEY (`quote_item_id`) REFERENCES `#__quote_item` (`item_id`) ON DELETE CASCADE,
    CONSTRAINT `QUOTE_ADDR_ITEM_PARENT_ITEM_ID_QUOTE_ADDR_ITEM_ADDR_ITEM_ID` FOREIGN KEY (`parent_item_id`) REFERENCES `#__quote_address_item` (`address_item_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Quote Address Item';
  
  DROP TABLE IF EXISTS `#__quote_item`;
  CREATE TABLE `#__quote_item` (
    `item_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Item Id',
    `quote_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Quote Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `product_id` int(10) unsigned DEFAULT NULL COMMENT 'Product Id',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `parent_item_id` int(10) unsigned DEFAULT NULL COMMENT 'Parent Item Id',
    `is_virtual` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Virtual',
    `sku` varchar(255) DEFAULT NULL COMMENT 'Sku',
    `name` varchar(255) DEFAULT NULL COMMENT 'Name',
    `description` text COMMENT 'Description',
    `applied_rule_ids` text COMMENT 'Applied Rule Ids',
    `additional_data` text COMMENT 'Additional Data',
    `is_qty_decimal` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Qty Decimal',
    `no_discount` smallint(5) unsigned DEFAULT '0' COMMENT 'No Discount',
    `weight` decimal(12,4) DEFAULT '0.0000' COMMENT 'Weight',
    `qty` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Qty',
    `price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Price',
    `base_price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Price',
    `custom_price` decimal(12,4) DEFAULT NULL COMMENT 'Custom Price',
    `discount_percent` decimal(12,4) DEFAULT '0.0000' COMMENT 'Discount Percent',
    `discount_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Discount Amount',
    `base_discount_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Discount Amount',
    `tax_percent` decimal(12,4) DEFAULT '0.0000' COMMENT 'Tax Percent',
    `tax_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Tax Amount',
    `base_tax_amount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Base Tax Amount',
    `row_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Row Total',
    `base_row_total` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Base Row Total',
    `row_total_with_discount` decimal(12,4) DEFAULT '0.0000' COMMENT 'Row Total With Discount',
    `row_weight` decimal(12,4) DEFAULT '0.0000' COMMENT 'Row Weight',
    `product_type` varchar(255) DEFAULT NULL COMMENT 'Product Type',
    `base_tax_before_discount` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Before Discount',
    `tax_before_discount` decimal(12,4) DEFAULT NULL COMMENT 'Tax Before Discount',
    `original_custom_price` decimal(12,4) DEFAULT NULL COMMENT 'Original Custom Price',
    `redirect_url` varchar(255) DEFAULT NULL COMMENT 'Redirect Url',
    `base_cost` decimal(12,4) DEFAULT NULL COMMENT 'Base Cost',
    `price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Price Incl Tax',
    `base_price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Price Incl Tax',
    `row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Row Total Incl Tax',
    `base_row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Row Total Incl Tax',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `free_shipping` smallint(6) DEFAULT NULL,
    `gift_message_id` int(11) DEFAULT NULL COMMENT 'Gift Message Id',
    `weee_tax_applied` text COMMENT 'Weee Tax Applied',
    `weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Amount',
    `weee_tax_applied_row_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Row Amount',
    `weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Disposition',
    `weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Row Disposition',
    `base_weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Amount',
    `base_weee_tax_applied_row_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Row Amnt',
    `base_weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Disposition',
    `base_weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Row Disposition',
    PRIMARY KEY (`item_id`),
    KEY `QUOTE_ITEM_PARENT_ITEM_ID` (`parent_item_id`),
    KEY `QUOTE_ITEM_PRODUCT_ID` (`product_id`),
    KEY `QUOTE_ITEM_QUOTE_ID` (`quote_id`),
    KEY `QUOTE_ITEM_STORE_ID` (`store_id`),
    CONSTRAINT `QUOTE_ITEM_PARENT_ITEM_ID_QUOTE_ITEM_ITEM_ID` FOREIGN KEY (`parent_item_id`) REFERENCES `#__quote_item` (`item_id`) ON DELETE CASCADE,
    CONSTRAINT `QUOTE_ITEM_PRODUCT_ID_CATALOG_PRODUCT_ENTITY_ENTITY_ID` FOREIGN KEY (`product_id`) REFERENCES `#__catalog_product_entity` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `QUOTE_ITEM_QUOTE_ID_QUOTE_ENTITY_ID` FOREIGN KEY (`quote_id`) REFERENCES `#__quote` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `QUOTE_ITEM_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Quote Item';
  
  DROP TABLE IF EXISTS `#__quote_item_option`;
  CREATE TABLE `#__quote_item_option` (
    `option_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Option Id',
    `item_id` int(10) unsigned NOT NULL COMMENT 'Item Id',
    `product_id` int(10) unsigned NOT NULL COMMENT 'Product Id',
    `code` varchar(255) NOT NULL COMMENT 'Code',
    `value` text COMMENT 'Value',
    PRIMARY KEY (`option_id`),
    KEY `QUOTE_ITEM_OPTION_ITEM_ID` (`item_id`),
    CONSTRAINT `QUOTE_ITEM_OPTION_ITEM_ID_QUOTE_ITEM_ITEM_ID` FOREIGN KEY (`item_id`) REFERENCES `#__quote_item` (`item_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Quote Item Option';
  
  DROP TABLE IF EXISTS `#__quote_payment`;
  CREATE TABLE `#__quote_payment` (
    `payment_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Payment Id',
    `quote_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Quote Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `method` varchar(255) DEFAULT NULL COMMENT 'Method',
    `cc_type` varchar(255) DEFAULT NULL COMMENT 'Cc Type',
    `cc_number_enc` varchar(255) DEFAULT NULL COMMENT 'Cc Number Enc',
    `cc_last_4` varchar(255) DEFAULT NULL COMMENT 'Cc Last 4',
    `cc_cid_enc` varchar(255) DEFAULT NULL COMMENT 'Cc Cid Enc',
    `cc_owner` varchar(255) DEFAULT NULL COMMENT 'Cc Owner',
    `cc_exp_month` varchar(255) DEFAULT NULL COMMENT 'Cc Exp Month',
    `cc_exp_year` smallint(5) unsigned DEFAULT '0' COMMENT 'Cc Exp Year',
    `cc_ss_owner` varchar(255) DEFAULT NULL COMMENT 'Cc Ss Owner',
    `cc_ss_start_month` smallint(5) unsigned DEFAULT '0' COMMENT 'Cc Ss Start Month',
    `cc_ss_start_year` smallint(5) unsigned DEFAULT '0' COMMENT 'Cc Ss Start Year',
    `po_number` varchar(255) DEFAULT NULL COMMENT 'Po Number',
    `additional_data` text COMMENT 'Additional Data',
    `cc_ss_issue` varchar(255) DEFAULT NULL COMMENT 'Cc Ss Issue',
    `additional_information` text COMMENT 'Additional Information',
    `paypal_payer_id` varchar(255) DEFAULT NULL COMMENT 'Paypal Payer Id',
    `paypal_payer_status` varchar(255) DEFAULT NULL COMMENT 'Paypal Payer Status',
    `paypal_correlation_id` varchar(255) DEFAULT NULL COMMENT 'Paypal Correlation Id',
    PRIMARY KEY (`payment_id`),
    KEY `QUOTE_PAYMENT_QUOTE_ID` (`quote_id`),
    CONSTRAINT `QUOTE_PAYMENT_QUOTE_ID_QUOTE_ENTITY_ID` FOREIGN KEY (`quote_id`) REFERENCES `#__quote` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Quote Payment';
  
  DROP TABLE IF EXISTS `#__quote_shipping_rate`;
  CREATE TABLE `#__quote_shipping_rate` (
    `rate_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Rate Id',
    `address_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Address Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `carrier` varchar(255) DEFAULT NULL COMMENT 'Carrier',
    `carrier_title` varchar(255) DEFAULT NULL COMMENT 'Carrier Title',
    `code` varchar(255) DEFAULT NULL COMMENT 'Code',
    `method` varchar(255) DEFAULT NULL COMMENT 'Method',
    `method_description` text COMMENT 'Method Description',
    `price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Price',
    `error_message` text COMMENT 'Error Message',
    `method_title` text COMMENT 'Method Title',
    PRIMARY KEY (`rate_id`),
    KEY `QUOTE_SHIPPING_RATE_ADDRESS_ID` (`address_id`),
    CONSTRAINT `QUOTE_SHIPPING_RATE_ADDRESS_ID_QUOTE_ADDRESS_ADDRESS_ID` FOREIGN KEY (`address_id`) REFERENCES `#__quote_address` (`address_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Quote Shipping Rate';
  
  DROP TABLE IF EXISTS `#__sales_order_payment`;
  CREATE TABLE `#__sales_order_payment` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `base_shipping_captured` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Captured',
    `shipping_captured` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Captured',
    `amount_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Amount Refunded',
    `base_amount_paid` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount Paid',
    `amount_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Amount Canceled',
    `base_amount_authorized` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount Authorized',
    `base_amount_paid_online` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount Paid Online',
    `base_amount_refunded_online` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount Refunded Online',
    `base_shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Amount',
    `shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Amount',
    `amount_paid` decimal(12,4) DEFAULT NULL COMMENT 'Amount Paid',
    `amount_authorized` decimal(12,4) DEFAULT NULL COMMENT 'Amount Authorized',
    `base_amount_ordered` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount Ordered',
    `base_shipping_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Refunded',
    `shipping_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Refunded',
    `base_amount_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount Refunded',
    `amount_ordered` decimal(12,4) DEFAULT NULL COMMENT 'Amount Ordered',
    `base_amount_canceled` decimal(12,4) DEFAULT NULL COMMENT 'Base Amount Canceled',
    `quote_payment_id` int(11) DEFAULT NULL COMMENT 'Quote Payment Id',
    `additional_data` text COMMENT 'Additional Data',
    `cc_exp_month` varchar(12) DEFAULT NULL COMMENT 'Cc Exp Month',
    `cc_ss_start_year` varchar(12) DEFAULT NULL COMMENT 'Cc Ss Start Year',
    `echeck_bank_name` varchar(128) DEFAULT NULL COMMENT 'Echeck Bank Name',
    `method` varchar(128) DEFAULT NULL COMMENT 'Method',
    `cc_debug_request_body` varchar(32) DEFAULT NULL COMMENT 'Cc Debug Request Body',
    `cc_secure_verify` varchar(32) DEFAULT NULL COMMENT 'Cc Secure Verify',
    `protection_eligibility` varchar(32) DEFAULT NULL COMMENT 'Protection Eligibility',
    `cc_approval` varchar(32) DEFAULT NULL COMMENT 'Cc Approval',
    `cc_last_4` varchar(100) DEFAULT NULL COMMENT 'Cc Last 4',
    `cc_status_description` varchar(32) DEFAULT NULL COMMENT 'Cc Status Description',
    `echeck_type` varchar(32) DEFAULT NULL COMMENT 'Echeck Type',
    `cc_debug_response_serialized` varchar(32) DEFAULT NULL COMMENT 'Cc Debug Response Serialized',
    `cc_ss_start_month` varchar(128) DEFAULT NULL COMMENT 'Cc Ss Start Month',
    `echeck_account_type` varchar(255) DEFAULT NULL COMMENT 'Echeck Account Type',
    `last_trans_id` varchar(32) DEFAULT NULL COMMENT 'Last Trans Id',
    `cc_cid_status` varchar(32) DEFAULT NULL COMMENT 'Cc Cid Status',
    `cc_owner` varchar(128) DEFAULT NULL COMMENT 'Cc Owner',
    `cc_type` varchar(32) DEFAULT NULL COMMENT 'Cc Type',
    `po_number` varchar(32) DEFAULT NULL COMMENT 'Po Number',
    `cc_exp_year` varchar(4) DEFAULT NULL COMMENT 'Cc Exp Year',
    `cc_status` varchar(4) DEFAULT NULL COMMENT 'Cc Status',
    `echeck_routing_number` varchar(32) DEFAULT NULL COMMENT 'Echeck Routing Number',
    `account_status` varchar(32) DEFAULT NULL COMMENT 'Account Status',
    `anet_trans_method` varchar(32) DEFAULT NULL COMMENT 'Anet Trans Method',
    `cc_debug_response_body` varchar(32) DEFAULT NULL COMMENT 'Cc Debug Response Body',
    `cc_ss_issue` varchar(32) DEFAULT NULL COMMENT 'Cc Ss Issue',
    `echeck_account_name` varchar(32) DEFAULT NULL COMMENT 'Echeck Account Name',
    `cc_avs_status` varchar(32) DEFAULT NULL COMMENT 'Cc Avs Status',
    `cc_number_enc` varchar(32) DEFAULT NULL COMMENT 'Cc Number Enc',
    `cc_trans_id` varchar(32) DEFAULT NULL COMMENT 'Cc Trans Id',
    `address_status` varchar(32) DEFAULT NULL COMMENT 'Address Status',
    `additional_information` text COMMENT 'Additional Information',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_ORDER_PAYMENT_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_ORDER_PAYMENT_PARENT_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Order Payment';
  
  DROP TABLE IF EXISTS `#__sales_payment_transaction`;
  CREATE TABLE `#__sales_payment_transaction` (
    `transaction_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Transaction Id',
    `parent_id` int(10) unsigned DEFAULT NULL COMMENT 'Parent Id',
    `order_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Order Id',
    `payment_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Payment Id',
    `txn_id` varchar(100) DEFAULT NULL COMMENT 'Txn Id',
    `parent_txn_id` varchar(100) DEFAULT NULL COMMENT 'Parent Txn Id',
    `txn_type` varchar(15) DEFAULT NULL COMMENT 'Txn Type',
    `is_closed` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Is Closed',
    `additional_information` blob COMMENT 'Additional Information',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    PRIMARY KEY (`transaction_id`),
    UNIQUE KEY `SALES_PAYMENT_TRANSACTION_ORDER_ID_PAYMENT_ID_TXN_ID` (`order_id`,`payment_id`,`txn_id`),
    KEY `SALES_PAYMENT_TRANSACTION_PARENT_ID` (`parent_id`),
    KEY `SALES_PAYMENT_TRANSACTION_PAYMENT_ID` (`payment_id`),
    CONSTRAINT `FK_B99FF1A06402D725EBDB0F3A7ECD47A2` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_payment_transaction` (`transaction_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_PAYMENT_TRANSACTION_ORDER_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`order_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_PAYMENT_TRANSACTION_PAYMENT_ID_SALES_ORDER_PAYMENT_ENTT_ID` FOREIGN KEY (`payment_id`) REFERENCES `#__sales_order_payment` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Payment Transaction';
  
  DROP TABLE IF EXISTS `#__sales_refunded_aggregated`;
  CREATE TABLE `#__sales_refunded_aggregated` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) NOT NULL COMMENT 'Order Status',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `refunded` decimal(12,4) DEFAULT NULL COMMENT 'Refunded',
    `online_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Online Refunded',
    `offline_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Offline Refunded',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_REFUNDED_AGGREGATED_PERIOD_STORE_ID_ORDER_STATUS` (`period`,`store_id`,`order_status`),
    KEY `SALES_REFUNDED_AGGREGATED_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_REFUNDED_AGGREGATED_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Refunded Aggregated';
  
  DROP TABLE IF EXISTS `#__sales_refunded_aggregated_order`;
  CREATE TABLE `#__sales_refunded_aggregated_order` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) DEFAULT NULL COMMENT 'Order Status',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `refunded` decimal(12,4) DEFAULT NULL COMMENT 'Refunded',
    `online_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Online Refunded',
    `offline_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Offline Refunded',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_REFUNDED_AGGREGATED_ORDER_PERIOD_STORE_ID_ORDER_STATUS` (`period`,`store_id`,`order_status`),
    KEY `SALES_REFUNDED_AGGREGATED_ORDER_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_REFUNDED_AGGREGATED_ORDER_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Refunded Aggregated Order';
  
  DROP TABLE IF EXISTS `#__sales_invoice`;
  CREATE TABLE `#__sales_invoice` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `base_grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Base Grand Total',
    `shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Tax Amount',
    `tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Tax Amount',
    `base_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Amount',
    `store_to_order_rate` decimal(12,4) DEFAULT NULL COMMENT 'Store To Order Rate',
    `base_shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Tax Amount',
    `base_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Amount',
    `base_to_order_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Order Rate',
    `grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Grand Total',
    `shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Amount',
    `subtotal_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal Incl Tax',
    `base_subtotal_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal Incl Tax',
    `store_to_base_rate` decimal(12,4) DEFAULT NULL COMMENT 'Store To Base Rate',
    `base_shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Amount',
    `total_qty` decimal(12,4) DEFAULT NULL COMMENT 'Total Qty',
    `base_to_global_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Global Rate',
    `subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal',
    `base_subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal',
    `discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Amount',
    `billing_address_id` int(11) DEFAULT NULL COMMENT 'Billing Address Id',
    `is_used_for_refund` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Used For Refund',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `email_sent` smallint(5) unsigned DEFAULT NULL COMMENT 'Email Sent',
    `send_email` smallint(5) unsigned DEFAULT NULL COMMENT 'Send Email',
    `can_void_flag` smallint(5) unsigned DEFAULT NULL COMMENT 'Can Void Flag',
    `state` int(11) DEFAULT NULL COMMENT 'State',
    `shipping_address_id` int(11) DEFAULT NULL COMMENT 'Shipping Address Id',
    `store_currency_code` varchar(3) DEFAULT NULL COMMENT 'Store Currency Code',
    `transaction_id` varchar(255) DEFAULT NULL COMMENT 'Transaction Id',
    `order_currency_code` varchar(3) DEFAULT NULL COMMENT 'Order Currency Code',
    `base_currency_code` varchar(3) DEFAULT NULL COMMENT 'Base Currency Code',
    `global_currency_code` varchar(3) DEFAULT NULL COMMENT 'Global Currency Code',
    `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `shipping_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Discount Tax Compensation Amount',
    `base_shipping_discount_tax_compensation_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Discount Tax Compensation Amount',
    `shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Incl Tax',
    `base_shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Incl Tax',
    `base_total_refunded` decimal(12,4) DEFAULT NULL COMMENT 'Base Total Refunded',
    `discount_description` varchar(255) DEFAULT NULL COMMENT 'Discount Description',
    `customer_note` text COMMENT 'Customer Note',
    `customer_note_notify` smallint(5) unsigned DEFAULT NULL COMMENT 'Customer Note Notify',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_INVOICE_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_INVOICE_STORE_ID` (`store_id`),
    KEY `SALES_INVOICE_GRAND_TOTAL` (`grand_total`),
    KEY `SALES_INVOICE_ORDER_ID` (`order_id`),
    KEY `SALES_INVOICE_STATE` (`state`),
    KEY `SALES_INVOICE_CREATED_AT` (`created_at`),
    KEY `SALES_INVOICE_UPDATED_AT` (`updated_at`),
    KEY `SALES_INVOICE_SEND_EMAIL` (`send_email`),
    KEY `SALES_INVOICE_EMAIL_SENT` (`email_sent`),
    CONSTRAINT `SALES_INVOICE_ORDER_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`order_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_INVOICE_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Invoice';
  
  DROP TABLE IF EXISTS `#__sales_invoiced_aggregated`;
  CREATE TABLE `#__sales_invoiced_aggregated` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) DEFAULT NULL COMMENT 'Order Status',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `orders_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Orders Invoiced',
    `invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Invoiced',
    `invoiced_captured` decimal(12,4) DEFAULT NULL COMMENT 'Invoiced Captured',
    `invoiced_not_captured` decimal(12,4) DEFAULT NULL COMMENT 'Invoiced Not Captured',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_INVOICED_AGGREGATED_PERIOD_STORE_ID_ORDER_STATUS` (`period`,`store_id`,`order_status`),
    KEY `SALES_INVOICED_AGGREGATED_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_INVOICED_AGGREGATED_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Invoiced Aggregated';
  
  DROP TABLE IF EXISTS `#__sales_invoiced_aggregated_order`;
  CREATE TABLE `#__sales_invoiced_aggregated_order` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) NOT NULL COMMENT 'Order Status',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `orders_invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Orders Invoiced',
    `invoiced` decimal(12,4) DEFAULT NULL COMMENT 'Invoiced',
    `invoiced_captured` decimal(12,4) DEFAULT NULL COMMENT 'Invoiced Captured',
    `invoiced_not_captured` decimal(12,4) DEFAULT NULL COMMENT 'Invoiced Not Captured',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_INVOICED_AGGREGATED_ORDER_PERIOD_STORE_ID_ORDER_STATUS` (`period`,`store_id`,`order_status`),
    KEY `SALES_INVOICED_AGGREGATED_ORDER_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_INVOICED_AGGREGATED_ORDER_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Invoiced Aggregated Order';
  
  DROP TABLE IF EXISTS `#__sales_invoice_comment`;
  CREATE TABLE `#__sales_invoice_comment` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `is_customer_notified` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Customer Notified',
    `is_visible_on_front` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is Visible On Front',
    `comment` text COMMENT 'Comment',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_INVOICE_COMMENT_CREATED_AT` (`created_at`),
    KEY `SALES_INVOICE_COMMENT_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_INVOICE_COMMENT_PARENT_ID_SALES_INVOICE_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_invoice` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Invoice Comment';
  
  DROP TABLE IF EXISTS `#__sales_invoice_grid`;
  CREATE TABLE `#__sales_invoice_grid` (
    `entity_id` int(10) unsigned NOT NULL COMMENT 'Entity Id',
    `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
    `state` int(11) DEFAULT NULL COMMENT 'State',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `store_name` varchar(255) DEFAULT NULL COMMENT 'Store Name',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `order_increment_id` varchar(50) DEFAULT NULL COMMENT 'Order Increment Id',
    `order_created_at` timestamp NULL DEFAULT NULL COMMENT 'Order Created At',
    `customer_name` varchar(255) DEFAULT NULL COMMENT 'Customer Name',
    `customer_email` varchar(255) DEFAULT NULL COMMENT 'Customer Email',
    `customer_group_id` smallint(6) DEFAULT NULL COMMENT 'Customer Group Id',
    `payment_method` varchar(128) DEFAULT NULL COMMENT 'Payment Method',
    `store_currency_code` varchar(3) DEFAULT NULL COMMENT 'Store Currency Code',
    `order_currency_code` varchar(3) DEFAULT NULL COMMENT 'Order Currency Code',
    `base_currency_code` varchar(3) DEFAULT NULL COMMENT 'Base Currency Code',
    `global_currency_code` varchar(3) DEFAULT NULL COMMENT 'Global Currency Code',
    `billing_name` varchar(255) DEFAULT NULL COMMENT 'Billing Name',
    `billing_address` varchar(255) DEFAULT NULL COMMENT 'Billing Address',
    `shipping_address` varchar(255) DEFAULT NULL COMMENT 'Shipping Address',
    `shipping_information` varchar(255) DEFAULT NULL COMMENT 'Shipping Method Name',
    `subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal',
    `shipping_and_handling` decimal(12,4) DEFAULT NULL COMMENT 'Shipping and handling amount',
    `grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Grand Total',
    `created_at` timestamp NULL DEFAULT NULL COMMENT 'Created At',
    `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Updated At',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_INVOICE_GRID_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_INVOICE_GRID_STORE_ID` (`store_id`),
    KEY `SALES_INVOICE_GRID_GRAND_TOTAL` (`grand_total`),
    KEY `SALES_INVOICE_GRID_ORDER_ID` (`order_id`),
    KEY `SALES_INVOICE_GRID_STATE` (`state`),
    KEY `SALES_INVOICE_GRID_ORDER_INCREMENT_ID` (`order_increment_id`),
    KEY `SALES_INVOICE_GRID_CREATED_AT` (`created_at`),
    KEY `SALES_INVOICE_GRID_UPDATED_AT` (`updated_at`),
    KEY `SALES_INVOICE_GRID_ORDER_CREATED_AT` (`order_created_at`),
    KEY `SALES_INVOICE_GRID_BILLING_NAME` (`billing_name`),
    FULLTEXT KEY `FTI_95D9C924DD6A8734EB8B5D01D60F90DE` (`increment_id`,`order_increment_id`,`billing_name`,`billing_address`,`shipping_address`,`customer_name`,`customer_email`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Invoice Grid';
  
  DROP TABLE IF EXISTS `#__sales_invoice_item`;
  CREATE TABLE `#__sales_invoice_item` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `base_price` decimal(12,4) DEFAULT NULL COMMENT 'Base Price',
    `tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Tax Amount',
    `base_row_total` decimal(12,4) DEFAULT NULL COMMENT 'Base Row Total',
    `discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Amount',
    `row_total` decimal(12,4) DEFAULT NULL COMMENT 'Row Total',
    `base_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Amount',
    `price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Price Incl Tax',
    `base_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Amount',
    `base_price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Price Incl Tax',
    `qty` decimal(12,4) DEFAULT NULL COMMENT 'Qty',
    `base_cost` decimal(12,4) DEFAULT NULL COMMENT 'Base Cost',
    `price` decimal(12,4) DEFAULT NULL COMMENT 'Price',
    `base_row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Row Total Incl Tax',
    `row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Row Total Incl Tax',
    `product_id` int(11) DEFAULT NULL COMMENT 'Product Id',
    `order_item_id` int(11) DEFAULT NULL COMMENT 'Order Item Id',
    `additional_data` text COMMENT 'Additional Data',
    `description` text COMMENT 'Description',
    `sku` varchar(255) DEFAULT NULL COMMENT 'Sku',
    `name` varchar(255) DEFAULT NULL COMMENT 'Name',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `tax_ratio` text COMMENT 'Ratio of tax invoiced over tax of the order item',
    `weee_tax_applied` text COMMENT 'Weee Tax Applied',
    `weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Amount',
    `weee_tax_applied_row_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Row Amount',
    `weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Disposition',
    `weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Row Disposition',
    `base_weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Amount',
    `base_weee_tax_applied_row_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Row Amnt',
    `base_weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Disposition',
    `base_weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Row Disposition',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_INVOICE_ITEM_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_INVOICE_ITEM_PARENT_ID_SALES_INVOICE_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_invoice` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Invoice Item';
  
  DROP TABLE IF EXISTS `#__sales_shipment`;
  CREATE TABLE `#__sales_shipment` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `total_weight` decimal(12,4) DEFAULT NULL COMMENT 'Total Weight',
    `total_qty` decimal(12,4) DEFAULT NULL COMMENT 'Total Qty',
    `email_sent` smallint(5) unsigned DEFAULT NULL COMMENT 'Email Sent',
    `send_email` smallint(5) unsigned DEFAULT NULL COMMENT 'Send Email',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `customer_id` int(11) DEFAULT NULL COMMENT 'Customer Id',
    `shipping_address_id` int(11) DEFAULT NULL COMMENT 'Shipping Address Id',
    `billing_address_id` int(11) DEFAULT NULL COMMENT 'Billing Address Id',
    `shipment_status` int(11) DEFAULT NULL COMMENT 'Shipment Status',
    `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `packages` text COMMENT 'Packed Products in Packages',
    `shipping_label` mediumblob COMMENT 'Shipping Label Content',
    `customer_note` text COMMENT 'Customer Note',
    `customer_note_notify` smallint(5) unsigned DEFAULT NULL COMMENT 'Customer Note Notify',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_SHIPMENT_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_SHIPMENT_STORE_ID` (`store_id`),
    KEY `SALES_SHIPMENT_TOTAL_QTY` (`total_qty`),
    KEY `SALES_SHIPMENT_ORDER_ID` (`order_id`),
    KEY `SALES_SHIPMENT_CREATED_AT` (`created_at`),
    KEY `SALES_SHIPMENT_UPDATED_AT` (`updated_at`),
    KEY `SALES_SHIPMENT_SEND_EMAIL` (`send_email`),
    KEY `SALES_SHIPMENT_EMAIL_SENT` (`email_sent`),
    CONSTRAINT `SALES_SHIPMENT_ORDER_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`order_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_SHIPMENT_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Shipment';
  
  DROP TABLE IF EXISTS `#__sales_shipment_comment`;
  CREATE TABLE `#__sales_shipment_comment` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `is_customer_notified` int(11) DEFAULT NULL COMMENT 'Is Customer Notified',
    `is_visible_on_front` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is Visible On Front',
    `comment` text COMMENT 'Comment',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_SHIPMENT_COMMENT_CREATED_AT` (`created_at`),
    KEY `SALES_SHIPMENT_COMMENT_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_SHIPMENT_COMMENT_PARENT_ID_SALES_SHIPMENT_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_shipment` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Shipment Comment';
  
  DROP TABLE IF EXISTS `#__sales_shipment_grid`;
  CREATE TABLE `#__sales_shipment_grid` (
    `entity_id` int(10) unsigned NOT NULL COMMENT 'Entity Id',
    `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_increment_id` varchar(32) NOT NULL COMMENT 'Order Increment Id',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `order_created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Order Increment Id',
    `customer_name` varchar(128) NOT NULL COMMENT 'Customer Name',
    `total_qty` decimal(12,4) DEFAULT NULL COMMENT 'Total Qty',
    `shipment_status` int(11) DEFAULT NULL COMMENT 'Shipment Status',
    `order_status` varchar(32) DEFAULT NULL COMMENT 'Order',
    `billing_address` varchar(255) DEFAULT NULL COMMENT 'Billing Address',
    `shipping_address` varchar(255) DEFAULT NULL COMMENT 'Shipping Address',
    `billing_name` varchar(128) DEFAULT NULL COMMENT 'Billing Name',
    `shipping_name` varchar(128) DEFAULT NULL COMMENT 'Shipping Name',
    `customer_email` varchar(128) DEFAULT NULL COMMENT 'Customer Email',
    `customer_group_id` smallint(6) DEFAULT NULL COMMENT 'Customer Group Id',
    `payment_method` varchar(32) DEFAULT NULL COMMENT 'Payment Method',
    `shipping_information` varchar(255) DEFAULT NULL COMMENT 'Shipping Method Name',
    `created_at` timestamp NULL DEFAULT NULL COMMENT 'Created At',
    `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Updated At',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_SHIPMENT_GRID_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_SHIPMENT_GRID_STORE_ID` (`store_id`),
    KEY `SALES_SHIPMENT_GRID_TOTAL_QTY` (`total_qty`),
    KEY `SALES_SHIPMENT_GRID_ORDER_INCREMENT_ID` (`order_increment_id`),
    KEY `SALES_SHIPMENT_GRID_SHIPMENT_STATUS` (`shipment_status`),
    KEY `SALES_SHIPMENT_GRID_ORDER_STATUS` (`order_status`),
    KEY `SALES_SHIPMENT_GRID_CREATED_AT` (`created_at`),
    KEY `SALES_SHIPMENT_GRID_UPDATED_AT` (`updated_at`),
    KEY `SALES_SHIPMENT_GRID_ORDER_CREATED_AT` (`order_created_at`),
    KEY `SALES_SHIPMENT_GRID_SHIPPING_NAME` (`shipping_name`),
    KEY `SALES_SHIPMENT_GRID_BILLING_NAME` (`billing_name`),
    FULLTEXT KEY `FTI_086B40C8955F167B8EA76653437879B4` (`increment_id`,`order_increment_id`,`shipping_name`,`customer_name`,`customer_email`,`billing_address`,`shipping_address`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Shipment Grid';
  
  DROP TABLE IF EXISTS `#__sales_shipment_item`;
  CREATE TABLE `#__sales_shipment_item` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `row_total` decimal(12,4) DEFAULT NULL COMMENT 'Row Total',
    `price` decimal(12,4) DEFAULT NULL COMMENT 'Price',
    `weight` decimal(12,4) DEFAULT NULL COMMENT 'Weight',
    `qty` decimal(12,4) DEFAULT NULL COMMENT 'Qty',
    `product_id` int(11) DEFAULT NULL COMMENT 'Product Id',
    `order_item_id` int(11) DEFAULT NULL COMMENT 'Order Item Id',
    `additional_data` text COMMENT 'Additional Data',
    `description` text COMMENT 'Description',
    `name` varchar(255) DEFAULT NULL COMMENT 'Name',
    `sku` varchar(255) DEFAULT NULL COMMENT 'Sku',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_SHIPMENT_ITEM_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_SHIPMENT_ITEM_PARENT_ID_SALES_SHIPMENT_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_shipment` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Shipment Item';
  
  DROP TABLE IF EXISTS `#__sales_shipment_track`;
  CREATE TABLE `#__sales_shipment_track` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `weight` decimal(12,4) DEFAULT NULL COMMENT 'Weight',
    `qty` decimal(12,4) DEFAULT NULL COMMENT 'Qty',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `track_number` text COMMENT 'Number',
    `description` text COMMENT 'Description',
    `title` varchar(255) DEFAULT NULL COMMENT 'Title',
    `carrier_code` varchar(32) DEFAULT NULL COMMENT 'Carrier Code',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_SHIPMENT_TRACK_PARENT_ID` (`parent_id`),
    KEY `SALES_SHIPMENT_TRACK_ORDER_ID` (`order_id`),
    KEY `SALES_SHIPMENT_TRACK_CREATED_AT` (`created_at`),
    CONSTRAINT `SALES_SHIPMENT_TRACK_PARENT_ID_SALES_SHIPMENT_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_shipment` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Shipment Track';
  
  DROP TABLE IF EXISTS `#__sales_shipping_aggregated`;
  CREATE TABLE `#__sales_shipping_aggregated` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) DEFAULT NULL COMMENT 'Order Status',
    `shipping_description` varchar(255) DEFAULT NULL COMMENT 'Shipping Description',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `total_shipping` decimal(12,4) DEFAULT NULL COMMENT 'Total Shipping',
    `total_shipping_actual` decimal(12,4) DEFAULT NULL COMMENT 'Total Shipping Actual',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_SHPP_AGGRED_PERIOD_STORE_ID_ORDER_STS_SHPP_DESCRIPTION` (`period`,`store_id`,`order_status`,`shipping_description`),
    KEY `SALES_SHIPPING_AGGREGATED_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_SHIPPING_AGGREGATED_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Shipping Aggregated';
  
  DROP TABLE IF EXISTS `#__sales_shipping_aggregated_order`;
  CREATE TABLE `#__sales_shipping_aggregated_order` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `order_status` varchar(50) DEFAULT NULL COMMENT 'Order Status',
    `shipping_description` varchar(255) DEFAULT NULL COMMENT 'Shipping Description',
    `orders_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Orders Count',
    `total_shipping` decimal(12,4) DEFAULT NULL COMMENT 'Total Shipping',
    `total_shipping_actual` decimal(12,4) DEFAULT NULL COMMENT 'Total Shipping Actual',
    PRIMARY KEY (`id`),
    UNIQUE KEY `UNQ_C05FAE47282EEA68654D0924E946761F` (`period`,`store_id`,`order_status`,`shipping_description`),
    KEY `SALES_SHIPPING_AGGREGATED_ORDER_STORE_ID` (`store_id`),
    CONSTRAINT `SALES_SHIPPING_AGGREGATED_ORDER_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Shipping Aggregated Order';
  
  DROP TABLE IF EXISTS `#__sales_creditmemo`;
  CREATE TABLE `#__sales_creditmemo` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `adjustment_positive` decimal(12,4) DEFAULT NULL COMMENT 'Adjustment Positive',
    `base_shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Tax Amount',
    `store_to_order_rate` decimal(12,4) DEFAULT NULL COMMENT 'Store To Order Rate',
    `base_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Amount',
    `base_to_order_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Order Rate',
    `grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Grand Total',
    `base_adjustment_negative` decimal(12,4) DEFAULT NULL COMMENT 'Base Adjustment Negative',
    `base_subtotal_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal Incl Tax',
    `shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Amount',
    `subtotal_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal Incl Tax',
    `adjustment_negative` decimal(12,4) DEFAULT NULL COMMENT 'Adjustment Negative',
    `base_shipping_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Amount',
    `store_to_base_rate` decimal(12,4) DEFAULT NULL COMMENT 'Store To Base Rate',
    `base_to_global_rate` decimal(12,4) DEFAULT NULL COMMENT 'Base To Global Rate',
    `base_adjustment` decimal(12,4) DEFAULT NULL COMMENT 'Base Adjustment',
    `base_subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Base Subtotal',
    `discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Amount',
    `subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal',
    `adjustment` decimal(12,4) DEFAULT NULL COMMENT 'Adjustment',
    `base_grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Base Grand Total',
    `base_adjustment_positive` decimal(12,4) DEFAULT NULL COMMENT 'Base Adjustment Positive',
    `base_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Amount',
    `shipping_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Tax Amount',
    `tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Tax Amount',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `email_sent` smallint(5) unsigned DEFAULT NULL COMMENT 'Email Sent',
    `send_email` smallint(5) unsigned DEFAULT NULL COMMENT 'Send Email',
    `creditmemo_status` int(11) DEFAULT NULL COMMENT 'Creditmemo Status',
    `state` int(11) DEFAULT NULL COMMENT 'State',
    `shipping_address_id` int(11) DEFAULT NULL COMMENT 'Shipping Address Id',
    `billing_address_id` int(11) DEFAULT NULL COMMENT 'Billing Address Id',
    `invoice_id` int(11) DEFAULT NULL COMMENT 'Invoice Id',
    `store_currency_code` varchar(3) DEFAULT NULL COMMENT 'Store Currency Code',
    `order_currency_code` varchar(3) DEFAULT NULL COMMENT 'Order Currency Code',
    `base_currency_code` varchar(3) DEFAULT NULL COMMENT 'Base Currency Code',
    `global_currency_code` varchar(3) DEFAULT NULL COMMENT 'Global Currency Code',
    `transaction_id` varchar(255) DEFAULT NULL COMMENT 'Transaction Id',
    `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `shipping_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Discount Tax Compensation Amount',
    `base_shipping_discount_tax_compensation_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Discount Tax Compensation Amount',
    `shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Shipping Incl Tax',
    `base_shipping_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Shipping Incl Tax',
    `discount_description` varchar(255) DEFAULT NULL COMMENT 'Discount Description',
    `customer_note` text COMMENT 'Customer Note',
    `customer_note_notify` smallint(5) unsigned DEFAULT NULL COMMENT 'Customer Note Notify',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_CREDITMEMO_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_CREDITMEMO_STORE_ID` (`store_id`),
    KEY `SALES_CREDITMEMO_ORDER_ID` (`order_id`),
    KEY `SALES_CREDITMEMO_CREDITMEMO_STATUS` (`creditmemo_status`),
    KEY `SALES_CREDITMEMO_STATE` (`state`),
    KEY `SALES_CREDITMEMO_CREATED_AT` (`created_at`),
    KEY `SALES_CREDITMEMO_UPDATED_AT` (`updated_at`),
    KEY `SALES_CREDITMEMO_SEND_EMAIL` (`send_email`),
    KEY `SALES_CREDITMEMO_EMAIL_SENT` (`email_sent`),
    CONSTRAINT `SALES_CREDITMEMO_ORDER_ID_SALES_ORDER_ENTITY_ID` FOREIGN KEY (`order_id`) REFERENCES `#__sales_order` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_CREDITMEMO_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE SET NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Creditmemo';
  
  DROP TABLE IF EXISTS `#__sales_creditmemo_comment`;
  CREATE TABLE `#__sales_creditmemo_comment` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `is_customer_notified` int(11) DEFAULT NULL COMMENT 'Is Customer Notified',
    `is_visible_on_front` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is Visible On Front',
    `comment` text COMMENT 'Comment',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_CREDITMEMO_COMMENT_CREATED_AT` (`created_at`),
    KEY `SALES_CREDITMEMO_COMMENT_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_CREDITMEMO_COMMENT_PARENT_ID_SALES_CREDITMEMO_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_creditmemo` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Creditmemo Comment';
  
  DROP TABLE IF EXISTS `#__sales_creditmemo_grid`;
  CREATE TABLE `#__sales_creditmemo_grid` (
    `entity_id` int(10) unsigned NOT NULL COMMENT 'Entity Id',
    `increment_id` varchar(50) DEFAULT NULL COMMENT 'Increment Id',
    `created_at` timestamp NULL DEFAULT NULL COMMENT 'Created At',
    `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Updated At',
    `order_id` int(10) unsigned NOT NULL COMMENT 'Order Id',
    `order_increment_id` varchar(50) DEFAULT NULL COMMENT 'Order Increment Id',
    `order_created_at` timestamp NULL DEFAULT NULL COMMENT 'Order Created At',
    `billing_name` varchar(255) DEFAULT NULL COMMENT 'Billing Name',
    `state` int(11) DEFAULT NULL COMMENT 'Status',
    `base_grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Base Grand Total',
    `order_status` varchar(32) DEFAULT NULL COMMENT 'Order Status',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `billing_address` varchar(255) DEFAULT NULL COMMENT 'Billing Address',
    `shipping_address` varchar(255) DEFAULT NULL COMMENT 'Shipping Address',
    `customer_name` varchar(128) NOT NULL COMMENT 'Customer Name',
    `customer_email` varchar(128) DEFAULT NULL COMMENT 'Customer Email',
    `customer_group_id` smallint(6) DEFAULT NULL COMMENT 'Customer Group Id',
    `payment_method` varchar(32) DEFAULT NULL COMMENT 'Payment Method',
    `shipping_information` varchar(255) DEFAULT NULL COMMENT 'Shipping Method Name',
    `subtotal` decimal(12,4) DEFAULT NULL COMMENT 'Subtotal',
    `shipping_and_handling` decimal(12,4) DEFAULT NULL COMMENT 'Shipping and handling amount',
    `adjustment_positive` decimal(12,4) DEFAULT NULL COMMENT 'Adjustment Positive',
    `adjustment_negative` decimal(12,4) DEFAULT NULL COMMENT 'Adjustment Negative',
    `order_base_grand_total` decimal(12,4) DEFAULT NULL COMMENT 'Order Grand Total',
    PRIMARY KEY (`entity_id`),
    UNIQUE KEY `SALES_CREDITMEMO_GRID_INCREMENT_ID_STORE_ID` (`increment_id`,`store_id`),
    KEY `SALES_CREDITMEMO_GRID_ORDER_INCREMENT_ID` (`order_increment_id`),
    KEY `SALES_CREDITMEMO_GRID_CREATED_AT` (`created_at`),
    KEY `SALES_CREDITMEMO_GRID_UPDATED_AT` (`updated_at`),
    KEY `SALES_CREDITMEMO_GRID_ORDER_CREATED_AT` (`order_created_at`),
    KEY `SALES_CREDITMEMO_GRID_STATE` (`state`),
    KEY `SALES_CREDITMEMO_GRID_BILLING_NAME` (`billing_name`),
    KEY `SALES_CREDITMEMO_GRID_ORDER_STATUS` (`order_status`),
    KEY `SALES_CREDITMEMO_GRID_BASE_GRAND_TOTAL` (`base_grand_total`),
    KEY `SALES_CREDITMEMO_GRID_STORE_ID` (`store_id`),
    KEY `SALES_CREDITMEMO_GRID_ORDER_BASE_GRAND_TOTAL` (`order_base_grand_total`),
    KEY `SALES_CREDITMEMO_GRID_ORDER_ID` (`order_id`),
    FULLTEXT KEY `FTI_32B7BA885941A8254EE84AE650ABDC86` (`increment_id`,`order_increment_id`,`billing_name`,`billing_address`,`shipping_address`,`customer_name`,`customer_email`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Creditmemo Grid';
  
  DROP TABLE IF EXISTS `#__sales_creditmemo_item`;
  CREATE TABLE `#__sales_creditmemo_item` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
    `parent_id` int(10) unsigned NOT NULL COMMENT 'Parent Id',
    `base_price` decimal(12,4) DEFAULT NULL COMMENT 'Base Price',
    `tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Tax Amount',
    `base_row_total` decimal(12,4) DEFAULT NULL COMMENT 'Base Row Total',
    `discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Amount',
    `row_total` decimal(12,4) DEFAULT NULL COMMENT 'Row Total',
    `base_discount_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Amount',
    `price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Price Incl Tax',
    `base_tax_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Tax Amount',
    `base_price_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Price Incl Tax',
    `qty` decimal(12,4) DEFAULT NULL COMMENT 'Qty',
    `base_cost` decimal(12,4) DEFAULT NULL COMMENT 'Base Cost',
    `price` decimal(12,4) DEFAULT NULL COMMENT 'Price',
    `base_row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Base Row Total Incl Tax',
    `row_total_incl_tax` decimal(12,4) DEFAULT NULL COMMENT 'Row Total Incl Tax',
    `product_id` int(11) DEFAULT NULL COMMENT 'Product Id',
    `order_item_id` int(11) DEFAULT NULL COMMENT 'Order Item Id',
    `additional_data` text COMMENT 'Additional Data',
    `description` text COMMENT 'Description',
    `sku` varchar(255) DEFAULT NULL COMMENT 'Sku',
    `name` varchar(255) DEFAULT NULL COMMENT 'Name',
    `discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Discount Tax Compensation Amount',
    `base_discount_tax_compensation_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Discount Tax Compensation Amount',
    `tax_ratio` text COMMENT 'Ratio of tax in the creditmemo item over tax of the order item',
    `weee_tax_applied` text COMMENT 'Weee Tax Applied',
    `weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Amount',
    `weee_tax_applied_row_amount` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Applied Row Amount',
    `weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Disposition',
    `weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Weee Tax Row Disposition',
    `base_weee_tax_applied_amount` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Amount',
    `base_weee_tax_applied_row_amnt` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Applied Row Amnt',
    `base_weee_tax_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Disposition',
    `base_weee_tax_row_disposition` decimal(12,4) DEFAULT NULL COMMENT 'Base Weee Tax Row Disposition',
    PRIMARY KEY (`entity_id`),
    KEY `SALES_CREDITMEMO_ITEM_PARENT_ID` (`parent_id`),
    CONSTRAINT `SALES_CREDITMEMO_ITEM_PARENT_ID_SALES_CREDITMEMO_ENTITY_ID` FOREIGN KEY (`parent_id`) REFERENCES `#__sales_creditmemo` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Flat Creditmemo Item';
  
  DROP TABLE IF EXISTS `#__sales_bestsellers_aggregated_daily`;
  CREATE TABLE `#__sales_bestsellers_aggregated_daily` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `product_id` int(10) unsigned DEFAULT NULL COMMENT 'Product Id',
    `product_name` varchar(255) DEFAULT NULL COMMENT 'Product Name',
    `product_price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Product Price',
    `qty_ordered` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Qty Ordered',
    `rating_pos` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Rating Pos',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_BESTSELLERS_AGGREGATED_DAILY_PERIOD_STORE_ID_PRODUCT_ID` (`period`,`store_id`,`product_id`),
    KEY `SALES_BESTSELLERS_AGGREGATED_DAILY_STORE_ID` (`store_id`),
    KEY `SALES_BESTSELLERS_AGGREGATED_DAILY_PRODUCT_ID` (`product_id`),
    CONSTRAINT `SALES_BESTSELLERS_AGGRED_DAILY_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `#__catalog_product_entity` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_BESTSELLERS_AGGREGATED_DAILY_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Bestsellers Aggregated Daily';
  
  DROP TABLE IF EXISTS `#__sales_bestsellers_aggregated_monthly`;
  CREATE TABLE `#__sales_bestsellers_aggregated_monthly` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `product_id` int(10) unsigned DEFAULT NULL COMMENT 'Product Id',
    `product_name` varchar(255) DEFAULT NULL COMMENT 'Product Name',
    `product_price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Product Price',
    `qty_ordered` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Qty Ordered',
    `rating_pos` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Rating Pos',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_BESTSELLERS_AGGREGATED_MONTHLY_PERIOD_STORE_ID_PRODUCT_ID` (`period`,`store_id`,`product_id`),
    KEY `SALES_BESTSELLERS_AGGREGATED_MONTHLY_STORE_ID` (`store_id`),
    KEY `SALES_BESTSELLERS_AGGREGATED_MONTHLY_PRODUCT_ID` (`product_id`),
    CONSTRAINT `SALES_BESTSELLERS_AGGRED_MONTHLY_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `#__catalog_product_entity` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_BESTSELLERS_AGGREGATED_MONTHLY_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Bestsellers Aggregated Monthly';
  
  DROP TABLE IF EXISTS `#__sales_bestsellers_aggregated_yearly`;
  CREATE TABLE `#__sales_bestsellers_aggregated_yearly` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `period` date DEFAULT NULL COMMENT 'Period',
    `store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
    `product_id` int(10) unsigned DEFAULT NULL COMMENT 'Product Id',
    `product_name` varchar(255) DEFAULT NULL COMMENT 'Product Name',
    `product_price` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Product Price',
    `qty_ordered` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Qty Ordered',
    `rating_pos` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Rating Pos',
    PRIMARY KEY (`id`),
    UNIQUE KEY `SALES_BESTSELLERS_AGGREGATED_YEARLY_PERIOD_STORE_ID_PRODUCT_ID` (`period`,`store_id`,`product_id`),
    KEY `SALES_BESTSELLERS_AGGREGATED_YEARLY_STORE_ID` (`store_id`),
    KEY `SALES_BESTSELLERS_AGGREGATED_YEARLY_PRODUCT_ID` (`product_id`),
    CONSTRAINT `SALES_BESTSELLERS_AGGRED_YEARLY_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `#__catalog_product_entity` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALES_BESTSELLERS_AGGREGATED_YEARLY_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Bestsellers Aggregated Yearly';
  
  DROP TABLE IF EXISTS `#__salesrule`;
  CREATE TABLE `#__salesrule` (
    `rule_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Rule Id',
    `name` varchar(255) DEFAULT NULL COMMENT 'Name',
    `description` text COMMENT 'Description',
    `from_date` date DEFAULT NULL COMMENT 'From',
    `to_date` date DEFAULT NULL COMMENT 'To',
    `uses_per_customer` int(11) NOT NULL DEFAULT '0' COMMENT 'Uses Per Customer',
    `is_active` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Is Active',
    `conditions_serialized` mediumtext COMMENT 'Conditions Serialized',
    `actions_serialized` mediumtext COMMENT 'Actions Serialized',
    `stop_rules_processing` smallint(6) NOT NULL DEFAULT '1' COMMENT 'Stop Rules Processing',
    `is_advanced` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Is Advanced',
    `product_ids` text COMMENT 'Product Ids',
    `sort_order` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Sort Order',
    `simple_action` varchar(32) DEFAULT NULL COMMENT 'Simple Action',
    `discount_amount` decimal(12,4) NOT NULL DEFAULT '0.0000' COMMENT 'Discount Amount',
    `discount_qty` decimal(12,4) DEFAULT NULL COMMENT 'Discount Qty',
    `discount_step` int(10) unsigned NOT NULL COMMENT 'Discount Step',
    `apply_to_shipping` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Apply To Shipping',
    `times_used` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Times Used',
    `is_rss` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Is Rss',
    `coupon_type` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Coupon Type',
    `use_auto_generation` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Use Auto Generation',
    `uses_per_coupon` int(11) NOT NULL DEFAULT '0' COMMENT 'User Per Coupon',
    `simple_free_shipping` smallint(6) DEFAULT NULL,
    PRIMARY KEY (`rule_id`),
    KEY `SALESRULE_IS_ACTIVE_SORT_ORDER_TO_DATE_FROM_DATE` (`is_active`,`sort_order`,`to_date`,`from_date`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Salesrule';
  
  DROP TABLE IF EXISTS `#__salesrule_coupon`;
  CREATE TABLE `#__salesrule_coupon` (
    `coupon_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Coupon Id',
    `rule_id` int(10) unsigned NOT NULL COMMENT 'Rule Id',
    `code` varchar(255) DEFAULT NULL COMMENT 'Code',
    `usage_limit` int(10) unsigned DEFAULT NULL COMMENT 'Usage Limit',
    `usage_per_customer` int(10) unsigned DEFAULT NULL COMMENT 'Usage Per Customer',
    `times_used` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Times Used',
    `expiration_date` timestamp NULL DEFAULT NULL COMMENT 'Expiration Date',
    `is_primary` smallint(5) unsigned DEFAULT NULL COMMENT 'Is Primary',
    `created_at` timestamp NULL DEFAULT NULL COMMENT 'Coupon Code Creation Date',
    `type` smallint(6) DEFAULT '0' COMMENT 'Coupon Code Type',
    PRIMARY KEY (`coupon_id`),
    UNIQUE KEY `SALESRULE_COUPON_CODE` (`code`),
    UNIQUE KEY `SALESRULE_COUPON_RULE_ID_IS_PRIMARY` (`rule_id`,`is_primary`),
    KEY `SALESRULE_COUPON_RULE_ID` (`rule_id`),
    CONSTRAINT `SALESRULE_COUPON_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `#__salesrule` (`rule_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Salesrule Coupon';
  
  DROP TABLE IF EXISTS `#__salesrule_coupon_usage`;
  CREATE TABLE `#__salesrule_coupon_usage` (
    `coupon_id` int(10) unsigned NOT NULL COMMENT 'Coupon Id',
    `customer_id` int(10) unsigned NOT NULL COMMENT 'Customer Id',
    `times_used` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Times Used',
    PRIMARY KEY (`coupon_id`,`customer_id`),
    KEY `SALESRULE_COUPON_USAGE_CUSTOMER_ID` (`customer_id`),
    CONSTRAINT `SALESRULE_COUPON_USAGE_COUPON_ID_SALESRULE_COUPON_COUPON_ID` FOREIGN KEY (`coupon_id`) REFERENCES `#__salesrule_coupon` (`coupon_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_COUPON_USAGE_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `#__customer_entity` (`entity_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Salesrule Coupon Usage';
  
  DROP TABLE IF EXISTS `#__salesrule_customer`;
  CREATE TABLE `#__salesrule_customer` (
    `rule_customer_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Rule Customer Id',
    `rule_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Rule Id',
    `customer_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Customer Id',
    `times_used` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Times Used',
    PRIMARY KEY (`rule_customer_id`),
    KEY `SALESRULE_CUSTOMER_RULE_ID_CUSTOMER_ID` (`rule_id`,`customer_id`),
    KEY `SALESRULE_CUSTOMER_CUSTOMER_ID_RULE_ID` (`customer_id`,`rule_id`),
    CONSTRAINT `SALESRULE_CUSTOMER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `#__customer_entity` (`entity_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `#__salesrule` (`rule_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Salesrule Customer';
  
  DROP TABLE IF EXISTS `#__salesrule_customer_group`;
  CREATE TABLE `#__salesrule_customer_group` (
    `rule_id` int(10) unsigned NOT NULL COMMENT 'Rule Id',
    `customer_group_id` smallint(5) unsigned NOT NULL COMMENT 'Customer Group Id',
    PRIMARY KEY (`rule_id`,`customer_group_id`),
    KEY `SALESRULE_CUSTOMER_GROUP_CUSTOMER_GROUP_ID` (`customer_group_id`),
    CONSTRAINT `SALESRULE_CSTR_GROUP_CSTR_GROUP_ID_CSTR_GROUP_CSTR_GROUP_ID` FOREIGN KEY (`customer_group_id`) REFERENCES `#__customer_group` (`customer_group_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_CUSTOMER_GROUP_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `#__salesrule` (`rule_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Rules To Customer Groups Relations';
  
  DROP TABLE IF EXISTS `#__salesrule_label`;
  CREATE TABLE `#__salesrule_label` (
    `label_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Label Id',
    `rule_id` int(10) unsigned NOT NULL COMMENT 'Rule Id',
    `store_id` smallint(5) unsigned NOT NULL COMMENT 'Store Id',
    `label` varchar(255) DEFAULT NULL COMMENT 'Label',
    PRIMARY KEY (`label_id`),
    UNIQUE KEY `SALESRULE_LABEL_RULE_ID_STORE_ID` (`rule_id`,`store_id`),
    KEY `SALESRULE_LABEL_STORE_ID` (`store_id`),
    CONSTRAINT `SALESRULE_LABEL_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `#__salesrule` (`rule_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_LABEL_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `#__store` (`store_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Salesrule Label';
  
  DROP TABLE IF EXISTS `#__salesrule_product_attribute`;
  CREATE TABLE `#__salesrule_product_attribute` (
    `rule_id` int(10) unsigned NOT NULL COMMENT 'Rule Id',
    `website_id` smallint(5) unsigned NOT NULL COMMENT 'Website Id',
    `customer_group_id` smallint(5) unsigned NOT NULL COMMENT 'Customer Group Id',
    `attribute_id` smallint(5) unsigned NOT NULL COMMENT 'Attribute Id',
    PRIMARY KEY (`rule_id`,`website_id`,`customer_group_id`,`attribute_id`),
    KEY `SALESRULE_PRODUCT_ATTRIBUTE_WEBSITE_ID` (`website_id`),
    KEY `SALESRULE_PRODUCT_ATTRIBUTE_CUSTOMER_GROUP_ID` (`customer_group_id`),
    KEY `SALESRULE_PRODUCT_ATTRIBUTE_ATTRIBUTE_ID` (`attribute_id`),
    CONSTRAINT `SALESRULE_PRD_ATTR_ATTR_ID_EAV_ATTR_ATTR_ID` FOREIGN KEY (`attribute_id`) REFERENCES `#__eav_attribute` (`attribute_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_PRD_ATTR_CSTR_GROUP_ID_CSTR_GROUP_CSTR_GROUP_ID` FOREIGN KEY (`customer_group_id`) REFERENCES `#__customer_group` (`customer_group_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_PRODUCT_ATTRIBUTE_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `#__salesrule` (`rule_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_PRODUCT_ATTRIBUTE_WEBSITE_ID_STORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `#__store_website` (`website_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Salesrule Product Attribute';
  
  DROP TABLE IF EXISTS `#__salesrule_website`;
  CREATE TABLE `#__salesrule_website` (
    `rule_id` int(10) unsigned NOT NULL COMMENT 'Rule Id',
    `website_id` smallint(5) unsigned NOT NULL COMMENT 'Website Id',
    PRIMARY KEY (`rule_id`,`website_id`),
    KEY `SALESRULE_WEBSITE_WEBSITE_ID` (`website_id`),
    CONSTRAINT `SALESRULE_WEBSITE_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `#__salesrule` (`rule_id`) ON DELETE CASCADE,
    CONSTRAINT `SALESRULE_WEBSITE_WEBSITE_ID_STORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `#__store_website` (`website_id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Sales Rules To Websites Relations';
  
  SET FOREIGN_KEY_CHECKS=1;