<?php

namespace External\MSSQLBundle\Resources\upgrade;

class MoneyUpgrade extends \UpgradeNew
{
    public function check_MoneyOrders()
    {
        return $this->checkTableExists('money_orders');
    }

    /** Add table money_orders */
    public function upgrade_MoneyOrders()
    {
        sqlQuery('
            CREATE TABLE IF NOT EXISTS `money_orders` (
              `id_money` varchar(100) NOT NULL,
              `id_order` int(10) UNSIGNED NOT NULL,
              `status` int(11) NOT NULL DEFAULT 0,
              UNIQUE KEY `money_mapping_money_id_uindex` (`id_money`),
              CONSTRAINT FKMoney_id_order FOREIGN KEY (id_order) REFERENCES  orders (id) ON DELETE CASCADE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'MoneyS5 orders mapping\';
        ');

        $this->upgradeOK();
    }

    public function check_MoneySections()
    {
        return $this->checkTableExists('money_sections');
    }

    /** Add table money_sections */
    public function upgrade_MoneySections()
    {
        sqlQuery('CREATE TABLE IF NOT EXISTS `money_sections` (
              `id_money` varchar(100) NOT NULL,
              `id_money_parent` varchar(100) DEFAULT NULL,
              `id_section` int(11) NOT NULL,
              UNIQUE KEY `money_sections_money_id_uindex` (`id_money`),
              CONSTRAINT FKMoney_id_section FOREIGN KEY (id_section) REFERENCES  sections (id) ON DELETE CASCADE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'MoneyS5 sections mapping\';');

        $this->upgradeOK();
    }

    public function check_MoneyProducts()
    {
        return $this->checkTableExists('money_products');
    }

    /** Add table money_products */
    public function upgrade_MoneyProducts()
    {
        sqlQuery('CREATE TABLE IF NOT EXISTS `money_products` (
              `id_money` varchar(100) NOT NULL,
              `id_product` int(11) NOT NULL,
              UNIQUE KEY `money_products_money_id_uindex` (`id_money`),
              CONSTRAINT FKMoney_money_products_id_product FOREIGN KEY (id_product) REFERENCES  products (id) ON DELETE CASCADE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'MoneyS5 products mapping\';');

        $this->upgradeOK();
    }

    public function check_MoneyVariations()
    {
        return $this->checkTableExists('money_variations');
    }

    /** Add table money_variations */
    public function upgrade_MoneyVariations()
    {
        sqlQuery('CREATE TABLE IF NOT EXISTS `money_variations` (
              `id_money` varchar(100) NOT NULL,
              `id_variation` int(11) NOT NULL,
              UNIQUE KEY `money_variations_money_id_uindex` (`id_money`),
              CONSTRAINT FKMoney_id_variation FOREIGN KEY (id_variation) REFERENCES  products_variations (id) ON DELETE CASCADE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'MoneyS5 variations mapping\';');

        $this->upgradeOK();
    }

    public function check_MoneyUsers()
    {
        return $this->checkTableExists('money_users');
    }

    /** Add table money_users */
    public function upgrade_MoneyUsers()
    {
        sqlQuery('CREATE TABLE IF NOT EXISTS `money_users` (
              `id_money` varchar(100) NOT NULL,
              `id_user` int(11) unsigned NOT NULL,
              UNIQUE KEY `money_users_money_id_uindex` (`id_money`),
              CONSTRAINT FKMoney_id_user FOREIGN KEY (id_user) REFERENCES  users (id) ON DELETE CASCADE
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'MoneyS5 users mapping\';');

        $this->upgradeOK();
    }
}
