[CalendarServer-changes] [8015] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 25 07:32:54 PDT 2011


Revision: 8015
          http://trac.macosforge.org/projects/calendarserver/changeset/8015
Author:   cdaboo at apple.com
Date:     2011-08-25 07:32:53 -0700 (Thu, 25 Aug 2011)
Log Message:
-----------
Make sure missing schedule-object state results in a recalculation of the proper state to aid migration from non-implicit.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/scheduling/implicit.py
    CalendarServer/trunk/txdav/caldav/datastore/file.py
    CalendarServer/trunk/txdav/caldav/datastore/test/common.py
    CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_template.sql
    CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py

Added Paths:
-----------
    CalendarServer/trunk/txdav/common/datastore/sql_schema/old/v3.sql
    CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_from_3_to_4.sql

Modified: CalendarServer/trunk/twistedcaldav/scheduling/implicit.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/scheduling/implicit.py	2011-08-25 02:29:22 UTC (rev 8014)
+++ CalendarServer/trunk/twistedcaldav/scheduling/implicit.py	2011-08-25 14:32:53 UTC (rev 8015)
@@ -67,7 +67,7 @@
         self.internal_request = internal_request
 
         existing_resource = resource.exists()
-        is_scheduling_object = self.checkSchedulingObjectResource(resource)
+        is_scheduling_object = (yield self.checkSchedulingObjectResource(resource))
         existing_type = "schedule" if is_scheduling_object else "calendar"
         new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"
 
@@ -114,8 +114,8 @@
         new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"
 
         dest_exists = destresource.exists()
-        dest_is_implicit = self.checkSchedulingObjectResource(destresource)
-        src_is_implicit = self.checkSchedulingObjectResource(srcresource) or new_type == "schedule"
+        dest_is_implicit = (yield self.checkSchedulingObjectResource(destresource))
+        src_is_implicit = (yield self.checkSchedulingObjectResource(srcresource)) or new_type == "schedule"
 
         if srccal and destcal:
             if src_is_implicit and dest_exists or dest_is_implicit:
@@ -148,8 +148,8 @@
 
         new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"
 
-        dest_is_implicit = self.checkSchedulingObjectResource(destresource)
-        src_is_implicit = self.checkSchedulingObjectResource(srcresource) or new_type == "schedule"
+        dest_is_implicit = (yield self.checkSchedulingObjectResource(destresource))
+        src_is_implicit = (yield self.checkSchedulingObjectResource(srcresource)) or new_type == "schedule"
 
         if srccal and destcal:
             if src_is_implicit or dest_is_implicit:
@@ -181,15 +181,36 @@
 
         yield self.checkImplicitState()
 
-        is_scheduling_object = self.checkSchedulingObjectResource(resource)
+        is_scheduling_object = (yield self.checkSchedulingObjectResource(resource))
         resource_type = "schedule" if is_scheduling_object else "calendar"
         self.action = "remove" if resource_type == "schedule" else "none"
 
         returnValue((self.action != "none", False,))
 
+    @inlineCallbacks
     def checkSchedulingObjectResource(self, resource):
         
-        return resource.isScheduleObject if resource and resource.exists() else False
+        if resource and resource.exists():
+            implicit = resource.isScheduleObject
+            if implicit is not None:
+                returnValue(implicit)
+            else:
+                calendar = (yield self.resource.iCalendarForUser(self.request))
+                # Get the ORGANIZER and verify it is the same for all components
+                try:
+                    organizer = calendar.validOrganizerForScheduling()
+                except ValueError:
+                    # We have different ORGANIZERs in the same iCalendar object - this is an error
+                    returnValue(False)
+                organizerPrincipal = resource.principalForCalendarUserAddress(organizer) if organizer else None
+                implicit = organizerPrincipal != None
+                log.debug("Implicit - checked scheduling object resource state for UID: '%s', result: %s" % (
+                    calendar.resourceUID(),
+                    implicit,
+                ))
+                returnValue(implicit)
+
+        returnValue(False)
         
     @inlineCallbacks
     def checkImplicitState(self):

