<?php

namespace KupShop\OrderRestrictionsBundle\Resources\upgrade;

class OrderRestrictionsUpgrade extends \UpgradeNew
{
    public function check_OrderRestrictionsTable()
    {
        return $this->checkTableExists('order_restrictions');
    }

    /** Create order restrictions table */
    public function upgrade_OrderRestrictionsTable()
    {
        sqlQuery('CREATE TABLE order_restrictions (
                  id INT AUTO_INCREMENT PRIMARY KEY,
                  date_created DATETIME,
                  email VARCHAR(255) DEFAULT NULL,
                  ip VARCHAR(255) DEFAULT NULL,
                  description VARCHAR(255) DEFAULT "",
                  UNIQUE (email),
                  UNIQUE (ip)
                );
        ');

        $this->upgradeOK();
    }

    public function check_orderRestrictionsDateCreatedDefault()
    {
        return $this->checkColumnDefault('order_restrictions', 'date_created', 'current_timestamp()');
    }

    /** Set order_restrictions.date_created default to current_timestamp */
    public function upgrade_orderRestrictionsDateCreatedDefault()
    {
        sqlQuery('ALTER TABLE `order_restrictions` MODIFY COLUMN `date_created` DATETIME DEFAULT NOW()');

        $this->upgradeOK();
    }
}
