41
43
"schema-package": self._get_schema_package(store),
44
def setupDatabases(self, drop=False):
46
def setupDatabases(self, drop=True):
45
47
for data in self._databases:
46
48
name = data["database"]
53
55
name = data["database"]
54
56
self._dropDatabase(name)
58
def _getConnection(self):
59
return psycopg2.connect("dbname=template1")
56
61
def _dropDatabase(self, name):
57
os.system("dropdb %s > /dev/null 2>&1" % name)
63
connection = self._getConnection()
64
except psycopg2.OperationalError, error:
65
if "does not exist" in str(error):
70
connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
72
# Kill all backend connections if this helper happens to be
73
# available. We could create it if it doesn't exist if not
74
# always having this is a problem.
76
cursor = connection.cursor()
78
SELECT pg_terminate_backend(procpid)
80
WHERE procpid <> pg_backend_pid() AND datname=%s
82
except psycopg2.DatabaseError:
85
# Drop the database, trying for a number of seconds in case
86
# connections are slow in dropping off.
88
cursor = connection.cursor()
92
except psycopg2.DatabaseError, error:
93
if "does not exist" in str(error):
59
99
def _createDatabase(self, name):
60
os.system("createdb %s > /dev/null 2>&1" % name)
100
connection = self._getConnection()
102
connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
103
cursor = connection.cursor()
106
CREATE DATABASE "%s" TEMPLATE=template0 ENCODING='UNICODE'
108
# Try to ensure our cleanup gets invoked, even in
109
# the face of adversity such as the test suite
111
atexit.register(lambda: self._dropDatabase(name))
112
except psycopg2.DatabaseError, error:
113
if "already exists" in str(error):
62
121
def setupPatchStores(self, layer):
63
122
layer._old_patch_zstorm = queryUtility(IZStorm)