Modified: CalendarServer/trunk/txdav/caldav/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/file.py	2011-08-25 02:29:22 UTC (rev 8014)
+++ CalendarServer/trunk/txdav/caldav/datastore/file.py	2011-08-25 14:32:53 UTC (rev 8015)
@@ -439,11 +439,18 @@
     accessMode = property(_get_accessMode, _set_accessMode)
 
     def _get_isScheduleObject(self):
-        return str(self.properties().get(PropertyName.fromElement(customxml.TwistedSchedulingObjectResource), "false")) == "true"
+        """
+        If the property is not present, then return None, else return a bool based on the
+        str "true" or "false" value.
+        """
+        prop = self.properties().get(PropertyName.fromElement(customxml.TwistedSchedulingObjectResource))
+        if prop is not None:
+            prop = str(prop) == "true"
+        return prop
 
     def _set_isScheduleObject(self, value):
         pname = PropertyName.fromElement(customxml.TwistedSchedulingObjectResource)
-        if value:
+        if value is not None:
             self.properties()[pname] = customxml.TwistedSchedulingObjectResource.fromString("true" if value else "false")
         elif pname in self.properties():
             del self.properties()[pname]

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2011-08-25 02:29:22 UTC (rev 8014)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2011-08-25 14:32:53 UTC (rev 8015)
@@ -175,7 +175,7 @@
     }
     metadata3 = {
         "accessMode": "PUBLIC",
-        "isScheduleObject": True,
+        "isScheduleObject": None,
         "scheduleTag": "abc",
         "scheduleEtags": (),
         "hasPrivateComment": True,

Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql	2011-08-25 02:29:22 UTC (rev 8014)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/current.sql	2011-08-25 14:32:53 UTC (rev 8015)
@@ -174,7 +174,7 @@
   ORGANIZER_OBJECT     integer      references CALENDAR_OBJECT,
   RECURRANCE_MAX       date,        -- maximum date that recurrences have been expanded to.
   ACCESS               integer      default 0 not null,
-  SCHEDULE_OBJECT      boolean      default false not null,
+  SCHEDULE_OBJECT      boolean      default false,
   SCHEDULE_TAG         varchar(36)  default null,
   SCHEDULE_ETAGS       text         default null,
   PRIVATE_COMMENTS     boolean      default false not null,
@@ -479,5 +479,5 @@
   unique(NAME)
 );
 
-insert into CALENDARSERVER values ('VERSION', '3');
+insert into CALENDARSERVER values ('VERSION', '4');
 

