diff --git a/rhodecode/lib/db_manage.py b/rhodecode/lib/db_manage.py --- a/rhodecode/lib/db_manage.py +++ b/rhodecode/lib/db_manage.py @@ -43,6 +43,7 @@ from sqlalchemy.engine import create_eng from rhodecode.model.repos_group import ReposGroupModel #from rhodecode.model import meta from rhodecode.model.meta import Session, Base +from rhodecode.model.repo import RepoModel log = logging.getLogger(__name__) @@ -289,6 +290,9 @@ class DbManage(object): def step_10(self): pass + def step_11(self): + self.klass.update_repo_info() + upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1) # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE @@ -549,6 +553,9 @@ class DbManage(object): self.populate_default_permissions() return fixed + def update_repo_info(self): + RepoModel.update_repoinfo() + def config_prompt(self, test_repo_path='', retries=3): defaults = self.cli_args _path = defaults.get('repos_location') diff --git a/rhodecode/lib/dbmigrate/schema/db_1_6_0.py b/rhodecode/lib/dbmigrate/schema/db_1_6_0.py new file mode 100644 --- /dev/null +++ b/rhodecode/lib/dbmigrate/schema/db_1_6_0.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" + rhodecode.model.db_1_6_0 + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Database Models for RhodeCode <=1.5.X + + :created_on: Apr 08, 2010 + :author: marcink + :copyright: (C) 2010-2012 Marcin Kuzminski + :license: GPLv3, see COPYING for more details. +""" +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#TODO: replace that will db.py content after next + +from rhodecode.model.db import * diff --git a/rhodecode/lib/dbmigrate/versions/011_version_1_6_0.py b/rhodecode/lib/dbmigrate/versions/011_version_1_6_0.py new file mode 100644 --- /dev/null +++ b/rhodecode/lib/dbmigrate/versions/011_version_1_6_0.py @@ -0,0 +1,36 @@ +import logging +import datetime + +from sqlalchemy import * +from sqlalchemy.exc import DatabaseError +from sqlalchemy.orm import relation, backref, class_mapper, joinedload +from sqlalchemy.orm.session import Session +from sqlalchemy.ext.declarative import declarative_base + +from rhodecode.lib.dbmigrate.migrate import * +from rhodecode.lib.dbmigrate.migrate.changeset import * + +from rhodecode.model.meta import Base +from rhodecode.model import meta +from rhodecode.lib.dbmigrate.versions import _reset_base + +log = logging.getLogger(__name__) + + +def upgrade(migrate_engine): + """ + Upgrade operations go here. + Don't create your own engine; bind migrate_engine to your metadata + """ + _reset_base(migrate_engine) + #========================================================================== + # USER LOGS + #========================================================================== + from rhodecode.lib.dbmigrate.schema.db_1_6_0 import RepositoryField + tbl = RepositoryField.__table__ + tbl.create() + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine diff --git a/rhodecode/lib/update_repoinfo.py b/rhodecode/lib/update_repoinfo.py --- a/rhodecode/lib/update_repoinfo.py +++ b/rhodecode/lib/update_repoinfo.py @@ -32,9 +32,10 @@ import string from os.path import dirname as dn, join as jn from rhodecode.model import init_model -from rhodecode.lib.utils2 import engine_from_config, safe_str -from rhodecode.model.db import RhodeCodeUi, Repository -from rhodecode.lib.vcs.backends.base import EmptyChangeset +from rhodecode.lib.utils2 import engine_from_config +from rhodecode.model.db import Repository +from rhodecode.model.repo import RepoModel +from rhodecode.model.meta import Session #to get the rhodecode import @@ -70,13 +71,12 @@ class UpdateCommand(BasePasterCommand): if self.options.repo_update_list else None if repo_update_list: - repo_list = Repository.query().filter(Repository.repo_name.in_(repo_update_list)) + repo_list = Repository.query()\ + .filter(Repository.repo_name.in_(repo_update_list)) else: repo_list = Repository.getAll() - for repo in repo_list: - last_cs = (repo.scm_instance.get_changeset() if repo.scm_instance - else EmptyChangeset()) - repo.update_changeset_cache(last_cs) + RepoModel.update_repoinfo(repositories=repo_list) + Session().commit() def update_parser(self): self.parser.add_option('--update-only', diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -42,6 +42,7 @@ from rhodecode.model.db import Repositor RhodeCodeSetting, RepositoryField from rhodecode.lib import helpers as h from rhodecode.lib.auth import HasRepoPermissionAny +from rhodecode.lib.vcs.backends.base import EmptyChangeset log = logging.getLogger(__name__) @@ -143,6 +144,17 @@ class RepoModel(BaseModel): kwargs.update(dict(_=_, h=h, c=c)) return tmpl.render(*args, **kwargs) + @classmethod + def update_repoinfo(cls, repositories=None): + if not repositories: + repositories = Repository.getAll() + for repo in repositories: + scm_repo = repo.scm_instance_no_cache + last_cs = EmptyChangeset() + if scm_repo: + last_cs = scm_repo.get_changeset() + repo.update_changeset_cache(last_cs) + def get_repos_as_dict(self, repos_list=None, admin=False, perm_check=True, super_user_actions=False): _render = self._render_datatable