make Calendar update scripts more robust
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 6 Aug 2015 09:24:31 +0000 (11:24 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 6 Aug 2015 09:29:21 +0000 (11:29 +0200)
* check if etag col exists before adding
* remove rrule index as it already exists in most cases and
   there are problems with postgresql here

Change-Id: I346d5a493df4dd7684432852461d942c37ab9bb0
Reviewed-on: http://gerrit.tine20.com/customers/2095
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Calendar/Setup/Update/Release8.php

index a2be8f8..3cd3a66 100644 (file)
@@ -171,22 +171,24 @@ class Calendar_Setup_Update_Release8 extends Setup_Update_Abstract
      */
     public function update_3()
     {
-        $declaration = new Setup_Backend_Schema_Field_Xml('
-            <field>
-                <name>etag</name>
-                <type>text</type>
-                <length>60</length>
-            </field>');
-        $this->_backend->addCol('cal_events', $declaration);
-        
-        $declaration = new Setup_Backend_Schema_Index_Xml('
-            <index>
-                <name>etag</name>
+        if (! $this->_backend->columnExists('etag', 'cal_events')) {
+            $declaration = new Setup_Backend_Schema_Field_Xml('
                 <field>
                     <name>etag</name>
-                </field>
-            </index>');
-        $this->_backend->addIndex('cal_events', $declaration);
+                    <type>text</type>
+                    <length>60</length>
+                </field>');
+            $this->_backend->addCol('cal_events', $declaration);
+
+            $declaration = new Setup_Backend_Schema_Index_Xml('
+                <index>
+                    <name>etag</name>
+                    <field>
+                        <name>etag</name>
+                    </field>
+                </index>');
+            $this->_backend->addIndex('cal_events', $declaration);
+        }
         
         $this->setTableVersion('cal_events', 7);
         $this->setApplicationVersion('Calendar', '8.4');
@@ -221,7 +223,7 @@ class Calendar_Setup_Update_Release8 extends Setup_Update_Abstract
             $this->_backend->addCol('cal_events', $declaration);
         }
         
-        $this->setTableVersion('cal_events', 8);
+        $this->setTableVersion('cal_events', '8');
         $this->setApplicationVersion('Calendar', '8.6');
     }
     
@@ -229,21 +231,24 @@ class Calendar_Setup_Update_Release8 extends Setup_Update_Abstract
      * add rrule index
      * 
      * @see 0010214: improve calendar performance / yearly base events
+     *
+     * TODO re-enable this when it is fixed for postgresql
+     * @see 0011194: only drop index if it exists
      */
     public function update_6()
     {
-        $declaration = new Setup_Backend_Schema_Index_Xml('
-            <index>
-                <name>rrule</name>
-                <field>
-                    <name>rrule</name>
-                </field>
-            </index>');
-        try {
-            $this->_backend->addIndex('cal_events', $declaration);
-        } catch (Zend_Db_Statement_Exception $e) {
-            Tinebase_Exception::log($e);
-        }
+//        $declaration = new Setup_Backend_Schema_Index_Xml('
+//            <index>
+//                <name>rrule</name>
+//                <field>
+//                    <name>rrule</name>
+//                </field>
+//            </index>');
+//        try {
+//            $this->_backend->addIndex('cal_events', $declaration);
+//        } catch (Zend_Db_Statement_Exception $e) {
+//            Tinebase_Exception::log($e);
+//        }
         
         $this->setTableVersion('cal_events', '9');
         $this->setApplicationVersion('Calendar', '8.7');