<?php

namespace External\VarioBundle\Resources\upgrade;

class UsersUpgrade extends \UpgradeNew
{
    public function check_idVario()
    {
        return $this->checkColumnExists('users', 'id_vario');
    }

    /** add column 'id_vario' into 'users' table */
    public function upgrade_idVario()
    {
        sqlQuery('ALTER TABLE users ADD COLUMN id_vario VARCHAR(150) DEFAULT NULL');

        $this->upgradeOK();
    }

    public function check_VarioIdentifier()
    {
        return $this->checkColumnExists('users', 'vario_identifier');
    }

    /** add column 'vario_identifier' into 'users' table */
    public function upgrade_VarioIdentifier()
    {
        sqlQuery('ALTER TABLE users ADD COLUMN vario_identifier VARCHAR(150) DEFAULT NULL');

        $this->upgradeOK();
    }

    public function check_VarioUsers(): bool
    {
        return $this->checkTableExists('vario_users');
    }

    /** Add vario_users table */
    public function upgrade_VarioUsers(): void
    {
        sqlQuery('CREATE TABLE vario_users (
                  id_vario VARCHAR(100) PRIMARY KEY,
                  id_user INT(11) UNSIGNED NOT NULL,
                  identifier VARCHAR(50) NOT NULL,
                  FOREIGN KEY (id_user) REFERENCES users (id)
                  ON DELETE CASCADE ON UPDATE CASCADE
                );');

        $this->upgradeOK();
    }
}
