Exemplo n.º 1
0
def run_evolve(*args):
    description = """\
    Run evolve script(s) to make changes to the database when the application is upgraded.  Example:
    'evolve development.ini'
    """
    usage = "usage: %prog config_uri"
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description)
        )
    options, args = parser.parse_args(sys.argv[1:])
    if not len(args) >= 1:
        print('You must provide at least one argument')
        return 2
    config_uri = args[0]
    env = bootstrap(config_uri)
    root = env['root']
    try:
        manager = ZODBEvolutionManager(root, evolve_packagename = 'madetomeasure.evolve',
                                       sw_version = VERSION,
                                       initial_db_version = 0)
        ver = manager.get_db_version()
        if ver < VERSION:
            evolve_to_latest(manager)
            print 'Evolved from %s to %s' % (ver, manager.get_db_version())
        else:
            print 'Already evolved to latest version'
    finally:
        env['closer']
Exemplo n.º 2
0
    def test_check_database_config_outdated(self, mock):
        from papaye import check_database_config
        root = self.get_root()
        manager = ZODBEvolutionManager(root,
                                       evolve_packagename='papaye.evolve',
                                       sw_version=1,
                                       initial_db_version=0)
        manager.sw_version = 1
        mock.return_value = manager

        from pyramid.config import ConfigurationError
        self.assertRaises(ConfigurationError, check_database_config,
                          self.config)
Exemplo n.º 3
0
    def test_check_database_config_outdated(self, mock):
        from papaye import check_database_config
        root = self.get_root()
        manager = ZODBEvolutionManager(
            root,
            evolve_packagename='papaye.evolve',
            sw_version=1,
            initial_db_version=0
        )
        manager.sw_version = 1
        mock.return_value = manager

        from pyramid.config import ConfigurationError
        self.assertRaises(ConfigurationError, check_database_config, self.config)
Exemplo n.º 4
0
def appmaker(zodb_root):
    try:
        return zodb_root['app_root']
    except KeyError:
        from repoze.evolution import ZODBEvolutionManager
        from madetomeasure.evolve import VERSION
        root = bootstrap_root()
        zodb_root['app_root'] = root
        import transaction
        transaction.commit()
        manager = ZODBEvolutionManager(root, evolve_packagename = 'madetomeasure.evolve', sw_version = VERSION)
        manager.set_db_version(VERSION)
        manager.transaction.commit()
        return root
Exemplo n.º 5
0
def main(argv=sys.argv):
    worker = ScriptWorker('evolve')
    root = worker.root
    
    print 'Evolve site'
    print "\n"
    manager = ZODBEvolutionManager(root, evolve_packagename='voteit.core.evolve', sw_version=VERSION, initial_db_version=0)
    ver = manager.get_db_version()
    if ver < VERSION:
        evolve_to_latest(manager)
        print 'Evolved from %s to %s' % (ver, manager.get_db_version())
    else:
        print 'Already evolved to latest version'
    
    worker.shutdown()
Exemplo n.º 6
0
def evolve_database(root, sw_version, initial_db_version=0):
    from repoze.evolution import ZODBEvolutionManager, evolve_to_latest
    manager = ZODBEvolutionManager(
        root, evolve_packagename='pyGallerid.evolve',
        sw_version=sw_version,
        initial_db_version=initial_db_version
    )
    db_version = manager.get_db_version()
    sw_version = manager.get_sw_version()
    if db_version < sw_version:
        logger.info('Evolving database from %d to %d ...' \
                    % (db_version, sw_version))
    evolve_to_latest(manager)
    if db_version < sw_version:
        logger.info('Finished evolving of the database.')
Exemplo n.º 7
0
def get_manager(config):
    conn = config.registry._zodb_databases[''].open()
    root = conn.root()[APP_ROOT_NAME]
    manager = ZODBEvolutionManager(root,
                                   evolve_packagename='papaye.evolve',
                                   sw_version=SW_VERSION,
                                   initial_db_version=0)
    return manager
Exemplo n.º 8
0
 def test_check_database_config(self, mock):
     from papaye import check_database_config
     root = self.get_root()
     mock.return_value = ZODBEvolutionManager(
         root,
         evolve_packagename='papaye.evolve',
         sw_version=0,
         initial_db_version=0)
     result = check_database_config(self.config)
     self.assertTrue(result)
Exemplo n.º 9
0
def appmaker(zodb_root):
    """ This determines the root object for each request. If no site root exists,
        this function will run bootstrap_voteit and create one.
        Read more about traversal in the Pyramid docs.
        
        The funny looking try / except here is to bootstrap the site in case it hasn't been bootstrapped.
        This is faster than using an if statement.
    """
    try:
        return zodb_root['app_root']
    except KeyError:
        from voteit.core.bootstrap import bootstrap_voteit
        zodb_root['app_root'] = bootstrap_voteit() #Returns a site root
        import transaction
        transaction.commit()
        #Set intitial version of database
        from repoze.evolution import ZODBEvolutionManager
        from voteit.core.evolve import VERSION
        manager = ZODBEvolutionManager(zodb_root['app_root'], evolve_packagename='voteit.core.evolve', sw_version=VERSION)
        manager.set_db_version(VERSION)
        manager.transaction.commit()
        return zodb_root['app_root']
Exemplo n.º 10
0
def appmaker(zodb_root):
    """ This determines the root object for each request. If no site root exists,
        this function will run bootstrap_voteit and create one.
        Read more about traversal in the Pyramid docs.
        
        The funny looking try / except here is to bootstrap the site in case it hasn't been bootstrapped.
        This is faster than using an if statement.
    """
    try:
        return zodb_root['app_root']
    except KeyError:
        from voteit.core.bootstrap import bootstrap_voteit
        zodb_root['app_root'] = bootstrap_voteit()  #Returns a site root
        import transaction
        transaction.commit()
        #Set intitial version of database
        from repoze.evolution import ZODBEvolutionManager
        from voteit.core.evolve import VERSION
        manager = ZODBEvolutionManager(zodb_root['app_root'],
                                       evolve_packagename='voteit.core.evolve',
                                       sw_version=VERSION)
        manager.set_db_version(VERSION)
        manager.transaction.commit()
        return zodb_root['app_root']
Exemplo n.º 11
0
    def test_check_database_config_without_approot(self, mock):
        from papaye import check_database_config
        root = self.get_root()
        manager = ZODBEvolutionManager(root,
                                       evolve_packagename='papaye.evolve',
                                       sw_version=0,
                                       initial_db_version=0)
        mock.return_value = manager

        # Remove app_root
        del (self.config.registry._zodb_databases[''].open().root()
             ['papaye_root'])
        import transaction
        transaction.commit()

        from pyramid.config import ConfigurationError
        self.assertRaises(ConfigurationError, check_database_config,
                          self.config)