• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

Revision31cc45a051263f0351a4767bbda5ff469dda34a5 (tree)
Time2010-05-05 03:03:51
AuthorRick Copeland <rcopeland@geek...>
CommiterRick Copeland

Log Message

[#330] - add flyway options, as well as flyway initialization on project DB create

Change Summary

Incremental Difference

--- a/pyforge/flyway/command.py
+++ b/pyforge/flyway/command.py
@@ -22,11 +22,13 @@ class MigrateCommand(command.Command):
2222 parser.add_option('--log-level', dest='log_level', default='INFO')
2323 parser.add_option('--reset', dest='reset', action='store_true', default=False)
2424 parser.add_option('-d', '--dry-run', dest='dry_run', action='store_true', default=False)
25+ parser.add_option('-s', '--status', dest='status_only', action='store_true', default=False)
26+ parser.add_option('--force', dest='force', action='store_true', default=False)
2527
2628 def command(self):
2729 self._setup_logging()
2830 self._load_migrations()
29- from .runner import run_migration, reset_migration
31+ from .runner import run_migration, reset_migration, show_status, set_status
3032 parsed_connection_url = parse_uri(self.options.connection_url)
3133 if not parsed_connection_url['path']:
3234 parsed_connection_url['path'] += '/'
@@ -45,7 +47,11 @@ class MigrateCommand(command.Command):
4547 parsed_connection_url['port'])
4648 for ds in datastores:
4749 self.log.info('Migrate DB: %s', ds.database)
48- if self.options.reset:
50+ if self.options.status_only:
51+ show_status(ds)
52+ elif self.options.force:
53+ set_status(ds, self._target_versions())
54+ elif self.options.reset:
4955 reset_migration(ds, dry_run=self.options.dry_run)
5056 else:
5157 run_migration(ds, self._target_versions(), dry_run=self.options.dry_run)
--- a/pyforge/flyway/runner.py
+++ b/pyforge/flyway/runner.py
@@ -32,6 +32,31 @@ def run_migration(datastore, target_versions, dry_run):
3232 step.apply(info.versions)
3333 info.m.save()
3434
35+def show_status(datastore):
36+ # Get the migration status of the db
37+ session = MigrationInfo.__mongometa__.session
38+ session.bind = datastore
39+ info = MigrationInfo.m.get()
40+ if info is None:
41+ info = MigrationInfo.make({})
42+ for k,v in info.versions.iteritems():
43+ log.info('%s=%s', k, v)
44+
45+def set_status(datastore, target_versions):
46+ # Get the migration status of the db
47+ session = MigrationInfo.__mongometa__.session
48+ session.bind = datastore
49+ info = MigrationInfo.m.get()
50+ if info is None:
51+ info = MigrationInfo.make({})
52+ latest_versions = Migration.latest_versions()
53+ for k,v in target_versions.iteritems():
54+ cur = info.versions.get(k, -1)
55+ islatest = ' (LATEST)' if v == latest_versions[k] else ''
56+ log.info('FORCE %s=%s%s (current=%s)', k, v, islatest, cur)
57+ info.versions.update(target_versions)
58+ info.m.save()
59+
3560 def plan_migration(session, ormsession, info, target):
3661 '''Return the optimal list of graph.MigrationSteps to run in order to
3762 satisfy the target requirements'''
--- a/pyforge/pyforge/model/project.py
+++ b/pyforge/pyforge/model/project.py
@@ -147,6 +147,7 @@ class Neighborhood(MappedClass):
147147 + 'You can edit this description in the admin page'),
148148 database=database,
149149 is_root=True)
150+ p.configure_flyway_initial()
150151 with h.push_config(c, project=p, user=user):
151152 # Install default named roles (#78)
152153 role_owner = auth.ProjectRole(name='Owner')
@@ -466,6 +467,16 @@ class Project(MappedClass):
466467 project_users = uniq([r.user for r in self.roles if not r.user.username.startswith('*')])
467468 return project_users
468469
470+ def configure_flyway_initial(self):
471+ from flyway.model import MigrationInfo
472+ from flyway.migrate import Migration
473+ with h.push_config(c, project=self):
474+ mi = project_doc_session.get(MigrationInfo)
475+ if mi is None:
476+ mi = MigrationInfo.make({})
477+ mi.versions.update(Migration.latest_versions())
478+ project_doc_session.save(mi)
479+
469480 class AppConfig(MappedClass):
470481 class __mongometa__:
471482 session = project_orm_session