Fix creating new PostgreSQL database
PostgreSQL will rollback the entire transaction on errors. Change the code so that we know that columns created dynamically do not already exist.
This commit is contained in:
parent
a2b5c8e34c
commit
8f69201a70
@ -135,58 +135,47 @@ class DBAPI(DbGeneric):
|
|||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'given_name TEXT, '
|
'given_name TEXT, '
|
||||||
'surname TEXT, '
|
'surname TEXT, '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE family '
|
self.dbapi.execute('CREATE TABLE family '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'father_handle VARCHAR(50), '
|
|
||||||
'mother_handle VARCHAR(50), '
|
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE source '
|
self.dbapi.execute('CREATE TABLE source '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE citation '
|
self.dbapi.execute('CREATE TABLE citation '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE event '
|
self.dbapi.execute('CREATE TABLE event '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE media '
|
self.dbapi.execute('CREATE TABLE media '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE place '
|
self.dbapi.execute('CREATE TABLE place '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'enclosed_by VARCHAR(50), '
|
'enclosed_by VARCHAR(50), '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE repository '
|
self.dbapi.execute('CREATE TABLE repository '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE note '
|
self.dbapi.execute('CREATE TABLE note '
|
||||||
'('
|
'('
|
||||||
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
|
||||||
'gramps_id TEXT, '
|
|
||||||
'blob_data BLOB'
|
'blob_data BLOB'
|
||||||
')')
|
')')
|
||||||
self.dbapi.execute('CREATE TABLE tag '
|
self.dbapi.execute('CREATE TABLE tag '
|
||||||
@ -912,17 +901,8 @@ class DBAPI(DbGeneric):
|
|||||||
Citation, Media, Note, Tag):
|
Citation, Media, Note, Tag):
|
||||||
table_name = cls.__name__.lower()
|
table_name = cls.__name__.lower()
|
||||||
for field, schema_type, max_length in cls.get_secondary_fields():
|
for field, schema_type, max_length in cls.get_secondary_fields():
|
||||||
sql_type = self._sql_type(schema_type, max_length)
|
if field != 'handle':
|
||||||
try:
|
sql_type = self._sql_type(schema_type, max_length)
|
||||||
# test to see if it exists:
|
|
||||||
self.dbapi.execute("SELECT %s FROM %s LIMIT 1"
|
|
||||||
% (field, table_name))
|
|
||||||
LOG.info(" Table %s, field %s is up to date",
|
|
||||||
table_name, field)
|
|
||||||
except:
|
|
||||||
# if not, let's add it
|
|
||||||
LOG.info(" Table %s, field %s was added",
|
|
||||||
table_name, field)
|
|
||||||
self.dbapi.execute("ALTER TABLE %s ADD COLUMN %s %s"
|
self.dbapi.execute("ALTER TABLE %s ADD COLUMN %s %s"
|
||||||
% (table_name, field, sql_type))
|
% (table_name, field, sql_type))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user