<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210118080016 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
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('CREATE TABLE lot_user (lot_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_19BF4809A8CBA5F7 (lot_id), INDEX IDX_19BF4809A76ED395 (user_id), PRIMARY KEY(lot_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE programme_user_consult (programme_id INT NOT NULL, user_consult_id INT NOT NULL, INDEX IDX_3B5296662BB7AEE (programme_id), INDEX IDX_3B529669F760A74 (user_consult_id), PRIMARY KEY(programme_id, user_consult_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE lot_user ADD CONSTRAINT FK_19BF4809A8CBA5F7 FOREIGN KEY (lot_id) REFERENCES lot (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE lot_user ADD CONSTRAINT FK_19BF4809A76ED395 FOREIGN KEY (user_id) REFERENCES app_users (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE programme_user_consult ADD CONSTRAINT FK_3B5296662BB7AEE FOREIGN KEY (programme_id) REFERENCES programme (id)');
$this->addSql('ALTER TABLE programme_user_consult ADD CONSTRAINT FK_3B529669F760A74 FOREIGN KEY (user_consult_id) REFERENCES app_users (id)');
$this->addSql('ALTER TABLE app_users ADD type VARCHAR(250) DEFAULT \'Particulier\' NOT NULL, ADD company_name VARCHAR(250) NOT NULL, ADD civility VARCHAR(250) NOT NULL');
$this->addSql('INSERT INTO `lot_user`(`lot_id`, `user_id`) SELECT id, aquereur_id FROM lot WHERE aquereur_id IS NOT NULL');
$this->addSql('INSERT INTO `lot_user`(`lot_id`, `user_id`) SELECT id, aquereur_secondaire_id FROM lot WHERE aquereur_secondaire_id IS NOT NULL');
$this->addSql('ALTER TABLE lot DROP FOREIGN KEY FK_916087CE40C1DE50');
$this->addSql('ALTER TABLE lot DROP FOREIGN KEY FK_916087CE7268FEC8');
$this->addSql('ALTER TABLE lot DROP FOREIGN KEY FK_916087CE8BA37A96');
$this->addSql('ALTER TABLE lot DROP FOREIGN KEY FK_916087CE916738B7');
$this->addSql('DROP INDEX IDX_B81291B8BA37A96 ON lot');
$this->addSql('DROP INDEX IDX_B81291B7268FEC8 ON lot');
$this->addSql('DROP INDEX IDX_B81291B40C1DE50 ON lot');
$this->addSql('DROP INDEX IDX_B81291B916738B7 ON lot');
$this->addSql('ALTER TABLE lot DROP aquereur_id, DROP aquereur_secondaire_id, DROP contact_first_id, DROP contact_second_id, DROP typeaquereur');
}
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('ALTER TABLE lot ADD aquereur_id INT NOT NULL, ADD aquereur_secondaire_id INT DEFAULT NULL, ADD contact_first_id INT NOT NULL, ADD contact_second_id INT DEFAULT NULL, ADD typeaquereur VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
$this->addSql('ALTER TABLE lot ADD CONSTRAINT FK_916087CE40C1DE50 FOREIGN KEY (aquereur_secondaire_id) REFERENCES app_users (id)');
$this->addSql('ALTER TABLE lot ADD CONSTRAINT FK_916087CE7268FEC8 FOREIGN KEY (contact_first_id) REFERENCES app_users (id)');
$this->addSql('ALTER TABLE lot ADD CONSTRAINT FK_916087CE8BA37A96 FOREIGN KEY (aquereur_id) REFERENCES app_users (id)');
$this->addSql('ALTER TABLE lot ADD CONSTRAINT FK_916087CE916738B7 FOREIGN KEY (contact_second_id) REFERENCES app_users (id)');
$this->addSql('CREATE INDEX IDX_B81291B8BA37A96 ON lot (aquereur_id)');
$this->addSql('CREATE INDEX IDX_B81291B7268FEC8 ON lot (contact_first_id)');
$this->addSql('CREATE INDEX IDX_B81291B40C1DE50 ON lot (aquereur_secondaire_id)');
$this->addSql('CREATE INDEX IDX_B81291B916738B7 ON lot (contact_second_id)');
$this->addSql('DROP TABLE lot_user');
$this->addSql('DROP TABLE programme_user_consult');
$this->addSql('DROP INDEX UNIQ_C25028248CDE5729 ON app_users');
$this->addSql('DROP INDEX UNIQ_C25028241D4E64E8 ON app_users');
$this->addSql('DROP INDEX UNIQ_C2502824384D4799 ON app_users');
$this->addSql('ALTER TABLE app_users DROP type, DROP company_name, DROP civility');
$this->addSql('ALTER TABLE lot ADD typeaquereur VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
}
}