migrations/Version20230203122139.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20230203122139 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $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))');
  19.         $this->addSql('CREATE UNIQUE INDEX UNIQ_64BF3F0277153098 ON coupon (code)');
  20.         $this->addSql('CREATE INDEX IDX_64BF3F0261220EA6 ON coupon (creator_id)');
  21.         $this->addSql('COMMENT ON COLUMN coupon.id IS \'(DC2Type:uuid)\'');
  22.         $this->addSql('COMMENT ON COLUMN coupon.creator_id IS \'(DC2Type:uuid)\'');
  23.         $this->addSql('COMMENT ON COLUMN coupon.expired_at IS \'(DC2Type:datetime_immutable)\'');
  24.         $this->addSql('CREATE TABLE coupon__recipients (coupon_id UUID NOT NULL, user_id UUID NOT NULL, PRIMARY KEY(coupon_id, user_id))');
  25.         $this->addSql('CREATE INDEX IDX_4B511B66C5951B ON coupon__recipients (coupon_id)');
  26.         $this->addSql('CREATE INDEX IDX_4B511BA76ED395 ON coupon__recipients (user_id)');
  27.         $this->addSql('COMMENT ON COLUMN coupon__recipients.coupon_id IS \'(DC2Type:uuid)\'');
  28.         $this->addSql('COMMENT ON COLUMN coupon__recipients.user_id IS \'(DC2Type:uuid)\'');
  29.         $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))');
  30.         $this->addSql('CREATE INDEX IDX_6170BAD9E92F8F78 ON coupon__redeem (recipient_id)');
  31.         $this->addSql('CREATE INDEX IDX_6170BAD966C5951B ON coupon__redeem (coupon_id)');
  32.         $this->addSql('CREATE UNIQUE INDEX UNIQ_6170BAD92FC0CB0F ON coupon__redeem (transaction_id)');
  33.         $this->addSql('COMMENT ON COLUMN coupon__redeem.id IS \'(DC2Type:uuid)\'');
  34.         $this->addSql('COMMENT ON COLUMN coupon__redeem.recipient_id IS \'(DC2Type:uuid)\'');
  35.         $this->addSql('COMMENT ON COLUMN coupon__redeem.coupon_id IS \'(DC2Type:uuid)\'');
  36.         $this->addSql('COMMENT ON COLUMN coupon__redeem.transaction_id IS \'(DC2Type:uuid)\'');
  37.         $this->addSql('ALTER TABLE coupon ADD CONSTRAINT FK_64BF3F0261220EA6 FOREIGN KEY (creator_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  38.         $this->addSql('ALTER TABLE coupon__recipients ADD CONSTRAINT FK_4B511B66C5951B FOREIGN KEY (coupon_id) REFERENCES coupon (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
  39.         $this->addSql('ALTER TABLE coupon__recipients ADD CONSTRAINT FK_4B511BA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
  40.         $this->addSql('ALTER TABLE coupon__redeem ADD CONSTRAINT FK_6170BAD9E92F8F78 FOREIGN KEY (recipient_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  41.         $this->addSql('ALTER TABLE coupon__redeem ADD CONSTRAINT FK_6170BAD966C5951B FOREIGN KEY (coupon_id) REFERENCES coupon (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  42.         $this->addSql('ALTER TABLE coupon__redeem ADD CONSTRAINT FK_6170BAD92FC0CB0F FOREIGN KEY (transaction_id) REFERENCES ledger__transaction (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  43.         $this->addSql('ALTER INDEX uniq_9aaedfce8cb9a7aa RENAME TO UNIQ_8261DD858CB9A7AA');
  44.         $this->addSql('ALTER INDEX uniq_9aaedfce93bac426 RENAME TO UNIQ_8261DD8593BAC426');
  45.     }
  46.     public function down(Schema $schema): void
  47.     {
  48.         // this down() migration is auto-generated, please modify it to your needs
  49.         $this->addSql('ALTER TABLE coupon DROP CONSTRAINT FK_64BF3F0261220EA6');
  50.         $this->addSql('ALTER TABLE coupon__recipients DROP CONSTRAINT FK_4B511B66C5951B');
  51.         $this->addSql('ALTER TABLE coupon__recipients DROP CONSTRAINT FK_4B511BA76ED395');
  52.         $this->addSql('ALTER TABLE coupon__redeem DROP CONSTRAINT FK_6170BAD9E92F8F78');
  53.         $this->addSql('ALTER TABLE coupon__redeem DROP CONSTRAINT FK_6170BAD966C5951B');
  54.         $this->addSql('ALTER TABLE coupon__redeem DROP CONSTRAINT FK_6170BAD92FC0CB0F');
  55.         $this->addSql('DROP TABLE coupon');
  56.         $this->addSql('DROP TABLE coupon__recipients');
  57.         $this->addSql('DROP TABLE coupon__redeem');
  58.         $this->addSql('ALTER INDEX uniq_8261dd8593bac426 RENAME TO uniq_9aaedfce93bac426');
  59.         $this->addSql('ALTER INDEX uniq_8261dd858cb9a7aa RENAME TO uniq_9aaedfce8cb9a7aa');
  60.     }
  61. }