|
a/pyforge/flyway/runner.py |
|
b/pyforge/flyway/runner.py |
|
... |
|
... |
5 |
from .model import MigrationInfo
|
5 |
from .model import MigrationInfo
|
6 |
from .migrate import Migration
|
6 |
from .migrate import Migration
|
7 |
from . import graph
|
7 |
from . import graph
|
8 |
|
8 |
|
9 |
log = logging.getLogger(__name__)
|
9 |
log = logging.getLogger(__name__)
|
|
|
10 |
|
|
|
11 |
MIGRATION_GRAPH = None
|
10 |
|
12 |
|
11 |
def run_migration(datastore, target_versions, dry_run):
|
13 |
def run_migration(datastore, target_versions, dry_run):
|
12 |
'''Attempt to migrate the database to a specific set of required
|
14 |
'''Attempt to migrate the database to a specific set of required
|
13 |
modules & versions.'''
|
15 |
modules & versions.'''
|
14 |
# Get the migration status of the db
|
16 |
# Get the migration status of the db
|
|
... |
|
... |
58 |
info.m.save()
|
60 |
info.m.save()
|
59 |
|
61 |
|
60 |
def plan_migration(session, ormsession, info, target):
|
62 |
def plan_migration(session, ormsession, info, target):
|
61 |
'''Return the optimal list of graph.MigrationSteps to run in order to
|
63 |
'''Return the optimal list of graph.MigrationSteps to run in order to
|
62 |
satisfy the target requirements'''
|
64 |
satisfy the target requirements'''
|
|
|
65 |
global MIGRATION_GRAPH
|
|
|
66 |
if MIGRATION_GRAPH is None:
|
63 |
migrations = dict((k, v(session, ormsession))
|
67 |
migrations = dict((k, v(session, ormsession))
|
64 |
for k,v in Migration.migrations_registry.iteritems())
|
68 |
for k,v in Migration.migrations_registry.iteritems())
|
65 |
g = graph.MigrationGraph(migrations)
|
69 |
MIGRATION_GRAPH = graph.MigrationGraph(migrations)
|
|
|
70 |
else:
|
|
|
71 |
MIGRATION_GRAPH.reset()
|
66 |
return g.shortest_path(info.versions, target)
|
72 |
return MIGRATION_GRAPH.shortest_path(info.versions, target)
|
67 |
|
73 |
|
68 |
def reset_migration(datastore, dry_run):
|
74 |
def reset_migration(datastore, dry_run):
|
69 |
'''Reset the state of the database to non-version-controlled WITHOUT migrating
|
75 |
'''Reset the state of the database to non-version-controlled WITHOUT migrating
|
70 |
|
76 |
|
71 |
This is equivalent to setting all the versions to -1.'''
|
77 |
This is equivalent to setting all the versions to -1.'''
|