[CalendarServer-changes] [8022] CalendarServer/trunk/txdav/common/datastore

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 25 20:54:17 PDT 2011


Revision: 8022
          http://trac.macosforge.org/projects/calendarserver/changeset/8022
Author:   cdaboo at apple.com
Date:     2011-08-25 20:54:16 -0700 (Thu, 25 Aug 2011)
Log Message:
-----------
Database upgrade scripts may differ by db type.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/common/datastore/util.py

Added Paths:
-----------
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_3_to_4.sql
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_3_to_4.sql

Removed Paths:
-------------
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_from_3_to_4.sql

Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_3_to_4.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_3_to_4.sql	                        (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_3_to_4.sql	2011-08-26 03:54:16 UTC (rev 8022)
@@ -0,0 +1,27 @@
+----
+-- Copyright (c) 2011 Apple Inc. All rights reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+----
+
+-------------------------------------------------
+-- Upgrade database schema from VERSION 3 to 4 --
+-------------------------------------------------
+
+-- Just need to modify one column
+alter table CALENDAR_OBJECT
+ modify (SCHEDULE_OBJECT null);
+
+-- Now update the version
+update CALENDARSERVER set VALUE = '4' where NAME = 'VERSION';
+

Copied: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_3_to_4.sql (from rev 8015, CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_from_3_to_4.sql)
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_3_to_4.sql	                        (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_3_to_4.sql	2011-08-26 03:54:16 UTC (rev 8022)
@@ -0,0 +1,27 @@
+----
+-- Copyright (c) 2011 Apple Inc. All rights reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+----
+
+-------------------------------------------------
+-- Upgrade database schema from VERSION 3 to 4 --
+-------------------------------------------------
+
+-- Just need to modify one column
+alter table CALENDAR_OBJECT
+ alter column SCHEDULE_OBJECT drop not null;
+
+-- Now update the version
+update CALENDARSERVER set VALUE = '4' where NAME = 'VERSION';
+

Deleted: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_from_3_to_4.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_from_3_to_4.sql	2011-08-26 03:44:19 UTC (rev 8021)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_from_3_to_4.sql	2011-08-26 03:54:16 UTC (rev 8022)
@@ -1,27 +0,0 @@
-----
--- Copyright (c) 2011 Apple Inc. All rights reserved.
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
-----
-
--------------------------------------------------
--- Upgrade database schema from VERSION 3 to 4 --
--------------------------------------------------
-
--- Just need to modify one column
-alter table CALENDAR_OBJECT
- alter column SCHEDULE_OBJECT drop not null;
-
--- Now update the version
-update CALENDARSERVER set VALUE = '4' where NAME = 'VERSION';
-

Modified: CalendarServer/trunk/txdav/common/datastore/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/util.py	2011-08-26 03:44:19 UTC (rev 8021)
+++ CalendarServer/trunk/txdav/common/datastore/util.py	2011-08-26 03:54:16 UTC (rev 8022)
@@ -267,6 +267,7 @@
         
         # Get the schema version in the current database
         sqlTxn = self.sqlStore.newTransaction()
+        dialect = sqlTxn.dialect
         try:
             actual_version = yield sqlTxn.schemaVersion()
             yield sqlTxn.commit()
@@ -284,7 +285,7 @@
             self.log_error(msg)
             raise RuntimeError(msg)
         else:
-            yield self.upgradeVersion(actual_version, required_version)
+            yield self.upgradeVersion(actual_version, required_version, dialect)
             
         self.log_warn(
             "Database schema check complete, launching database service."
@@ -294,7 +295,7 @@
 
     @inlineCallbacks
 
-    def upgradeVersion(self, fromVersion, toVersion):
+    def upgradeVersion(self, fromVersion, toVersion, dialect):
         """
         Update the database from one version to another (the current one). Do this by
         looking for upgrade_from_X_to_Y.sql files that cover the full range of upgrades.
@@ -303,10 +304,10 @@
         self.log_warn("Starting schema upgrade from version %d to %d." % (fromVersion, toVersion,))
         
         # Scan for all possible upgrade files - returned sorted
-        files = self.scanForUpgradeFiles()
+        files = self.scanForUpgradeFiles(dialect)
         
         # Determine upgrade sequence and run each upgrade
-        upgrades = self.determineUpgradeSequence(fromVersion, toVersion, files)
+        upgrades = self.determineUpgradeSequence(fromVersion, toVersion, files, dialect)
 
         # Use one transaction for the entire set of upgrades
         sqlTxn = self.sqlStore.newTransaction()
@@ -321,12 +322,12 @@
 
         self.log_warn("Schema upgraded from version %d to %d." % (fromVersion, toVersion,))
 
-    def scanForUpgradeFiles(self):
+    def scanForUpgradeFiles(self, dialect):
         """
         Scan the module path for upgrade files with the require name.
         """
         
-        fp = self.schemaLocation.child("upgrades")
+        fp = self.schemaLocation.child("upgrades").child(dialect)
         upgrades = []
         regex = re.compile("upgrade_from_(\d)+_to_(\d)+.sql")
         for child in fp.globChildren("upgrade_*.sql"):
@@ -339,7 +340,7 @@
         upgrades.sort(key=lambda x:(x[0], x[1]))
         return upgrades
     
-    def determineUpgradeSequence(self, fromVersion, toVersion, files):
+    def determineUpgradeSequence(self, fromVersion, toVersion, files, dialect):
         """
         Determine the upgrade_from_X_to_Y.sql files that cover the full range of upgrades.
         Note that X and Y may not be consecutive, e.g., we might have an upgrade from 3 to 4,
@@ -358,7 +359,7 @@
         nextVersion = fromVersion
         while nextVersion != toVersion:
             if nextVersion not in filesByFromVersion:
-                msg = "Missing upgrade file from version %d" % (nextVersion, )
+                msg = "Missing upgrade file from version %d with dialect %s" % (nextVersion, dialect,)
                 self.log_error(msg)
                 raise RuntimeError(msg)
             else:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110825/d1f4565c/attachment.html>


More information about the calendarserver-changes mailing list