Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let's add my changes from "The Great WL Data Migration of 2012" #2

Merged
merged 1 commit into from Jul 15, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions sqlalchemygrate/migrations.py
Expand Up @@ -53,14 +53,15 @@ def table_migrate(e1, e2, table, table2=None, convert_fn=None, limit=100000):
if convert_fn: if convert_fn:
r = [] r = []
for row in data: 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): if isinstance(converted, types.GeneratorType):
r += list(converted) r += list(converted)
else: elif converted is not None:
r.append(converted) r.append(converted)
data = r 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)) log.debug("-> Inserted {0} rows into: {1}".format(len(data), table2.name))




Expand Down Expand Up @@ -150,7 +151,7 @@ def migrate(e1, e2, metadata, convert_map=None, populate_fn=None, only_tables=No


if callable(populate_fn): if callable(populate_fn):
log.info("Running populate function.") 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: for table in metadata_old.sorted_tables:
table_name = table.name table_name = table.name
Expand Down