1 <?php 2 namespace Neos\Flow\Persistence\Doctrine\Migrations; 3 4 use Doctrine\Migrations\AbstractMigration; 5 use Doctrine\DBAL\Schema\Schema; 6 7 /** 8 * Introduce variant presets 9 */ 10 class Version20190314150745 extends AbstractMigration 11 { 12 13 /** 14 * @return string 15 */ 16 public function getDescription(): string 17 { 18 return 'Introduce variant presets'; 19 } 20 21 /** 22 * @param Schema $schema 23 * @return void 24 * @throws \Doctrine\DBAL\DBALException 25 * @throws \Doctrine\DBAL\Migrations\AbortMigrationException 26 */ 27 public function up(Schema $schema): void 28 { 29 $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on "postgresql".'); 30 31 // It is now safe the remove the default value from the database schema, as we only needed it during migration of earlier Neos versions: 32 $this->addSql('ALTER TABLE neos_media_domain_model_asset ALTER assetsourceidentifier DROP DEFAULT'); 33 $this->addSql('ALTER TABLE neos_media_domain_model_asset ALTER assetsourceidentifier SET NOT NULL'); 34 35 // Add Doctrine hint for DateTimeImmutable: 36 $this->addSql('COMMENT ON COLUMN neos_media_domain_model_importedasset.importedat IS \'(DC2Type:datetime_immutable)\''); 37 38 // Introduce variant preset fields: 39 $this->addSql('ALTER TABLE neos_media_domain_model_imagevariant ADD presetidentifier VARCHAR(255) DEFAULT NULL'); 40 $this->addSql('ALTER TABLE neos_media_domain_model_imagevariant ADD presetvariantname VARCHAR(255) DEFAULT NULL'); 41 } 42 43 /** 44 * @param Schema $schema 45 * @return void 46 * @throws \Doctrine\DBAL\DBALException 47 * @throws \Doctrine\DBAL\Migrations\AbortMigrationException 48 */ 49 public function down(Schema $schema): void 50 { 51 $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on "postgresql".'); 52 53 $this->addSql('ALTER TABLE neos_media_domain_model_asset ALTER assetsourceidentifier SET DEFAULT \'neos\''); 54 $this->addSql('ALTER TABLE neos_media_domain_model_asset ALTER assetsourceidentifier DROP NOT NULL'); 55 $this->addSql('ALTER TABLE neos_media_domain_model_imagevariant DROP presetidentifier'); 56 $this->addSql('ALTER TABLE neos_media_domain_model_imagevariant DROP presetvariantname'); 57 $this->addSql('COMMENT ON COLUMN neos_media_domain_model_importedasset.importedat IS NULL'); 58 } 59 }