[CalendarServer-changes] [6034] CalendarServer/branches/users/glyph/sql-store
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 10 13:22:29 PDT 2010
Revision: 6034
http://trac.macosforge.org/projects/calendarserver/changeset/6034
Author: sagen at apple.com
Date: 2010-08-10 13:22:28 -0700 (Tue, 10 Aug 2010)
Log Message:
-----------
Reset the schema each unit test run, by dropping the caldav database.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/test/test_postgres.py
CalendarServer/branches/users/glyph/sql-store/txdav/datastore/subpostgres.py
Modified: CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/test/test_postgres.py
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/test/test_postgres.py 2010-08-10 17:27:34 UTC (rev 6033)
+++ CalendarServer/branches/users/glyph/sql-store/txcaldav/calendarstore/test/test_postgres.py 2010-08-10 20:22:28 UTC (rev 6034)
@@ -99,7 +99,8 @@
(md5(dbRoot.path).hexdigest()))
self.sharedService = PostgresService(
dbRoot, getReady, v1_schema, "caldav",
- socketDirectory=socketDirectory
+ socketDirectory=socketDirectory,
+ resetSchema=True
)
self.sharedService.startService()
def startStopping():
Modified: CalendarServer/branches/users/glyph/sql-store/txdav/datastore/subpostgres.py
===================================================================
--- CalendarServer/branches/users/glyph/sql-store/txdav/datastore/subpostgres.py 2010-08-10 17:27:34 UTC (rev 6033)
+++ CalendarServer/branches/users/glyph/sql-store/txdav/datastore/subpostgres.py 2010-08-10 20:22:28 UTC (rev 6034)
@@ -27,6 +27,7 @@
from twisted.python import log
pgdb = namedAny("pgdb")
+from pg import DatabaseError
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
@@ -154,7 +155,8 @@
class PostgresService(MultiService):
def __init__(self, dataStoreDirectory, subServiceFactory,
- schema, databaseName='subpostgres', socketDirectory=None):
+ schema, databaseName='subpostgres', socketDirectory=None,
+ resetSchema=False):
"""
Initialize a L{PostgresService} pointed at a data store directory.
@@ -168,6 +170,7 @@
MultiService.__init__(self)
self.subServiceFactory = subServiceFactory
self.dataStoreDirectory = dataStoreDirectory
+ self.resetSchema = resetSchema
if socketDirectory:
self.socketDir = socketDirectory
else:
@@ -217,6 +220,15 @@
)
createDatabaseCursor = createDatabaseConn.cursor()
createDatabaseCursor.execute("commit")
+
+ if self.resetSchema:
+ try:
+ createDatabaseCursor.execute(
+ "drop database %s" % (self.databaseName)
+ )
+ except DatabaseError:
+ pass
+
try:
createDatabaseCursor.execute(
"create database %s" % (self.databaseName)
@@ -225,14 +237,20 @@
execSchema = False
else:
execSchema = True
+
createDatabaseCursor.close()
createDatabaseConn.close()
+
if execSchema:
connection = self.produceConnection()
cursor = connection.cursor()
cursor.execute(self.schema)
connection.commit()
connection.close()
+
+ connection = self.produceConnection()
+ cursor = connection.cursor()
+
self.subServiceFactory(self.produceConnection).setServiceParent(self)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100810/48fc08f6/attachment.html>
More information about the calendarserver-changes
mailing list