safeCreateTable('rescue_animal_gallery_item', [ 'id' => $this->primaryKey(), 'animal_id' => $this->integer()->notNull(), 'file_path' => $this->string(500)->null(), 'file_id' => $this->integer()->null(), 'source_post_id' => $this->integer()->null(), 'source_type' => $this->string(32)->notNull()->defaultValue('upload'), 'caption' => $this->text()->null(), 'created_by' => $this->integer()->null(), 'created_at' => $this->dateTime()->null(), 'updated_at' => $this->dateTime()->null(), ]); $this->safeCreateIndex('idx_rescue_animal_gallery_animal', 'rescue_animal_gallery_item', 'animal_id', false); $this->safeCreateIndex('idx_rescue_animal_gallery_file', 'rescue_animal_gallery_item', 'file_id', false); $this->safeCreateIndex('idx_rescue_animal_gallery_post', 'rescue_animal_gallery_item', 'source_post_id', false); $this->safeCreateIndex('idx_rescue_animal_gallery_created', 'rescue_animal_gallery_item', ['animal_id', 'id'], false); $this->safeAddForeignKey( 'fk_rescue_animal_gallery_animal', 'rescue_animal_gallery_item', 'animal_id', 'rescue_animal', 'id', 'CASCADE', 'CASCADE' ); if ($this->db->getSchema()->getTableSchema('file', true) !== null) { $this->safeAddForeignKey( 'fk_rescue_animal_gallery_file', 'rescue_animal_gallery_item', 'file_id', 'file', 'id', 'SET NULL', 'CASCADE' ); } if ($this->db->getSchema()->getTableSchema('post', true) !== null) { $this->safeAddForeignKey( 'fk_rescue_animal_gallery_post', 'rescue_animal_gallery_item', 'source_post_id', 'post', 'id', 'SET NULL', 'CASCADE' ); } } public function safeDown() { $this->safeDropTable('rescue_animal_gallery_item'); } }