def test_run_migrations(self): migrate.run_migrations( self.layer.app, migrate.get_migrations('foobar')) site = self.layer.app['plone']['plone'] registry = site['_registry'] self.assertEquals(registry[MIGRATION_DATA_REGISTRY_KEY]['foobar'], '2.1a1')
def test_run_migrations(self): migrate.run_migrations(self.layer.app, migrate.get_migrations('foobar')) site = self.layer.app['plone']['plone'] registry = site['_registry'] self.assertEquals(registry[MIGRATION_DATA_REGISTRY_KEY]['foobar'], '2.1a1')
def test_get_migrations_from_version(self): self.assertEqual( [m.to_version_raw for m in migrate.get_migrations('foobar', '1.0')], [ '1.0.1a1', '1.5.0', '2.1a1' ])
def test_get_migrations_to_version(self): self.assertEqual( [m.to_version_raw for m in migrate.get_migrations('foobar', to_version='1.0')], [ '0.2', '0.5', '1.0a1', '1.0a9.dev0', '1.0' ])
def test_get_migrations_for_application_in_order(self): self.assertEqual( [m.to_version_raw for m in migrate.get_migrations('foobar')], [ '0.2', '0.5', '1.0a1', '1.0a9.dev0', '1.0', '1.0.1a1', '1.5.0', '2.1a1' ])
def run(self, arguments, settings, app): app_settings['root_user']['password'] = TESTING_SETTINGS['root_user']['password'] root = getUtility(IApplication, name='root') # get sites to run command against if arguments.site: sites = { arguments.site: traverse_to_path(app, arguments.site) } else: sites = {} for _id, db in root: if IDatabase.providedBy(db): for s_id in db.keys(): sites['/' + _id + '/' + s_id] = (db, db[s_id]) if len(sites) == 0: print('No sites found') if arguments.app: apps = [arguments.app] else: apps = migrate.get_migratable_applications() if not arguments.report: # run them... for db, site in sites.values(): for app in apps: registry = site['_registry'] try: installed_versions = registry[MIGRATION_DATA_REGISTRY_KEY] except KeyError: installed_versions = {} _migrations = migrate.get_migrations( app, to_version=arguments.to_version, from_version=installed_versions.get(app)) if len(_migrations) > 0: trns = db.get_transaction_manager() if not arguments.dry_run and not arguments.report: trns.begin() migrate.run_site_migrations(site, _migrations, db) if not arguments.dry_run and not arguments.report: trns.commit() self.report(arguments, sites, apps)
def report(self, arguments, sites, apps): for site_path, data in sites.items(): db, site = data registry = site['_registry'] try: installed_versions = registry[MIGRATION_DATA_REGISTRY_KEY] except KeyError: installed_versions = {} title = '{} Migrations'.format(site_path) print('\n\n') print(title) print('=' * len(title)) print('{0:<20}{1:<40}{2:<60}'.format( 'application', 'installed', 'available' )) print('{0:<20}{1:<40}{2:<60}'.format( '-' * len('application'), '-' * len('installed'), '-' * len('available') )) for app in apps: _migrations = migrate.get_migrations( app, to_version=arguments.to_version, from_version=installed_versions.get(app)) version = upgrade_to = None if len(_migrations) > 0: upgrade_to = _migrations[-1].to_version_raw if app in installed_versions: version = installed_versions[app] if version or upgrade_to: items = [app] if version: items.append(version) else: items.append('-') if upgrade_to: items.append('{}({} migrations)'.format( upgrade_to, len(_migrations) )) else: items.append('-') print('{0:<20}{1:<40}{2:<60}'.format(*items))
def test_should_only_get_migrations_for_activated_applications(self): self.assertEqual(len(migrate.get_migrations('foobar')), 8) app_settings['applications'] = [] self.assertEqual(len(migrate.get_migrations('foobarother')), 0) self.assertEqual(len(migrate.get_migrations('foobar')), 0)
def test_get_migrations_to_version(self): self.assertEqual([ m.to_version_raw for m in migrate.get_migrations('foobar', to_version='1.0') ], ['0.2', '0.5', '1.0a1', '1.0a9.dev0', '1.0'])
def test_get_migrations_from_version(self): self.assertEqual([ m.to_version_raw for m in migrate.get_migrations('foobar', '1.0') ], ['1.0.1a1', '1.5.0', '2.1a1'])
def test_get_migrations_for_application(self): self.assertEqual(len(migrate.get_migrations('foobar')), 8)