| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Migration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Doctrine\DBAL\Schema\Schema; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Doctrine\Migrations\AbstractMigration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\DBAL\Migrations\Version; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Ds\Component\Acl\Migration\Version0_15_0 as Acl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Ds\Component\Config\Migration\Version0_15_0 as Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Ds\Component\Container\Attribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Ds\Component\Database\Util\Objects; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Ds\Component\Database\Util\Parameters; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Ds\Component\Metadata\Migration\Version0_15_0 as Metadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Ds\Component\Parameter\Migration\Version0_15_0 as Parameter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Ds\Component\Tenant\Migration\Version0_15_0 as Tenant; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * Class Version0_15_0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | final class Version0_15_0 extends AbstractMigration implements ContainerAwareInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     use Attribute\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @cont string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     const DIRECTORY = '/srv/api/config/migrations'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @var \Ds\Component\Acl\Migration\Version0_15_0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     private $acl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var \Ds\Component\Config\Migration\Version0_15_0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @var \Ds\Component\Metadata\Migration\Version0_15_0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     private $metadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @var \Ds\Component\Parameter\Migration\Version0_15_0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     private $parameter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @var \Ds\Component\Tenant\Migration\Version0_15_0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     private $tenant; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param \Doctrine\DBAL\Migrations\Version  $version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function __construct(Version $version) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         parent::__construct($version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->acl = new Acl($version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->config = new Config($version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->metadata = new Metadata($version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->parameter = new Parameter($version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->tenant = new Tenant($version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * Up migration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param \Doctrine\DBAL\Schema\Schema $schema | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     public function up(Schema $schema) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $parameters = Parameters::parseFile(static::DIRECTORY.'/parameters.yaml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->acl->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/acl.yaml', $parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $this->config->setContainer($this->container)->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/config.yaml', $parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->metadata->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/metadata.yaml', $parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->parameter->setContainer($this->container)->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/system/parameter.yaml', $parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->tenant->up($schema, Objects::parseFile(static::DIRECTORY.'/0_15_0/system/tenant.yaml', $parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         switch ($this->platform->getName()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             case 'postgresql': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 $this->addSql('CREATE SEQUENCE app_form_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 $this->addSql('CREATE SEQUENCE app_form_trans_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 $this->addSql('CREATE TABLE app_form (id INT NOT NULL, uuid UUID NOT NULL, "owner" VARCHAR(255) DEFAULT NULL, owner_uuid UUID DEFAULT NULL, type VARCHAR(255) DEFAULT NULL, config JSON NOT NULL, version INT DEFAULT 1 NOT NULL, tenant UUID NOT NULL, deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 $this->addSql('CREATE UNIQUE INDEX UNIQ_57A6D8EFD17F50A6 ON app_form (uuid)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 $this->addSql('COMMENT ON COLUMN app_form.config IS \'(DC2Type:json_array)\''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 $this->addSql('CREATE TABLE app_form_trans (id INT NOT NULL, translatable_id INT DEFAULT NULL, title VARCHAR(255) DEFAULT NULL, description TEXT DEFAULT NULL, locale VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 $this->addSql('CREATE INDEX IDX_A57D11022C2AC5D3 ON app_form_trans (translatable_id)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 $this->addSql('CREATE UNIQUE INDEX app_form_trans_unique_translation ON app_form_trans (translatable_id, locale)'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 $this->addSql('ALTER TABLE app_form_trans ADD CONSTRAINT FK_A57D11022C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES app_form (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 $this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * Down migration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @param \Doctrine\DBAL\Schema\Schema $schema | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 107 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |     public function down(Schema $schema) | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |         $this->acl->down($schema); | 
            
                                                        
            
                                    
            
            
                | 111 |  |  |         $this->config->setContainer($this->container)->down($schema); | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |         $this->metadata->down($schema); | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |         $this->parameter->setContainer($this->container)->down($schema); | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |         $this->tenant->down($schema); | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |         switch ($this->platform->getName()) { | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |             case 'postgresql': | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |                 $this->addSql('ALTER TABLE app_form_trans DROP CONSTRAINT FK_A57D11022C2AC5D3'); | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |                 $this->addSql('DROP SEQUENCE app_form_id_seq CASCADE'); | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |                 $this->addSql('DROP SEQUENCE app_form_trans_id_seq CASCADE'); | 
            
                                                        
            
                                    
            
            
                | 121 |  |  |                 $this->addSql('DROP TABLE app_form'); | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |                 $this->addSql('DROP TABLE app_form_trans'); | 
            
                                                        
            
                                    
            
            
                | 123 |  |  |                 break; | 
            
                                                        
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 125 |  |  |             default: | 
            
                                                        
            
                                    
            
            
                | 126 |  |  |                 $this->abortIf(true,'Migration cannot be executed on "'.$this->platform->getName().'".'); | 
            
                                                        
            
                                    
            
            
                | 127 |  |  |                 break; | 
            
                                                        
            
                                    
            
            
                | 128 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 130 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 131 |  |  |  |