Changeset - 7ae66bddf48d
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 15 years ago 2010-11-27 16:12:26
marcin@python-works.com
fixed db manage, to work on other databases than sqlite
2 files changed with 14 insertions and 13 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/db_manage.py
Show inline comments
 
@@ -41,23 +41,25 @@ import logging
 
log = logging.getLogger(__name__)
 

	
 
class DbManage(object):
 
    def __init__(self, log_sql, dbname, root, tests=False):
 
        self.dbname = dbname
 
    def __init__(self, log_sql, dbconf, root, tests=False):
 
        self.dbname = dbconf.split('/')[-1]
 
        self.tests = tests
 
        self.root = root
 
        dburi = 'sqlite:////%s' % jn(self.root, self.dbname)
 
        engine = create_engine(dburi, echo=log_sql)
 
        self.dburi = dbconf
 
        engine = create_engine(self.dburi, echo=log_sql)
 
        init_model(engine)
 
        self.sa = meta.Session()
 
        self.db_exists = False
 

	
 
    def check_for_db(self, override):
 
        db_path = jn(self.root, self.dbname)
 
        log.info('checking for existing db in %s', db_path)
 
        if os.path.isfile(db_path):
 
            self.db_exists = True
 
            if not override:
 
                raise Exception('database already exists')
 
        if self.dburi.startswith('sqlite'):
 
            log.info('checking for existing db in %s', db_path)
 
            if os.path.isfile(db_path):
 

	
 
                self.db_exists = True
 
                if not override:
 
                    raise Exception('database already exists')
 

	
 
    def create_tables(self, override=False):
 
        """
rhodecode/websetup.py
Show inline comments
 
@@ -8,16 +8,15 @@ log = logging.getLogger(__name__)
 

	
 
def setup_app(command, conf, vars):
 
    """Place any commands to setup rhodecode here"""
 
    dbname = os.path.split(conf['sqlalchemy.db1.url'])[-1] 
 
    dbmanage = DbManage(log_sql=True, dbname=dbname, root=conf['here'],
 
                         tests=False)
 
    dbconf = conf['sqlalchemy.db1.url']
 
    dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'], tests=False)
 
    dbmanage.create_tables(override=True)
 
    dbmanage.config_prompt(None)
 
    dbmanage.create_default_user()
 
    dbmanage.admin_prompt()
 
    dbmanage.create_permissions()
 
    dbmanage.populate_default_permissions()
 
           
 

	
 
    load_environment(conf.global_conf, conf.local_conf, initial=True)
 

	
 

	
0 comments (0 inline, 0 general)