<?php declare(strict_types = 1);
namespace DoctrineMigrations;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180502075306 extends AbstractMigration
{
public function preUp(Schema $schema) : void
{
// Remove some duplicated accounts in the tallo2 database
$this->addSql('UPDATE users SET email="invalid1@talloverde.com", is_active=0 WHERE id=4117');
$this->addSql('UPDATE users SET email="invalid2@talloverde.com", is_active=0 WHERE id=25958');
$this->addSql('UPDATE users SET email="invalid3@talloverde.com", is_active=0 WHERE id=23507');
$this->addSql('UPDATE users SET email="invalid4@talloverde.com", is_active=0 WHERE id=4526');
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP INDEX UNIQ_1483A5E9F85E0677 ON users');
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E9E7927C74 ON users (email)');
$this->addSql('ALTER TABLE users CHANGE username username VARCHAR(100) DEFAULT NULL');
// roles
$this->addSql('ALTER TABLE user_role DROP FOREIGN KEY FK_2DE8C6A3D60322AC');
$this->addSql('DROP TABLE role');
$this->addSql('DROP TABLE user_role');
$this->addSql('ALTER TABLE users ADD roles VARCHAR(255) NOT NULL DEFAULT \'ROLE_USER\'');
// drop unneeded clients data
$this->addSql('ALTER TABLE clients DROP FOREIGN KEY FK_C82E7420A4B75B');
$this->addSql('DROP INDEX IDX_C82E7420A4B75B ON clients');
$this->addSql('ALTER TABLE clients DROP phoneNumber, DROP birthdayDate, DROP birthdayMonth, DROP howYouKnowAboutUs, DROP documentNumber, DROP idReferral');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP INDEX UNIQ_1483A5E9E7927C74 ON users');
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E9F85E0677 ON users (username)');
$this->addSql('ALTER TABLE users CHANGE username username VARCHAR(100) NOT NULL COLLATE utf8_unicode_ci');
// roles
$this->addSql('CREATE TABLE role (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(30) NOT NULL COLLATE utf8_unicode_ci, role VARCHAR(20) NOT NULL COLLATE utf8_unicode_ci, UNIQUE INDEX UNIQ_57698A6A57698A6A (role), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_role (user_id INT NOT NULL, role_id INT NOT NULL, INDEX IDX_2DE8C6A3A76ED395 (user_id), INDEX IDX_2DE8C6A3D60322AC (role_id), PRIMARY KEY(user_id, role_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE user_role ADD CONSTRAINT FK_2DE8C6A3A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE user_role ADD CONSTRAINT FK_2DE8C6A3D60322AC FOREIGN KEY (role_id) REFERENCES role (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE users DROP roles');
// unneeded client data
$this->addSql('ALTER TABLE clients ADD phoneNumber VARCHAR(100) DEFAULT NULL COLLATE utf8_unicode_ci, ADD birthdayDate INT DEFAULT NULL, ADD birthdayMonth INT DEFAULT NULL, ADD howYouKnowAboutUs VARCHAR(100) DEFAULT NULL COLLATE utf8_unicode_ci, ADD documentNumber VARCHAR(20) DEFAULT NULL COLLATE utf8_unicode_ci, ADD idReferral INT DEFAULT NULL');
$this->addSql('ALTER TABLE clients ADD CONSTRAINT FK_C82E7420A4B75B FOREIGN KEY (idReferral) REFERENCES clients (id)');
$this->addSql('CREATE INDEX IDX_C82E7420A4B75B ON clients (idReferral)');
}
}