|
a/pyforge/flyway/runner.py |
|
b/pyforge/flyway/runner.py |
|
... |
|
... |
32 |
def plan_migration(session, info, target):
|
32 |
def plan_migration(session, info, target):
|
33 |
'''Return the optimal list of graph.MigrationSteps to run in order to
|
33 |
'''Return the optimal list of graph.MigrationSteps to run in order to
|
34 |
satisfy the target requirements'''
|
34 |
satisfy the target requirements'''
|
35 |
migrations = dict((k, v(session))
|
35 |
migrations = dict((k, v(session))
|
36 |
for k,v in Migration.migrations_registry.iteritems())
|
36 |
for k,v in Migration.migrations_registry.iteritems())
|
37 |
State, modules, states = graph.gen_migration_states(migrations)
|
37 |
g = graph.MigrationGraph(migrations)
|
38 |
state_index = graph.index_migration_states(modules, states)
|
38 |
return g.shortest_path(info.versions, target)
|
39 |
nodes = graph.build_graph(states, state_index, migrations)
|
|
|
40 |
start = dict((m, -1) for m in modules)
|
|
|
41 |
start.update(info.versions)
|
|
|
42 |
end_states = set(graph.states_with(target.items(), state_index))
|
|
|
43 |
start_node = [ n for n in nodes if State(**start) == n.data ][0]
|
|
|
44 |
end_nodes = set(n for n in nodes if n.data in end_states)
|
|
|
45 |
path = graph.shortest_path(nodes, start_node, end_nodes)
|
|
|
46 |
return [
|
|
|
47 |
s for s in path
|
|
|
48 |
if isinstance(s, graph.MigrateStep) ]
|
|
|
49 |
|
39 |
|
50 |
def reset_migration(datastore, dry_run):
|
40 |
def reset_migration(datastore, dry_run):
|
51 |
'''Reset the state of the database to non-version-controlled WITHOUT migrating
|
41 |
'''Reset the state of the database to non-version-controlled WITHOUT migrating
|
52 |
|
42 |
|
53 |
This is equivalent to setting all the versions to -1.'''
|
43 |
This is equivalent to setting all the versions to -1.'''
|