migrations/Version20230203122139.php line 1
<?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 Version20230203122139 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 coupon (id UUID NOT NULL, creator_id UUID NOT NULL, amount INT NOT NULL, size_type VARCHAR(20) NOT NULL, expired_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, quantity INT DEFAULT NULL, code VARCHAR(20) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_64BF3F0277153098 ON coupon (code)');
$this->addSql('CREATE INDEX IDX_64BF3F0261220EA6 ON coupon (creator_id)');
$this->addSql('COMMENT ON COLUMN coupon.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN coupon.creator_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN coupon.expired_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('CREATE TABLE coupon__recipients (coupon_id UUID NOT NULL, user_id UUID NOT NULL, PRIMARY KEY(coupon_id, user_id))');
$this->addSql('CREATE INDEX IDX_4B511B66C5951B ON coupon__recipients (coupon_id)');
$this->addSql('CREATE INDEX IDX_4B511BA76ED395 ON coupon__recipients (user_id)');
$this->addSql('COMMENT ON COLUMN coupon__recipients.coupon_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN coupon__recipients.user_id IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE coupon__redeem (id UUID NOT NULL, recipient_id UUID NOT NULL, coupon_id UUID NOT NULL, transaction_id UUID NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_6170BAD9E92F8F78 ON coupon__redeem (recipient_id)');
$this->addSql('CREATE INDEX IDX_6170BAD966C5951B ON coupon__redeem (coupon_id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_6170BAD92FC0CB0F ON coupon__redeem (transaction_id)');
$this->addSql('COMMENT ON COLUMN coupon__redeem.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN coupon__redeem.recipient_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN coupon__redeem.coupon_id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN coupon__redeem.transaction_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE coupon ADD CONSTRAINT FK_64BF3F0261220EA6 FOREIGN KEY (creator_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE coupon__recipients ADD CONSTRAINT FK_4B511B66C5951B FOREIGN KEY (coupon_id) REFERENCES coupon (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE coupon__recipients ADD CONSTRAINT FK_4B511BA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE coupon__redeem ADD CONSTRAINT FK_6170BAD9E92F8F78 FOREIGN KEY (recipient_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE coupon__redeem ADD CONSTRAINT FK_6170BAD966C5951B FOREIGN KEY (coupon_id) REFERENCES coupon (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE coupon__redeem ADD CONSTRAINT FK_6170BAD92FC0CB0F FOREIGN KEY (transaction_id) REFERENCES ledger__transaction (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX uniq_9aaedfce8cb9a7aa RENAME TO UNIQ_8261DD858CB9A7AA');
$this->addSql('ALTER INDEX uniq_9aaedfce93bac426 RENAME TO UNIQ_8261DD8593BAC426');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE coupon DROP CONSTRAINT FK_64BF3F0261220EA6');
$this->addSql('ALTER TABLE coupon__recipients DROP CONSTRAINT FK_4B511B66C5951B');
$this->addSql('ALTER TABLE coupon__recipients DROP CONSTRAINT FK_4B511BA76ED395');
$this->addSql('ALTER TABLE coupon__redeem DROP CONSTRAINT FK_6170BAD9E92F8F78');
$this->addSql('ALTER TABLE coupon__redeem DROP CONSTRAINT FK_6170BAD966C5951B');
$this->addSql('ALTER TABLE coupon__redeem DROP CONSTRAINT FK_6170BAD92FC0CB0F');
$this->addSql('DROP TABLE coupon');
$this->addSql('DROP TABLE coupon__recipients');
$this->addSql('DROP TABLE coupon__redeem');
$this->addSql('ALTER INDEX uniq_8261dd8593bac426 RENAME TO uniq_9aaedfce93bac426');
$this->addSql('ALTER INDEX uniq_8261dd858cb9a7aa RENAME TO uniq_9aaedfce8cb9a7aa');
}
}