<?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 Version20240523065841 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->addSql('CREATE TABLE discount (id INT AUTO_INCREMENT NOT NULL,discount_code VARCHAR(255) DEFAULT NULL,percentage INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE discount_entrada (discount_id INT NOT NULL, entrada_id INT NOT NULL, INDEX IDX_7F41CF654C7C611F (discount_id), INDEX IDX_7F41CF65A688222A (entrada_id), PRIMARY KEY(discount_id, entrada_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE discount_entrada ADD CONSTRAINT FK_7F41CF654C7C611F FOREIGN KEY (discount_id) REFERENCES discount (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE discount_entrada ADD CONSTRAINT FK_7F41CF65A688222A FOREIGN KEY (entrada_id) REFERENCES entrada (id) ON DELETE CASCADE');
$this->addSql('DROP TABLE migration_versions');
$this->addSql('ALTER TABLE ticket ADD discount_id INT DEFAULT NULL, ADD price DOUBLE PRECISION NOT NULL');
$this->addSql('ALTER TABLE ticket ADD CONSTRAINT FK_97A0ADA34C7C611F FOREIGN KEY (discount_id) REFERENCES discount (id)');
$this->addSql('CREATE INDEX IDX_97A0ADA34C7C611F ON ticket (discount_id)');
$this->addSql('UPDATE ticket SET price = (SELECT price FROM entrada WHERE entrada.id = ticket.entrada_type_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE discount_entrada DROP FOREIGN KEY FK_7F41CF654C7C611F');
$this->addSql('ALTER TABLE ticket DROP FOREIGN KEY FK_97A0ADA34C7C611F');
$this->addSql('CREATE TABLE migration_versions (version VARCHAR(14) CHARACTER SET utf8mb3 NOT NULL COLLATE `utf8mb3_unicode_ci`, executed_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(version)) DEFAULT CHARACTER SET utf8mb3 COLLATE `utf8mb3_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
$this->addSql('DROP TABLE discount');
$this->addSql('DROP TABLE discount_entrada');
$this->addSql('DROP INDEX IDX_97A0ADA34C7C611F ON ticket');
$this->addSql('ALTER TABLE ticket DROP discount_id, DROP price');
}
}