Patches to work with SQ 0.4

2 views
Skip to first unread message

Christian Simms

unread,
Feb 13, 2008, 12:32:43 PM2/13/08
to migrate-users
I'm still getting up to speed on the code base, but I would like to
help. I got all the unit tests working with the four database
platforms, the patch is below (against svn version 380).

Cheers,
Christian





Index: test/changeset/test_changeset.py
===================================================================
--- test/changeset/test_changeset.py (revision 380)
+++ test/changeset/test_changeset.py (working copy)
@@ -188,7 +188,7 @@
meta = MetaData()

def setUp(self):
- self.meta.connect(self.engine)
+ self.meta.bind = self.engine #self.meta.connect(self.engine)

@fixture.usedb()
def test_rename_table(self):
Index: test/changeset/test_constraint.py
===================================================================
--- test/changeset/test_constraint.py (revision 380)
+++ test/changeset/test_constraint.py (working copy)
@@ -36,7 +36,8 @@
pk.name = 'fgsfds'
pk.create()
self.refresh_table()
- self.assertEquals(list(self.table.primary_key),list(cols))
+ if not self.url.startswith('sqlite'):
+
self.assertEquals(list(self.table.primary_key),list(cols))
#self.assert_(self.table.primary_key.name is not None)

# Drop the PK constraint
@@ -125,7 +126,8 @@
cons = PrimaryKeyConstraint(self.table.c.id)
cons.create()
self.refresh_table()
-
self.assertEquals(list(cons.columns),list(self.table.primary_key))
+ if not self.url.startswith('sqlite'):
+
self.assertEquals(list(cons.columns),list(self.table.primary_key))

# Remove the name, drop the constraint; it should succeed
cons.name = None
Index: migrate/changeset/ansisql.py
===================================================================
--- migrate/changeset/ansisql.py (revision 380)
+++ migrate/changeset/ansisql.py (working copy)
@@ -58,16 +58,15 @@

class ANSIColumnGenerator(AlterTableVisitor,SchemaGenerator):
"""Extends ansisql generator for column creation (alter table add
col)"""
- def __init__(self, *args, **kwargs):
- dialect = None
- if isinstance(args[0], Connection):
- dialect = args[0].engine.dialect
- elif isinstance(args[0], Dialect):
- dialect = args[0]
- else:
- raise exceptions.Error("Cannot infer dialect in
__init__")
- super(ANSIColumnGenerator, self).__init__(dialect, *args,
-**kwargs)
+ #def __init__(self, *args, **kwargs):
+ # dialect = None
+ # if isinstance(args[0], Connection):
+ # dialect = args[0].engine.dialect
+ # elif isinstance(args[0], Dialect):
+ # dialect = args[0]
+ # else:
+ # raise exceptions.Error("Cannot infer dialect in
__init__")
+ # super(ANSIColumnGenerator, self).__init__(dialect, *args,
**kwargs)

def visit_column(self,column):
"""Create a column (table already exists); #32"""
@@ -192,7 +191,8 @@
if not isinstance(type,sa.types.AbstractType):
# It's the class itself, not an instance... make an
instance
type = type()
- type_text = type.engine_impl(self.engine).get_col_spec()
+ #type_text = type.engine_impl(self.engine).get_col_spec()
+ type_text = type.dialect_impl(self.dialect).get_col_spec()
self.start_alter_table(table_name)
self.append("ALTER COLUMN %s TYPE %s"%(col_name,type_text))
def _visit_column_name(self,table_name,col_name,delta):
Index: migrate/changeset/databases/sqlite.py
===================================================================
--- migrate/changeset/databases/sqlite.py (revision 380)
+++ migrate/changeset/databases/sqlite.py (working copy)
@@ -33,7 +33,7 @@
msg = tmpl%(name,tname,cols)
self.append(msg)
self.execute()
-class SQLiteConstraintDropper(object):
+class SQLiteConstraintDropper(ansisql.ANSIColumnDropper):
def visit_migrate_primary_key_constraint(self,constraint):
tmpl = "DROP INDEX %s "
name = constraint.name
Index: migrate/changeset/databases/mysql.py
===================================================================
--- migrate/changeset/databases/mysql.py (revision 380)
+++ migrate/changeset/databases/mysql.py (working copy)
@@ -24,7 +24,9 @@
"A column object is required to do this")

column = delta.result_column
+ if not column.table: column.table = delta.table # needed by
get_column_specification
colspec = self.get_column_specification(column)
+ #colspec =
self.get_column_specification(delta.table.c[col_name])
self.start_alter_table(table_name)
self.append("CHANGE COLUMN ")
self.append(col_name)
Index: migrate/changeset/schema.py
===================================================================
--- migrate/changeset/schema.py (revision 380)
+++ migrate/changeset/schema.py (working copy)
@@ -27,7 +27,7 @@
# Given: table name, maybe an engine
meta = sqlalchemy.MetaData()
if engine is not None:
- meta.connect(engine)
+ meta.bind = engine #meta.connect(engine)
return sqlalchemy.Table(table,meta)
def _to_index(index,table=None,engine=None):
if isinstance(index,sqlalchemy.Index):
@@ -305,7 +305,11 @@
for column defaults, only PassiveDefaults are managed by the
database -
changing others doesn't make sense.
"""
- return alter_column(self,*p,**k)
+ if 'table' not in k:
+ k['table'] = self.table
+ if 'engine' not in k:
+ k['engine'] = k['table'].bind
+ return alter_column(self, *p,**k)

def create(self,table=None,*args,**kwargs):
"""Create this column in the database. Assumes the given
table exists.
@@ -324,7 +328,8 @@
table = _normalize_table(self,table)
engine = table.bind
visitorcallable = get_engine_visitor(engine,'columndropper')
- engine._run_visitor(visitorcallable,self,*args,**kwargs)
+ #engine._run_visitor(visitorcallable,self,*args,**kwargs)
+ engine._run_visitor(lambda dialect, conn:
visitorcallable(conn),self,*args,**kwargs)
## Remove col from table object, too
#del table._columns[self.key]
#if self in table.primary_key:

Jan Dittberner

unread,
Feb 14, 2008, 7:06:22 AM2/14/08
to migrat...@googlegroups.com
Thank you very much Christian,

I'll integrate your patch this evening (GMT+2:00)


Regards
Jan

Reply all
Reply to author
Forward
0 new messages