vendor/bluue/customer-outstanding-bundle/migrations/Version20221207100624.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace CustomerOutstandingBundleMigrations;
  4. use App\Services\ObjectSerialize;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. use Symfony\Component\Uid\UuidV6;
  8. /**
  9.  * Auto-generated Migration: Please modify to your needs!
  10.  */
  11. final class Version20221207100624 extends AbstractMigration
  12. {
  13.     private ObjectSerialize $objectSerialize;
  14.     public function setObjectSerialize(ObjectSerialize $objectSerialize)
  15.     {
  16.         $this->objectSerialize $objectSerialize;
  17.     }
  18.     public function up(Schema $schema): void
  19.     {
  20.         $this->addSql('CREATE TABLE customer_outstanding_bundle__customer_type (id INT AUTO_INCREMENT NOT NULL, customer_id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', created_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', updated_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', deleted_by_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', amount NUMERIC(20, 6) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME DEFAULT NULL, INDEX IDX_4CCAA5F89395C3F3 (customer_id), INDEX IDX_4CCAA5F8B03A8386 (created_by_id), INDEX IDX_4CCAA5F8896DBBDE (updated_by_id), INDEX IDX_4CCAA5F8C76F1F52 (deleted_by_id), INDEX deleted_at (deleted_at), INDEX created_at (created_at), INDEX updated_at (updated_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  21.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type ADD CONSTRAINT FK_4CCAA5F89395C3F3 FOREIGN KEY (customer_id) REFERENCES customers_bundle__customer (id)');
  22.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type ADD CONSTRAINT FK_4CCAA5F8B03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id)');
  23.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type ADD CONSTRAINT FK_4CCAA5F8896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id)');
  24.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type ADD CONSTRAINT FK_4CCAA5F8C76F1F52 FOREIGN KEY (deleted_by_id) REFERENCES user (id)');
  25.     }
  26.     public function down(Schema $schema): void
  27.     {
  28.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type DROP FOREIGN KEY FK_4CCAA5F89395C3F3');
  29.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type DROP FOREIGN KEY FK_4CCAA5F8B03A8386');
  30.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type DROP FOREIGN KEY FK_4CCAA5F8896DBBDE');
  31.         $this->addSql('ALTER TABLE customer_outstanding_bundle__customer_type DROP FOREIGN KEY FK_4CCAA5F8C76F1F52');
  32.         $this->addSql('DROP TABLE customer_outstanding_bundle__customer_type');
  33.     }
  34.     public function postUp(Schema $schema): void
  35.     {
  36.         parent::postUp($schema);
  37.         $now = (new \DateTime())->format('Y-m-d H:i:s');
  38.         $configurations = [
  39.             'customer_outstanding_bundle__enabled' => true
  40.         ];
  41.         foreach ($configurations as $configuration => $value) {
  42.             $this->connection->insert('configuration', [
  43.                 'id' => (new UuidV6())->toBinary(),
  44.                 'name' => $configuration,
  45.                 'context_id' => null,
  46.                 'value' => $this->objectSerialize->add((object) ['value' => $value]),
  47.                 'created_at' => $now,
  48.                 'updated_at' => $now
  49.             ]);
  50.         }
  51.     }
  52. }