Changeset - 8924ed0e4f36
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 15 years ago 2010-12-11 02:15:29
marcin@python-works.com
added current db version into rhodecode,
added auto versioning of newly created databases
4 files changed with 29 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rhodecode/__init__.py
Show inline comments
 
@@ -29,6 +29,7 @@
 

	
 
VERSION = (1, 1, 0, 'beta')
 
__version__ = '.'.join((str(each) for each in VERSION[:4]))
 
__dbversion__ = 1 #defines current db version for migrations
 

	
 
from rhodecode.lib.utils import get_current_revision
 
_rev = get_current_revision()
rhodecode/lib/db_manage.py
Show inline comments
 
@@ -80,6 +80,23 @@ class DbManage(object):
 
        meta.Base.metadata.create_all(checkfirst=checkfirst)
 
        log.info('Created tables for %s', self.dbname)
 

	
 

	
 

	
 
    def set_db_version(self):
 
        from rhodecode import __dbversion__
 
        from rhodecode.model.db import DbMigrateVersion
 
        try:
 
            ver = DbMigrateVersion()
 
            ver.version = __dbversion__
 
            ver.repository_id = 'rhodecode_db_migrations'
 
            ver.repository_path = 'versions'
 
            self.sa.add(ver)
 
            self.sa.commit()
 
        except:
 
            self.sa.rollback()
 
            raise
 
        log.info('db version set to: %s', __dbversion__)
 

	
 
    def admin_prompt(self, second=False):
 
        if not self.tests:
 
            import getpass
rhodecode/model/db.py
Show inline comments
 
@@ -3,7 +3,8 @@
 
    rhodecode.model.db
 
    ~~~~~~~~~~~~~~~~~~
 
    
 
    Database Models for RhodeCode    
 
    Database Models for RhodeCode
 
    
 
    :created_on: Apr 08, 2010
 
    :author: marcink
 
    :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>    
 
@@ -246,3 +247,11 @@ class CacheInvalidation(Base, BaseModel)
 

	
 
    def __repr__(self):
 
        return "<CacheInvalidation('%s:%s')>" % (self.cache_id, self.cache_key)
 

	
 
class DbMigrateVersion(Base, BaseModel):
 
    __tablename__ = 'db_migrate_version'
 
    __table_args__ = {'useexisting':True}
 
    repository_id = Column('repository_id', String(250), primary_key=True)
 
    repository_path = Column('repository_path', Text)
 
    version = Column('version', Integer)
 

	
rhodecode/websetup.py
Show inline comments
 
@@ -11,6 +11,7 @@ def setup_app(command, conf, vars):
 
    dbconf = conf['sqlalchemy.db1.url']
 
    dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'], tests=False)
 
    dbmanage.create_tables(override=True)
 
    dbmanage.set_db_version()
 
    dbmanage.config_prompt(None)
 
    dbmanage.create_default_user()
 
    dbmanage.admin_prompt()
0 comments (0 inline, 0 general)