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

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 22 13:38:00 PDT 2011


Revision: 8114
          http://trac.macosforge.org/projects/calendarserver/changeset/8114
Author:   cdaboo at apple.com
Date:     2011-09-22 13:37:59 -0700 (Thu, 22 Sep 2011)
Log Message:
-----------
Fix issues related to truncation of index names with Oracle DBs.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_4_to_5.sql
    CalendarServer/trunk/txdav/common/datastore/sql_tables.py

Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_4_to_5.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_4_to_5.sql	2011-09-22 18:31:17 UTC (rev 8113)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_4_to_5.sql	2011-09-22 20:37:59 UTC (rev 8114)
@@ -18,50 +18,83 @@
 -- Upgrade database schema from VERSION 4 to 5 --
 -------------------------------------------------
 
+-- We have changed the hashing schema for index names, so rename
+-- all indexes first
+
+alter index IDX_0_CALENDAR_HOME_OWNER_UID rename to CALENDAR_HOME_OWNER_U_78016c63;
+alter index IDX_1_CALENDAR_HOME_METADATA_R rename to CALENDAR_HOME_METADAT_35a84eec;
+alter index IDX_2_INVITE_INVITE_UID rename to INVITE_INVITE_UID_9b0902ff;
+alter index IDX_3_INVITE_RESOURCE_ID rename to INVITE_RESOURCE_ID_b36ddc23;
+alter index IDX_4_INVITE_HOME_RESOURCE_ID rename to INVITE_HOME_RESOURCE__e9bdf77e;
+alter index IDX_5_NOTIFICATION_HOME_OWNER_ rename to NOTIFICATION_HOME_OWN_401a6203;
+alter index IDX_6_NOTIFICATION_NOTIFICATIO rename to NOTIFICATION_NOTIFICA_f891f5f9;
+alter index IDX_7_NOTIFICATION_NOTIFICATIO rename to NOTIFICATION_NOTIFICA_62daf834;
+alter index IDX_8_CALENDAR_BIND_HOME_RESOU rename to CALENDAR_BIND_HOME_RE_0d980be6;
+alter index IDX_9_CALENDAR_BIND_RESOURCE_I rename to CALENDAR_BIND_RESOURC_e57964d4;
+alter index IDX_10_CALENDAR_OBJECT_CALENDA rename to CALENDAR_OBJECT_CALEN_06694fd0;
+alter index IDX_11_CALENDAR_OBJECT_CALENDA rename to CALENDAR_OBJECT_CALEN_a9a453a9;
+alter index IDX_12_CALENDAR_OBJECT_CALENDA rename to CALENDAR_OBJECT_CALEN_96e83b73;
+alter index IDX_13_CALENDAR_OBJECT_ORGANIZ rename to CALENDAR_OBJECT_ORGAN_7ce24750;
+alter index IDX_14_CALENDAR_OBJECT_DROPBOX rename to CALENDAR_OBJECT_DROPB_de041d80;
+alter index IDX_15_TIME_RANGE_CALENDAR_RES rename to TIME_RANGE_CALENDAR_R_beb6e7eb;
+alter index IDX_16_TIME_RANGE_CALENDAR_OBJ rename to TIME_RANGE_CALENDAR_O_acf37bd1;
+alter index IDX_17_TRANSPARENCY_TIME_RANGE rename to TRANSPARENCY_TIME_RAN_5f34467f;
+alter index IDX_18_ATTACHMENT_DROPBOX_ID rename to ATTACHMENT_DROPBOX_ID_5073cf23;
+alter index IDX_19_ADDRESSBOOK_HOME_OWNER_ rename to ADDRESSBOOK_HOME_OWNE_44f7f53b;
+alter index IDX_20_ADDRESSBOOK_HOME_METADA rename to ADDRESSBOOK_HOME_META_cfe06701;
+alter index IDX_21_ADDRESSBOOK_BIND_HOME_R rename to ADDRESSBOOK_BIND_HOME_6a6dc8ce;
+alter index IDX_22_ADDRESSBOOK_BIND_RESOUR rename to ADDRESSBOOK_BIND_RESO_205aa75c;
+alter index IDX_23_ADDRESSBOOK_OBJECT_ADDR rename to ADDRESSBOOK_OBJECT_AD_1540450d;
+alter index IDX_24_CALENDAR_OBJECT_REVISIO rename to CALENDAR_OBJECT_REVIS_42be4d9e;
+alter index IDX_25_CALENDAR_OBJECT_REVISIO rename to CALENDAR_OBJECT_REVIS_3e41b7f0;
+alter index IDX_26_ADDRESSBOOK_OBJECT_REVI rename to ADDRESSBOOK_OBJECT_RE_5965a9e2
+alter index IDX_27_ADDRESSBOOK_OBJECT_REVI rename to ADDRESSBOOK_OBJECT_RE_2ab44f33;
+alter index IDX_28_NOTIFICATION_OBJECT_REV rename to NOTIFICATION_OBJECT_R_47002cd8;
+
 -- Changes related to primary key and index optimizations
 
