Permalink
Browse files

Merge pull request #2 from jewelia/master

Let's add my changes from "The Great WL Data Migration of 2012"
  • Loading branch information...
2 parents 6697f09 + 1e15a4d commit a8c838b3142744dbbbc6e4cdeed0248f3842b311 @shazow committed Jul 15, 2012
Showing with 5 additions and 4 deletions.
  1. +5 −4 sqlalchemygrate/migrations.py
@@ -53,14 +53,15 @@ def table_migrate(e1, e2, table, table2=None, convert_fn=None, limit=100000):
if convert_fn:
r = []
for row in data:
- converted = convert_fn(table, row)
+ converted = convert_fn(row=row, old_table=table, new_table=table2)
if isinstance(converted, types.GeneratorType):
r += list(converted)
- else:
+ elif converted is not None:
r.append(converted)
data = r
- e2.execute(table2.insert(), data).close()
+ if data:
+ e2.execute(table2.insert(), data).close()
log.debug("-> Inserted {0} rows into: {1}".format(len(data), table2.name))
@@ -150,7 +151,7 @@ def migrate(e1, e2, metadata, convert_map=None, populate_fn=None, only_tables=No
if callable(populate_fn):
log.info("Running populate function.")
- populate_fn(metadata_from=metadata_old, metadata_to=metadata)
+ populate_fn(metadata_from=metadata_old, metadata_to=metadata_new)
for table in metadata_old.sorted_tables:
table_name = table.name

0 comments on commit a8c838b

Please sign in to comment.