| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Migrations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\DBAL\Schema\Schema; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Doctrine\Migrations\AbstractMigration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | final class Version20190516120833 extends AbstractMigration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function getDescription(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         return 'Add authors table and course <=> author many to many relation table'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     public function up(Schema $schema): void | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         $this->addSql('CREATE TABLE npd_author ( | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |           uuid UUID NOT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |           name VARCHAR(255) NOT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |           bio TEXT DEFAULT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |           picture VARCHAR(255) DEFAULT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |           created TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |           updated TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |           PRIMARY KEY(uuid) | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         )'); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->addSql('COMMENT ON COLUMN npd_author.uuid IS \'(DC2Type:uuid)\''); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         $this->addSql('CREATE TABLE npd_author_course ( | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |           author_id UUID NOT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |           course_id INT NOT NULL,  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |           PRIMARY KEY(author_id, course_id) | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         )'); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         $this->addSql('CREATE INDEX IDX_61BCADC1F675F31B ON npd_author_course (author_id)'); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $this->addSql('CREATE INDEX IDX_61BCADC1591CC992 ON npd_author_course (course_id)'); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         $this->addSql('COMMENT ON COLUMN npd_author_course.author_id IS \'(DC2Type:uuid)\''); | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         $this->addSql('ALTER TABLE  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |           npd_author_course  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         ADD  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |           CONSTRAINT FK_61BCADC1F675F31B FOREIGN KEY (author_id) REFERENCES npd_author (uuid) NOT DEFERRABLE INITIALLY IMMEDIATE'); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $this->addSql('ALTER TABLE  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |           npd_author_course  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ADD  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |           CONSTRAINT FK_61BCADC1591CC992 FOREIGN KEY (course_id) REFERENCES course (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function down(Schema $schema): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->addSql('ALTER TABLE npd_author_course DROP CONSTRAINT FK_61BCADC1F675F31B'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->addSql('DROP TABLE npd_author'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->addSql('DROP TABLE npd_author_course'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  |