Added: CalendarServer/trunk/txdav/common/datastore/sql_schema/old/v3.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/old/v3.sql	                        (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/old/v3.sql	2011-08-25 14:32:53 UTC (rev 8015)
@@ -0,0 +1,483 @@
+-- -*- test-case-name: txdav.caldav.datastore.test.test_sql,txdav.carddav.datastore.test.test_sql -*-
+
+----
+-- Copyright (c) 2010-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.
+----
+
+-----------------
+-- Resource ID --
+-----------------
+
+create sequence RESOURCE_ID_SEQ;
+
+
+-------------------
+-- Calendar Home --
+-------------------
+
+create table CALENDAR_HOME (
+  RESOURCE_ID      integer      primary key default nextval('RESOURCE_ID_SEQ'),
+  OWNER_UID        varchar(255) not null unique
+);
+
+create index CALENDAR_HOME_OWNER_UID on CALENDAR_HOME(OWNER_UID);
+
+----------------------------
+-- Calendar Home Metadata --
+----------------------------
+
+create table CALENDAR_HOME_METADATA (
+  RESOURCE_ID      integer      not null references CALENDAR_HOME on delete cascade,
+  QUOTA_USED_BYTES integer      default 0 not null
+);
+
+create index CALENDAR_HOME_METADATA_RESOURCE_ID
+    on CALENDAR_HOME_METADATA(RESOURCE_ID);
+
+--------------
+-- Calendar --
+--------------
+
+create table CALENDAR (
+  RESOURCE_ID integer   primary key default nextval('RESOURCE_ID_SEQ'),
+  CREATED     timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED    timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+------------------------
+-- Sharing Invitation --
+------------------------
+
+create table INVITE (
+    INVITE_UID         varchar(255) not null,
+    NAME               varchar(255) not null,
+    RECIPIENT_ADDRESS  varchar(255) not null,
+    HOME_RESOURCE_ID   integer      not null,
+    RESOURCE_ID        integer      not null
+);
+
+create index INVITE_INVITE_UID on INVITE(INVITE_UID);
+create index INVITE_RESOURCE_ID on INVITE(INVITE_UID);
+create index INVITE_HOME_RESOURCE_ID on INVITE(INVITE_UID);
+
+---------------------------
+-- Sharing Notifications --
+---------------------------
+
+create table NOTIFICATION_HOME (
+  RESOURCE_ID integer      primary key default nextval('RESOURCE_ID_SEQ'),
+  OWNER_UID   varchar(255) not null unique
+);
+
+create index NOTIFICATION_HOME_OWNER_UID on NOTIFICATION_HOME(OWNER_UID);
+
+
+create table NOTIFICATION (
+  RESOURCE_ID                   integer      primary key default nextval('RESOURCE_ID_SEQ'),
+  NOTIFICATION_HOME_RESOURCE_ID integer      not null references NOTIFICATION_HOME,
+  NOTIFICATION_UID              varchar(255) not null,
+  XML_TYPE                      varchar(255) not null,
+  XML_DATA                      text         not null,
+  MD5                           char(32)     not null,
+  CREATED                       timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                      timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+
+  unique(NOTIFICATION_UID, NOTIFICATION_HOME_RESOURCE_ID)
+);
+
+create index NOTIFICATION_NOTIFICATION_HOME_RESOURCE_ID on
+  NOTIFICATION(NOTIFICATION_HOME_RESOURCE_ID);
+
+create index NOTIFICATION_NOTIFICATION_UID on NOTIFICATION(NOTIFICATION_UID);
+
+-------------------
+-- Calendar Bind --
+-------------------
+
+-- Joins CALENDAR_HOME and CALENDAR
+
+create table CALENDAR_BIND (
+  CALENDAR_HOME_RESOURCE_ID integer      not null references CALENDAR_HOME,
+  CALENDAR_RESOURCE_ID      integer      not null references CALENDAR on delete cascade,
+  
+  -- An invitation which hasn't been accepted yet will not yet have a resource
+  -- name, so this field may be null.
+  
+  CALENDAR_RESOURCE_NAME    varchar(255),
+  BIND_MODE                 integer      not null, -- enum CALENDAR_BIND_MODE
+  BIND_STATUS               integer      not null, -- enum CALENDAR_BIND_STATUS
+  SEEN_BY_OWNER             boolean      not null,
+  SEEN_BY_SHAREE            boolean      not null,
+  MESSAGE                   text,
+
+  primary key(CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_ID),
+  unique(CALENDAR_HOME_RESOURCE_ID, CALENDAR_RESOURCE_NAME)
+);
+
+create index CALENDAR_BIND_HOME_RESOURCE_ID on
+  CALENDAR_BIND(CALENDAR_HOME_RESOURCE_ID);
+create index CALENDAR_BIND_RESOURCE_ID on
+  CALENDAR_BIND(CALENDAR_RESOURCE_ID);
+
+-- Enumeration of calendar bind modes
+
+create table CALENDAR_BIND_MODE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_BIND_MODE values (0, 'own'  );
+insert into CALENDAR_BIND_MODE values (1, 'read' );
+insert into CALENDAR_BIND_MODE values (2, 'write');
+insert into CALENDAR_BIND_MODE values (3, 'direct');
+
+-- Enumeration of statuses
+
+create table CALENDAR_BIND_STATUS (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_BIND_STATUS values (0, 'invited' );
+insert into CALENDAR_BIND_STATUS values (1, 'accepted');
+insert into CALENDAR_BIND_STATUS values (2, 'declined');
+insert into CALENDAR_BIND_STATUS values (3, 'invalid');
+
+
+---------------------
+-- Calendar Object --
+---------------------
+
+create table CALENDAR_OBJECT (
+  RESOURCE_ID          integer      primary key default nextval('RESOURCE_ID_SEQ'),
+  CALENDAR_RESOURCE_ID integer      not null references CALENDAR on delete cascade,
+  RESOURCE_NAME        varchar(255) not null,
+  ICALENDAR_TEXT       text         not null,
+  ICALENDAR_UID        varchar(255) not null,
+  ICALENDAR_TYPE       varchar(255) not null,
+  ATTACHMENTS_MODE     integer      default 0 not null, -- enum CALENDAR_OBJECT_ATTACHMENTS_MODE
+  DROPBOX_ID           varchar(255),
+  ORGANIZER            varchar(255),
+  ORGANIZER_OBJECT     integer      references CALENDAR_OBJECT,
+  RECURRANCE_MAX       date,        -- maximum date that recurrences have been expanded to.
+  ACCESS               integer      default 0 not null,
+  SCHEDULE_OBJECT      boolean      default false not null,
+  SCHEDULE_TAG         varchar(36)  default null,
+  SCHEDULE_ETAGS       text         default null,
+  PRIVATE_COMMENTS     boolean      default false not null,
+  MD5                  char(32)     not null,
+  CREATED              timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED             timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+
+  unique(CALENDAR_RESOURCE_ID, RESOURCE_NAME)
+
+  -- since the 'inbox' is a 'calendar resource' for the purpose of storing
+  -- calendar objects, this constraint has to be selectively enforced by the
+  -- application layer.
+
+  -- unique(CALENDAR_RESOURCE_ID, ICALENDAR_UID)
+);
+
+create index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID on
+  CALENDAR_OBJECT(CALENDAR_RESOURCE_ID);
+
+create index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID_AND_ICALENDAR_UID on
+  CALENDAR_OBJECT(CALENDAR_RESOURCE_ID, ICALENDAR_UID);
+ 
+create index CALENDAR_OBJECT_CALENDAR_RESOURCE_ID_RECURRANCE_MAX on
+  CALENDAR_OBJECT(CALENDAR_RESOURCE_ID, RECURRANCE_MAX);
+
+create index CALENDAR_OBJECT_ORGANIZER_OBJECT on
+  CALENDAR_OBJECT(ORGANIZER_OBJECT);
+
+create index CALENDAR_OBJECT_DROPBOX_ID on
+  CALENDAR_OBJECT(DROPBOX_ID);
+
+-- Enumeration of attachment modes
+
+create table CALENDAR_OBJECT_ATTACHMENTS_MODE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into CALENDAR_OBJECT_ATTACHMENTS_MODE values (0, 'none' );
+insert into CALENDAR_OBJECT_ATTACHMENTS_MODE values (1, 'read' );
+insert into CALENDAR_OBJECT_ATTACHMENTS_MODE values (2, 'write');
+
+
+-- Enumeration of calendar access types
+
+create table CALENDAR_ACCESS_TYPE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(32) not null unique
+);
+
+insert into CALENDAR_ACCESS_TYPE values (0, ''             );
+insert into CALENDAR_ACCESS_TYPE values (1, 'public'       );
+insert into CALENDAR_ACCESS_TYPE values (2, 'private'      );
+insert into CALENDAR_ACCESS_TYPE values (3, 'confidential' );
+insert into CALENDAR_ACCESS_TYPE values (4, 'restricted'   );
+
+-----------------
+-- Instance ID --
+-----------------
+
+create sequence INSTANCE_ID_SEQ;
+
+
+----------------
+-- Time Range --
+----------------
+
+create table TIME_RANGE (
+  INSTANCE_ID                 integer        primary key default nextval('INSTANCE_ID_SEQ'),
+  CALENDAR_RESOURCE_ID        integer        not null references CALENDAR on delete cascade,
+  CALENDAR_OBJECT_RESOURCE_ID integer        not null references CALENDAR_OBJECT on delete cascade,
+  FLOATING                    boolean        not null,
+  START_DATE                  timestamp      not null,
+  END_DATE                    timestamp      not null,
+  FBTYPE                      integer        not null,
+  TRANSPARENT                 boolean        not null
+);
+
+create index TIME_RANGE_CALENDAR_RESOURCE_ID on
+  TIME_RANGE(CALENDAR_RESOURCE_ID);
+create index TIME_RANGE_CALENDAR_OBJECT_RESOURCE_ID on
+  TIME_RANGE(CALENDAR_OBJECT_RESOURCE_ID);
+
+
+-- Enumeration of free/busy types
+
+create table FREE_BUSY_TYPE (
+  ID          integer     primary key,
+  DESCRIPTION varchar(16) not null unique
+);
+
+insert into FREE_BUSY_TYPE values (0, 'unknown'         );
+insert into FREE_BUSY_TYPE values (1, 'free'            );
+insert into FREE_BUSY_TYPE values (2, 'busy'            );
+insert into FREE_BUSY_TYPE values (3, 'busy-unavailable');
+insert into FREE_BUSY_TYPE values (4, 'busy-tentative'  );
+
+
+------------------
+-- Transparency --
+------------------
+
+create table TRANSPARENCY (
+  TIME_RANGE_INSTANCE_ID      integer      not null references TIME_RANGE on delete cascade,
+  USER_ID                     varchar(255) not null,
+  TRANSPARENT                 boolean      not null
+);
+
+create index TRANSPARENCY_TIME_RANGE_INSTANCE_ID on
+  TRANSPARENCY(TIME_RANGE_INSTANCE_ID);
+
+----------------
+-- Attachment --
+----------------
+
+create table ATTACHMENT (
+  CALENDAR_HOME_RESOURCE_ID   integer       not null references CALENDAR_HOME,
+  DROPBOX_ID                  varchar(255)  not null,
+  CONTENT_TYPE                varchar(255)  not null,
+  SIZE                        integer       not null,
+  MD5                         char(32)      not null,
+  CREATED                     timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                    timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  PATH                        varchar(1024) not null,
+
+  unique(DROPBOX_ID, PATH)
+);
+
+create index ATTACHMENT_DROPBOX_ID on ATTACHMENT(DROPBOX_ID);
+
+
+-----------------------
+-- Resource Property --
+-----------------------
+
+create table RESOURCE_PROPERTY (
+  RESOURCE_ID integer      not null, -- foreign key: *.RESOURCE_ID
+  NAME        varchar(255) not null,
+  VALUE       text         not null, -- FIXME: xml?
+  VIEWER_UID  varchar(255),
+
+  primary key(RESOURCE_ID, NAME, VIEWER_UID)
+);
+
+
+----------------------
+-- AddressBook Home --
+----------------------
+
+create table ADDRESSBOOK_HOME (
+  RESOURCE_ID      integer      primary key default nextval('RESOURCE_ID_SEQ'),
+  OWNER_UID        varchar(255) not null unique
+);
+
+create index ADDRESSBOOK_HOME_OWNER_UID on ADDRESSBOOK_HOME(OWNER_UID);
+
+--------------------------------
+-- AddressBook Home Meta-data --
+--------------------------------
+
+create table ADDRESSBOOK_HOME_METADATA (
+  RESOURCE_ID      integer      not null references ADDRESSBOOK_HOME on delete cascade,
+  QUOTA_USED_BYTES integer      default 0 not null
+);
+
+create index ADDRESSBOOK_HOME_METADATA_RESOURCE_ID
+    on ADDRESSBOOK_HOME_METADATA(RESOURCE_ID);
+
+-----------------
+-- AddressBook --
+-----------------
+
+create table ADDRESSBOOK (
+  RESOURCE_ID integer   primary key default nextval('RESOURCE_ID_SEQ'),
+  CREATED     timestamp default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED    timestamp default timezone('UTC', CURRENT_TIMESTAMP)
+);
+
+
+----------------------
+-- AddressBook Bind --
+----------------------
+
+-- Joins ADDRESSBOOK_HOME and ADDRESSBOOK
+
+create table ADDRESSBOOK_BIND (
+  ADDRESSBOOK_HOME_RESOURCE_ID integer      not null references ADDRESSBOOK_HOME,
+  ADDRESSBOOK_RESOURCE_ID      integer      not null references ADDRESSBOOK on delete cascade,
+
+  -- An invitation which hasn't been accepted yet will not yet have a resource
+  -- name, so this field may be null.
+
+  ADDRESSBOOK_RESOURCE_NAME    varchar(255),
+  BIND_MODE                    integer      not null, -- enum CALENDAR_BIND_MODE
+  BIND_STATUS                  integer      not null, -- enum CALENDAR_BIND_STATUS
+  SEEN_BY_OWNER                boolean      not null,
+  SEEN_BY_SHAREE               boolean      not null,
+  MESSAGE                      text,                  -- FIXME: xml?
+
+  primary key(ADDRESSBOOK_HOME_RESOURCE_ID, ADDRESSBOOK_RESOURCE_ID),
+  unique(ADDRESSBOOK_HOME_RESOURCE_ID, ADDRESSBOOK_RESOURCE_NAME)
+);
+
+create index ADDRESSBOOK_BIND_HOME_RESOURCE_ID on
+  ADDRESSBOOK_BIND(ADDRESSBOOK_HOME_RESOURCE_ID);
+create index ADDRESSBOOK_BIND_RESOURCE_ID on
+  ADDRESSBOOK_BIND(ADDRESSBOOK_RESOURCE_ID);
+
+create table ADDRESSBOOK_OBJECT (
+  RESOURCE_ID             integer      primary key default nextval('RESOURCE_ID_SEQ'),
+  ADDRESSBOOK_RESOURCE_ID integer      not null references ADDRESSBOOK on delete cascade,
+  RESOURCE_NAME           varchar(255) not null,
+  VCARD_TEXT              text         not null,
+  VCARD_UID               varchar(255) not null,
+  MD5                     char(32)     not null,
+  CREATED                 timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+  MODIFIED                timestamp    default timezone('UTC', CURRENT_TIMESTAMP),
+
+  unique(ADDRESSBOOK_RESOURCE_ID, RESOURCE_NAME),
+  unique(ADDRESSBOOK_RESOURCE_ID, VCARD_UID)
+);
+
+create index ADDRESSBOOK_OBJECT_ADDRESSBOOK_RESOURCE_ID on
+  ADDRESSBOOK_OBJECT(ADDRESSBOOK_RESOURCE_ID);
+
+---------------
+-- Revisions --
+---------------
+
+create sequence REVISION_SEQ;
+
+
+---------------
+-- Revisions --
+---------------
+
+create table CALENDAR_OBJECT_REVISIONS (
+  CALENDAR_HOME_RESOURCE_ID integer      not null references CALENDAR_HOME,
+  CALENDAR_RESOURCE_ID      integer      references CALENDAR,
+  CALENDAR_NAME             varchar(255) default null,
+  RESOURCE_NAME             varchar(255),
+  REVISION                  integer      default nextval('REVISION_SEQ') not null,
+  DELETED                   boolean      not null,
+
+  unique(CALENDAR_RESOURCE_ID, RESOURCE_NAME)
+);
+
+
+create index CALENDAR_OBJECT_REVISIONS_HOME_RESOURCE_ID
+  on CALENDAR_OBJECT_REVISIONS(CALENDAR_HOME_RESOURCE_ID);
+
+create index CALENDAR_OBJECT_REVISIONS_RESOURCE_ID
+  on CALENDAR_OBJECT_REVISIONS(CALENDAR_RESOURCE_ID);
+
+
+-------------------------------
+-- AddressBook Object Revisions --
+-------------------------------
+
+create table ADDRESSBOOK_OBJECT_REVISIONS (
+  ADDRESSBOOK_HOME_RESOURCE_ID integer      not null references ADDRESSBOOK_HOME,
+  ADDRESSBOOK_RESOURCE_ID      integer      references ADDRESSBOOK,
+  ADDRESSBOOK_NAME             varchar(255) default null,
+  RESOURCE_NAME                varchar(255),
+  REVISION                     integer      default nextval('REVISION_SEQ') not null,
+  DELETED                      boolean      not null,
+
+  unique(ADDRESSBOOK_RESOURCE_ID, RESOURCE_NAME)
+);
+
+create index ADDRESSBOOK_OBJECT_REVISIONS_HOME_RESOURCE_ID
+  on ADDRESSBOOK_OBJECT_REVISIONS(ADDRESSBOOK_HOME_RESOURCE_ID);
+
+create index ADDRESSBOOK_OBJECT_REVISIONS_RESOURCE_ID
+  on ADDRESSBOOK_OBJECT_REVISIONS(ADDRESSBOOK_RESOURCE_ID);
+
+-----------------------------------
+-- Notification Object Revisions --
+-----------------------------------
+
+create table NOTIFICATION_OBJECT_REVISIONS (
+  NOTIFICATION_HOME_RESOURCE_ID integer      not null references NOTIFICATION_HOME on delete cascade,
+  RESOURCE_NAME                 varchar(255),
+  REVISION                      integer      default nextval('REVISION_SEQ') not null,
+  DELETED                       boolean      not null,
+
+  unique(NOTIFICATION_HOME_RESOURCE_ID, RESOURCE_NAME)
+);
+
+
+create index NOTIFICATION_OBJECT_REVISIONS_HOME_RESOURCE_ID
+  on NOTIFICATION_OBJECT_REVISIONS(NOTIFICATION_HOME_RESOURCE_ID);
+
+
+--------------------
+-- Schema Version --
+--------------------
+
+create table CALENDARSERVER (
+  NAME                          varchar(255),
+  VALUE                         varchar(255),
+  unique(NAME)
+);
+
+insert into CALENDARSERVER values ('VERSION', '3');
+

Added: 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	                        (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_from_3_to_4.sql	2011-08-25 14:32:53 UTC (rev 8015)
@@ -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';
+

Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_template.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_template.sql	2011-08-25 02:29:22 UTC (rev 8014)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema/upgrades/upgrade_template.sql	2011-08-25 14:32:53 UTC (rev 8015)
@@ -14,6 +14,13 @@
 -- limitations under the License.
 ----
 
+-- The file name must be of the form:
+--
+-- upgrade_from_X_to_Y.sql
+--
+-- where X is the start version number, and Y the end version
+-- number for the upgrade 
+
 -------------------------------------------------
 -- Upgrade database schema from VERSION X to Y --
 -------------------------------------------------

Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py	2011-08-25 02:29:22 UTC (rev 8014)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql_tables.py	2011-08-25 14:32:53 UTC (rev 8015)
@@ -30,6 +30,7 @@
 from twext.enterprise.dal.parseschema import addSQLToSchema
 from twext.enterprise.dal.model import Schema
 from twext.enterprise.dal.syntax import SchemaSyntax
+from twisted.python.modules import getModule
 from twisted.trial.unittest import TestCase
 
 class SampleSomeColumns(TestCase):
@@ -58,10 +59,17 @@
         """
         _translateSchema includes 'insert' rows too.
         """
+        
+        pathObj = getModule(__name__).filePath.parent().sibling("sql_schema").child("current.sql")
+        schema = pathObj.getContent()
+        pos = schema.find("('VERSION', '")
+        version = int(schema[pos+13])
+        
         io = StringIO()
         _translateSchema(io)
+        
         self.assertIn("insert into CALENDARSERVER (NAME, VALUE) "
-                      "values ('VERSION', '3');",
+                      "values ('VERSION', '%s');" % version,
                       io.getvalue())
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110825/f013c186/attachment-0001.html>


More information about the calendarserver-changes mailing list