support for SA 0.5.1.

Only postgres is working fully.

MySQL has 2 broken tests.

sqlite has about 4 broken tests.
This commit is contained in:
percious17 2009-01-19 23:39:53 +00:00
parent 88ab816187
commit cb624f15db
4 changed files with 46 additions and 11 deletions

View File

@ -22,7 +22,7 @@ class RawAlterTableVisitor(object):
if isinstance(ret,sa.Table): if isinstance(ret,sa.Table):
ret = ret.fullname ret = ret.fullname
return ret return ret
def _do_quote_table_identifier(self, identifier): def _do_quote_table_identifier(self, identifier):
return '"%s"'%identifier return '"%s"'%identifier
@ -81,12 +81,16 @@ class ANSIColumnGenerator(AlterTableVisitor,SchemaGenerator):
pks = table.primary_key pks = table.primary_key
colspec = self.get_column_specification(column) colspec = self.get_column_specification(column)
self.append(colspec) self.append(colspec)
if column.foreign_keys:
for fk in column.foreign_keys: # if column.foreign_keys:
self.append(";\n\t ") # self.append(" ")
self.add_foreignkey(fk.constraint) # for fk in column.foreign_keys:
else: # self.add_foreignkey(fk.constraint)
self.execute() # continue
# self.append(";\n\t ")
# self.define_foreign_key(fk.constraint)
# else:
self.execute()
def visit_table(self,table): def visit_table(self,table):
@ -283,14 +287,35 @@ class ANSIConstraintDropper(ANSIConstraintCommon):
def visit_migrate_foreign_key_constraint(self,*p,**k): def visit_migrate_foreign_key_constraint(self,*p,**k):
return self._visit_constraint(*p,**k) return self._visit_constraint(*p,**k)
def visit_migrate_check_constraint(self,*p,**k): def visit_migrate_check_constraint(self,*p,**k):
return self._visit_constraint(*p,**k) return self._visit_constraint(*p,**k)
class ANSIFKGenerator(AlterTableVisitor,SchemaGenerator):
"""Extends ansisql generator for column creation (alter table add col)"""
def __init__(self, *args, **kwargs):
self.fk = kwargs.get('fk', None)
if self.fk:
del kwargs['fk']
super(ANSIFKGenerator, self).__init__(*args, **kwargs)
def visit_column(self,column):
"""Create foreign keys for a column (table already exists); #32"""
if self.fk:
self.add_foreignkey(self.fk.constraint)
if self.buffer.getvalue() !='':
self.execute()
def visit_table(self,table):
pass
class ANSIDialect(object): class ANSIDialect(object):
columngenerator = ANSIColumnGenerator columngenerator = ANSIColumnGenerator
columndropper = ANSIColumnDropper columndropper = ANSIColumnDropper
schemachanger = ANSISchemaChanger schemachanger = ANSISchemaChanger
columnfkgenerator = ANSIFKGenerator
@classmethod @classmethod
def visitor(self,name): def visitor(self,name):

View File

@ -318,7 +318,14 @@ class ChangesetColumn(object):
table = _normalize_table(self,table) table = _normalize_table(self,table)
engine = table.bind engine = table.bind
visitorcallable = get_engine_visitor(engine,'columngenerator') visitorcallable = get_engine_visitor(engine,'columngenerator')
engine._run_visitor(visitorcallable,self,*args,**kwargs) engine._run_visitor(visitorcallable, self, *args,**kwargs)
#add in foreign keys
if self.foreign_keys:
for fk in self.foreign_keys:
visitorcallable = get_engine_visitor(engine,'columnfkgenerator')
engine._run_visitor(visitorcallable, self, fk=fk)
return self return self
def drop(self,table=None,*args,**kwargs): def drop(self,table=None,*args,**kwargs):

View File

@ -40,6 +40,7 @@ class TestAddDropColumn(fixture.DB):
def _assert_numcols(expected,type_): def _assert_numcols(expected,type_):
result = len(self.table.c) result = len(self.table.c)
self.assertEquals(result,expected, self.assertEquals(result,expected,
"# %s cols incorrect: %s != %s"%(type_,result,expected)) "# %s cols incorrect: %s != %s"%(type_,result,expected))
if not col_k.get('primary_key',None): if not col_k.get('primary_key',None):
@ -53,9 +54,11 @@ class TestAddDropColumn(fixture.DB):
# Changed: create/drop shouldn't mess with the objects # Changed: create/drop shouldn't mess with the objects
#_assert_numcols(expected,'object') #_assert_numcols(expected,'object')
# Detect # database cols via autoload # Detect # database cols via autoload
self.meta.clear() #self.meta.clear()
del self.meta.tables[self.table_name]
self.table=Table(self.table_name,self.meta,autoload=True) self.table=Table(self.table_name,self.meta,autoload=True)
_assert_numcols(expected,'database') _assert_numcols(expected,'database')
assert_numcols(1) assert_numcols(1)
if len(col_p) == 0: if len(col_p) == 0:
col_p = [String(40)] col_p = [String(40)]

View File

@ -42,7 +42,7 @@ def is_supported(url,supported,not_supported):
#we make the engines global, which should make the tests run a bit faster #we make the engines global, which should make the tests run a bit faster
urls = readurls() urls = readurls()
engines=dict([(url,create_engine(url)) for url in urls]) engines=dict([(url,create_engine(url, echo=True)) for url in urls])
def usedb(supported=None,not_supported=None): def usedb(supported=None,not_supported=None):