Add default value for id and __id for issue880

Create sequence for history table
This commit is contained in:
Cédric Krier committed 2009-03-20 01:42:34 +01:00
1 parent 89baf71cf7
commit 1bd5fe4439
2 files changed
+14 -4

No files matched your search

+10 -3
View File
@@ -18,8 +18,7 @@ class TableHandler(TableHandlerInterface):
self._field2module = {}
# Create sequence if necessary
if not self.history and \
not self.sequence_exist(self.cursor, self.sequence_name):
if not self.sequence_exist(self.cursor, self.sequence_name):
self.cursor.execute('CREATE SEQUENCE "%s"' % self.sequence_name)
# Create new table if necessary
@@ -39,9 +38,17 @@ class TableHandler(TableHandlerInterface):
self._update_definitions()
if self.history and not '__id' in self._columns:
self.cursor.execute('ALTER TABLE "%s" ' \
'ADD COLUMN __id SERIAL NOT NULL' % self.table_name)
'ADD COLUMN __id INTEGER NOT NULL' % self.table_name)
self.cursor.execute('ALTER TABLE "%s" ' \
'ADD PRIMARY KEY(__id)' % self.table_name)
if self.history:
self.cursor.execute('ALTER TABLE "%s" ' \
'ALTER __id SET DEFAULT nextval(\'%s\')' % (self.table_name,
self.sequence_name))
else:
self.cursor.execute('ALTER TABLE "%s" ' \
'ALTER id SET DEFAULT nextval(\'%s\')' % (self.table_name,
self.sequence_name))
@staticmethod
def table_exist(cursor, table_name):
+4 -1
View File
@@ -21,7 +21,10 @@ class TableHandlerInterface(object):
else:
self.table_name = model._table
self.object_name = model._name
self.sequence_name = model._sequence
if history:
self.sequence_name = self.table_name + '___id_seq'
else:
self.sequence_name = model._sequence
self.module_name = module_name
self.history = history