Fix creation of table to use the right sequence name

This commit is contained in:
Cédric Krier committed 2009-03-17 22:38:41 +01:00
1 parent ba8c21c1b0
commit 3cc8b4727d
7 files changed
+39 -27

No files matched your search

+17 -14
View File
@@ -8,31 +8,34 @@ import logging
class TableHandler(TableHandlerInterface):
def __init__(self, cursor, table_name, object_name=None, module_name=None,
history=False):
super(TableHandler, self).__init__(cursor, table_name,
object_name=object_name, module_name=module_name)
def __init__(self, cursor, model, module_name=None, history=False):
super(TableHandler, self).__init__(cursor, model,
module_name=module_name)
self._columns = {}
self._constraints = []
self._fk_deltypes = {}
self._indexes = {}
self._field2module = {}
# Create sequence if necessary
if not self.history and \
not self.sequence_exist(self.cursor, self.sequence_name):
self.cursor.execute('CREATE SEQUENCE "%s"' % self.sequence_name)
# Create new table if necessary
if not self.table_exist(self.cursor, self.table_name):
if not history:
self.cursor.execute('CREATE TABLE "%s" ' \
"(id SERIAL NOT NULL, " \
"PRIMARY KEY(id))"% self.table_name)
else:
self.cursor.execute('CREATE TABLE "%s" ' \
'(id INTEGER)' % self.table_name)
self.cursor.execute('CREATE TABLE "%s" ' \
'(id INTEGER NOT NULL)' % self.table_name)
if not self.history:
self.cursor.execute('ALTER TABLE "%s" ' \
'ADD PRIMARY KEY(id)' % self.table_name)
self._update_definitions()
if 'id' not in self._columns:
self.cursor.execute('ALTER TABLE "%s" ' \
'ADD COLUMN id SERIAL NOT NULL' % self.table_name)
self.cursor.execute('ALTER TABLE "%s" ' \
'ADD PRIMARY KEY(id)' % self.table_name)
'ADD COLUMN id INTEGER NOT NULL' % self.table_name)
if not self.history:
self.cursor.execute('ALTER TABLE "%s" ' \
'ADD PRIMARY KEY(id)' % self.table_name)
self._update_definitions()
@staticmethod
+14 -4
View File
@@ -7,13 +7,23 @@ class TableHandlerInterface(object):
Define generic interface to handle database table
'''
def __init__(self, cursor, table_name, object_name=None, module_name=None,
history=False):
def __init__(self, cursor, model, module_name=None, history=False):
'''
:param cursor: the database cursor
:param model: the Model linked to the table
:param module_name: the module name
:param history: a boolean to define if it is a history table
'''
super(TableHandlerInterface, self).__init__()
self.cursor = cursor
self.table_name = table_name
self.object_name = object_name
if history:
self.table_name = model._table + '__history'
else:
self.table_name = model._table
self.object_name = model._name
self.sequence_name = model._sequence
self.module_name = module_name
self.history = history
@staticmethod
def table_exist(cursor, table_name):
+2 -2
View File
@@ -246,7 +246,7 @@ class ActionReport(ModelSQL, ModelView):
def init(self, cursor, module_name):
super(ActionReport, self).init(cursor, module_name)
table = TableHandler(cursor, self._table, self._name, module_name)
table = TableHandler(cursor, self, module_name)
# Migration from 1.0 report_name_uniq has been removed
table.drop_constraint('report_name_uniq')
@@ -442,7 +442,7 @@ class ActionActWindowView(ModelSQL, ModelView):
def init(self, cursor, module_name):
super(ActionActWindowView, self).init(cursor, module_name)
table = TableHandler(cursor, self._table, self._name, module_name)
table = TableHandler(cursor, self, module_name)
# Migration from 1.0 remove multi
table.drop_column('multi')
+1 -1
View File
@@ -66,7 +66,7 @@ class Translation(ModelSQL, ModelView, Cacheable):
def init(self, cursor, module_name):
super(Translation, self).init(cursor, module_name)
table = TableHandler(cursor, self._table, self._name, module_name)
table = TableHandler(cursor, self, module_name)
table.index_action(['lang', 'type', 'name'], 'add')
table.index_action(['lang', 'type', 'name', 'src'], 'add')
+1 -1
View File
@@ -46,7 +46,7 @@ class View(ModelSQL, ModelView):
def init(self, cursor, module_name):
super(View, self).init(cursor, module_name)
table = TableHandler(cursor, self._table, self._name, module_name)
table = TableHandler(cursor, self, module_name)
# Migration from 1.0 arch no more required
table.not_null_action('arch', action='remove')
+2 -3
View File
@@ -59,10 +59,9 @@ class ModelSQL(ModelStorage):
return
# create/update table in the database
table = TableHandler(cursor, self._table, self._name, module_name)
table = TableHandler(cursor, self, module_name)
if self._history:
history_table = TableHandler(cursor, self._table + '__history',
None, module_name, history=True)
history_table = TableHandler(cursor, self, module_name, history=True)
datetime_field = FIELDS['datetime']
integer_field = FIELDS['integer']
logs = (
+2 -2
View File
@@ -144,7 +144,7 @@ class WorkflowInstance(ModelSQL, ModelView):
def init(self, cursor, module_name):
super(WorkflowInstance, self).init(cursor, module_name)
table = TableHandler(cursor, self._table, self._name, module_name)
table = TableHandler(cursor, self, module_name)
table.index_action(['res_id', 'res_type', 'state'], 'add')
table.index_action(['res_id', 'workflow'], 'add')
@@ -454,7 +454,7 @@ class WorkflowTrigger(ModelSQL, ModelView):
def init(self, cursor, module_name):
super(WorkflowTrigger, self).init(cursor, module_name)
table = TableHandler(cursor, self._table, self._name, module_name)
table = TableHandler(cursor, self, module_name)
table.index_action(['res_id', 'model'], 'add')
WorkflowTrigger()