-drop index CALENDAR_HOME_OWNER_UID;
+drop index CALENDAR_HOME_OWNER_U_78016c63;
 
-drop index CALENDAR_HOME_METADATA_RESOURCE_ID;
+drop index CALENDAR_HOME_METADAT_35a84eec;
 alter table CALENDAR_HOME_METADATA
  add primary key(RESOURCE_ID);
 
-drop index INVITE_RESOURCE_ID;
-create index INVITE_RESOURCE_ID on INVITE(RESOURCE_ID);
+drop index INVITE_RESOURCE_ID_b36ddc23;
+create index INVITE_RESOURCE_ID_b36ddc23 on INVITE(RESOURCE_ID);
 
-drop index INVITE_HOME_RESOURCE_ID;
-create index INVITE_HOME_RESOURCE_ID on INVITE(HOME_RESOURCE_ID);
+drop index INVITE_HOME_RESOURCE__e9bdf77e;
+create index INVITE_HOME_RESOURCE__e9bdf77e on INVITE(HOME_RESOURCE_ID);
 
-drop index NOTIFICATION_HOME_OWNER_UID;
+drop index NOTIFICATION_HOME_OWN_401a6203;
 
-drop index NOTIFICATION_NOTIFICATION_UID;
+drop index NOTIFICATION_NOTIFICA_62daf834;
 
-drop index CALENDAR_BIND_HOME_RESOURCE_ID;
+drop index CALENDAR_BIND_HOME_RE_0d980be6;
 
-drop index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID;
+drop index CALENDAR_OBJECT_CALEN_06694fd0;
 
-drop index ATTACHMENT_DROPBOX_ID;
+drop index ATTACHMENT_DROPBOX_ID_5073cf23;
 alter table ATTACHMENT
  drop unique(DROPBOX_ID, PATH),
  add primary key(DROPBOX_ID, PATH);
-create index ATTACHMENT_CALENDAR_HOME_RESOURCE_ID on
+create index ATTACHMENT_CALENDAR_H_0078845c on
   ATTACHMENT(CALENDAR_HOME_RESOURCE_ID);
 
-drop index ADDRESSBOOK_HOME_OWNER_UID;
+drop index ADDRESSBOOK_HOME_OWNE_44f7f53b;
   
-drop index ADDRESSBOOK_HOME_METADATA_RESOURCE_ID;
+drop index ADDRESSBOOK_HOME_META_cfe06701;
 alter table ADDRESSBOOK_HOME_METADATA
  add primary key(RESOURCE_ID);
 
-drop index ADDRESSBOOK_BIND_HOME_RESOURCE_ID;
+drop index ADDRESSBOOK_BIND_HOME_6a6dc8ce;
 
-drop index ADDRESSBOOK_OBJECT_ADDRESSBOOK_RESOURCE_ID;
+drop index ADDRESSBOOK_OBJECT_AD_1540450d;
 
-drop index CALENDAR_OBJECT_REVISIONS_RESOURCE_ID;
+drop index CALENDAR_OBJECT_REVIS_3e41b7f0;
 
-drop index ADDRESSBOOK_OBJECT_REVISIONS_RESOURCE_ID;
+drop index ADDRESSBOOK_OBJECT_RE_2ab44f33;
 
-drop index NOTIFICATION_OBJECT_REVISIONS_HOME_RESOURCE_ID;
+drop index NOTIFICATION_OBJECT_R_47002cd8;
 
 alter table CALENDARSERVER
  drop unique(NAME),

Modified: CalendarServer/trunk/txdav/common/datastore/sql_tables.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_tables.py	2011-09-22 18:31:17 UTC (rev 8113)
+++ CalendarServer/trunk/txdav/common/datastore/sql_tables.py	2011-09-22 20:37:59 UTC (rev 8114)
@@ -29,6 +29,7 @@
 from twext.enterprise.ienterprise import ORACLE_TABLE_NAME_MAX
 from twext.enterprise.dal.parseschema import schemaFromPath
 
+import hashlib
 
 
 def _populateSchema():
@@ -316,14 +317,15 @@
             out.write(";\n")
 
 
-    for (num, index) in enumerate(schema.model.indexes):
+    for index in schema.model.indexes:
         # Index names combine and repeat multiple table names and column names,
         # so several of them conflict once oracle's length limit is applied.
-        # Luckily, index names don't matter to application code at all, so we
-        # can add a little disambiguating prefix without breaking anything.
-        # -glyph
-        uniqueIndexName = 'IDX_%d_%s' % (num, index.name)
-        shortIndexName = uniqueIndexName[:30]
+        # To keep them unique within the limit we truncate and append 8 characters
+        # of the md5 hash of the full name.
+        shortIndexName = "%s_%s" % (
+            index.name[:21],
+            str(hashlib.md5(index.name).hexdigest())[:8],
+        )
         shortTableName = index.table.name[:30]
         out.write(
             'create index %s on %s (\n    ' % (shortIndexName, shortTableName)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110922/552896b9/attachment-0001.html>


More information about the calendarserver-changes mailing list