@@ -57,13 +57,14 @@ class DbManage(object):
def init_db(self):
engine = create_engine(self.dburi, echo=self.log_sql)
init_model(engine)
self.sa = meta.Session
def create_tables(self, override=False):
"""Create a auth database
"""
Create a auth database
log.info("Any existing database is going to be destroyed")
if self.tests:
destroy = True
else:
@@ -83,13 +84,14 @@ class DbManage(object):
ver.repository_id = 'rhodecode_db_migrations'
ver.repository_path = 'versions'
self.sa.add(ver)
log.info('db version set to: %s', __dbversion__)
def upgrade(self):
"""Upgrades given database schema to given revision following
Upgrades given database schema to given revision following
all needed steps, to perform the upgrade
from rhodecode.lib.dbmigrate.migrate.versioning import api
from rhodecode.lib.dbmigrate.migrate.exceptions import \
@@ -122,21 +124,22 @@ class DbManage(object):
sys.exit('This database is already at the newest version')
#======================================================================
# UPGRADE STEPS
class UpgradeSteps(object):
"""Those steps follow schema versions so for example schema
Those steps follow schema versions so for example schema
for example schema with seq 002 == step_2 and so on.
def __init__(self, klass):
self.klass = klass
def step_0(self):
#step 0 is the schema upgrade, and than follow proper upgrades
# step 0 is the schema upgrade, and than follow proper upgrades
print ('attempting to do database upgrade to version %s' \
% __dbversion__)
api.upgrade(db_uri, repository_path, __dbversion__)
print ('Schema upgrade completed')
def step_1(self):
@@ -157,19 +160,20 @@ class DbManage(object):
self.klass.fix_settings()
print ('Adding ldap defaults')
self.klass.create_ldap_options(skip_existing=True)
upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
#CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
# CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
for step in upgrade_steps:
print ('performing upgrade step %s' % step)
getattr(UpgradeSteps(self), 'step_%s' % step)()
def fix_repo_paths(self):
"""Fixes a old rhodecode version path into new one without a '*'
Fixes a old rhodecode version path into new one without a '*'
paths = self.sa.query(RhodeCodeUi)\
.filter(RhodeCodeUi.ui_key == '/')\
.scalar()
@@ -180,13 +184,14 @@ class DbManage(object):
self.sa.commit()
except:
self.sa.rollback()
raise
def fix_default_user(self):
"""Fixes a old default user with some 'nicer' default values,
Fixes a old default user with some 'nicer' default values,
used mostly for anonymous access
def_user = self.sa.query(User)\
.filter(User.username == 'default')\
.one()
@@ -199,13 +204,14 @@ class DbManage(object):
def fix_settings(self):
"""Fixes rhodecode settings adds ga_code key for google analytics
Fixes rhodecode settings adds ga_code key for google analytics
hgsettings3 = RhodeCodeSetting('ga_code', '')
try:
self.sa.add(hgsettings3)
@@ -243,31 +249,32 @@ class DbManage(object):
email = raw_input('Specify admin email:')
self.create_user(username, password, email, True)
log.info('creating admin and regular test users')
from rhodecode.tests import TEST_USER_ADMIN_LOGIN,\
TEST_USER_ADMIN_PASS ,TEST_USER_ADMIN_EMAIL,TEST_USER_REGULAR_LOGIN,\
TEST_USER_REGULAR_PASS,TEST_USER_REGULAR_EMAIL,\
TEST_USER_REGULAR2_LOGIN,TEST_USER_REGULAR2_PASS,\
TEST_USER_REGULAR2_EMAIL
TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL,\
TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,\
TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
TEST_USER_ADMIN_EMAIL, True)
self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
TEST_USER_REGULAR_EMAIL, False)
self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
TEST_USER_REGULAR2_EMAIL, False)
def create_ui_settings(self):
"""Creates ui settings, fills out hooks
Creates ui settings, fills out hooks
and disables dotencode
#HOOKS
hooks1_key = RhodeCodeUi.HOOK_UPDATE
hooks1_ = self.sa.query(RhodeCodeUi)\
.filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
@@ -302,13 +309,13 @@ class DbManage(object):
dotencode_disable.ui_value = 'false'
# enable largefiles
largefiles = RhodeCodeUi()
largefiles.ui_section = 'extensions'
largefiles.ui_key = 'largefiles'
largefiles.ui_value = '1'
largefiles.ui_value = ''
self.sa.add(hooks1)
self.sa.add(hooks2)
self.sa.add(hooks3)
self.sa.add(hooks4)
self.sa.add(largefiles)
@@ -338,23 +345,22 @@ class DbManage(object):
path = raw_input('Specify valid full path to your repositories'
' you can change this later in application settings:')
path = test_repo_path
path_ok = True
#check proper dir
# check proper dir
if not os.path.isdir(path):
path_ok = False
log.error('Given path %s is not a valid directory', path)
#check write access
# check write access
if not os.access(path, os.W_OK) and path_ok:
log.error('No write permission to given path %s', path)
if retries == 0:
sys.exit('max retries reached')
if path_ok is False:
retries -= 1
return self.config_prompt(test_repo_path, retries)
@@ -419,14 +425,14 @@ class DbManage(object):
UserModel().create_or_update(username='default',
password=str(uuid.uuid1())[:8],
email='anonymous@rhodecode.org',
name='Anonymous', lastname='User')
def create_permissions(self):
#module.(access|create|change|delete)_[name]
#module.(read|write|owner)
# module.(access|create|change|delete)_[name]
# module.(read|write|owner)
perms = [('repository.none', 'Repository no access'),
('repository.read', 'Repository read access'),
('repository.write', 'Repository write access'),
('repository.admin', 'Repository admin access'),
('hg.admin', 'Hg Administrator'),
('hg.create.repository', 'Repository create'),
Status change: