Changeset - 5b2cf21b1947
rhodecode/lib/dbmigrate/migrate/__init__.py
Show inline comments
 
@@ -5,7 +5,7 @@
 
   using Python.
 
"""
 

	
 
from rhodecode.lib.dbmigrate.migrate.versioning import *
 
from rhodecode.lib.dbmigrate.migrate.changeset import *
 

	
 
__version__ = '0.7.2.dev'
 
\ No newline at end of file
 
__version__ = '0.7.3.dev'
 
\ No newline at end of file
rhodecode/lib/dbmigrate/migrate/changeset/databases/sqlite.py
Show inline comments
 
@@ -36,13 +36,13 @@ class SQLiteHelper(SQLiteCommon):
 

	
 
        self.append('ALTER TABLE %s RENAME TO migration_tmp' % table_name)
 
        self.execute()
 

	
 
        insertion_string = self._modify_table(table, column, delta)
 

	
 
        table.create()
 
        table.create(bind=self.connection)
 
        self.append(insertion_string % {'table_name': table_name})
 
        self.execute()
 
        self.append('DROP TABLE migration_tmp')
 
        self.execute()
 

	
 
    def visit_column(self, delta):
rhodecode/lib/dbmigrate/migrate/exceptions.py
Show inline comments
 
@@ -80,9 +80,8 @@ class NotSupportedError(Error):
 
    """Not supported error"""
 

	
 

	
 
class InvalidConstraintError(Error):
 
    """Invalid constraint error"""
 

	
 

	
 
class MigrateDeprecationWarning(DeprecationWarning):
 
    """Warning for deprecated features in Migrate"""
rhodecode/lib/dbmigrate/migrate/versioning/api.py
Show inline comments
 
@@ -116,13 +116,13 @@ def script_sql(database, description, re
 
    Create empty change SQL scripts for given DATABASE, where DATABASE
 
    is either specific ('postgresql', 'mysql', 'oracle', 'sqlite', etc.)
 
    or generic ('default').
 

	
 
    For instance, manage.py script_sql postgresql description creates:
 
    repository/versions/001_description_postgresql_upgrade.sql and
 
    repository/versions/001_description_postgresql_postgres.sql
 
    repository/versions/001_description_postgresql_downgrade.sql
 
    """
 
    repo = Repository(repository)
 
    repo.create_script_sql(database, description, **opts)
 

	
 

	
 
def version(repository, **opts):
 
@@ -209,20 +209,21 @@ def test(url, repository, **opts):
 
    database. This is not a real test and may leave the database in a
 
    bad state. You should therefore better run the test on a copy of
 
    your database.
 
    """
 
    engine = opts.pop('engine')
 
    repos = Repository(repository)
 
    script = repos.version(None).script()
 

	
 
    # Upgrade
 
    log.info("Upgrading...")
 
    script = repos.version(None).script(engine.name, 'upgrade')
 
    script.run(engine, 1)
 
    log.info("done")
 

	
 
    log.info("Downgrading...")
 
    script = repos.version(None).script(engine.name, 'downgrade')
 
    script.run(engine, -1)
 
    log.info("done")
 
    log.info("Success")
 

	
 

	
 
@with_engine
rhodecode/lib/dbmigrate/migrate/versioning/repository.py
Show inline comments
 
@@ -112,13 +112,13 @@ class Repository(pathed.Pathed):
 
        """
 
        if options is None:
 
            options = {}
 
        options.setdefault('version_table', 'migrate_version')
 
        options.setdefault('repository_id', name)
 
        options.setdefault('required_dbs', [])
 
        options.setdefault('use_timestamp_numbering', '0')
 
        options.setdefault('use_timestamp_numbering', False)
 

	
 
        tmpl = open(os.path.join(tmpl_dir, cls._config)).read()
 
        ret = TempitaTemplate(tmpl).substitute(options)
 

	
 
        # cleanup
 
        del options['__template_name__']
 
@@ -177,15 +177,15 @@ class Repository(pathed.Pathed):
 
        """Returns repository id specified in config"""
 
        return self.config.get('db_settings', 'repository_id')
 

	
 
    @property
 
    def use_timestamp_numbering(self):
 
        """Returns use_timestamp_numbering specified in config"""
 
        ts_numbering = self.config.get('db_settings', 'use_timestamp_numbering', raw=True)
 
        
 
        return ts_numbering
 
        if self.config.has_option('db_settings', 'use_timestamp_numbering'):
 
            return self.config.getboolean('db_settings', 'use_timestamp_numbering')
 
        return False
 

	
 
    def version(self, *p, **k):
 
        """API to :attr:`migrate.versioning.version.Collection.version`"""
 
        return self.versions.version(*p, **k)
 

	
 
    @classmethod
rhodecode/lib/dbmigrate/migrate/versioning/schemadiff.py
Show inline comments
 
@@ -14,14 +14,22 @@ def getDiffOfModelAgainstDatabase(metada
 
    """
 
    Return differences of model against database.
 

	
 
    :return: object which will evaluate to :keyword:`True` if there \
 
      are differences else :keyword:`False`.
 
    """
 
    return SchemaDiff(metadata,
 
                      sqlalchemy.MetaData(engine, reflect=True),
 
    db_metadata = sqlalchemy.MetaData(engine, reflect=True)
 

	
 
    # sqlite will include a dynamically generated 'sqlite_sequence' table if
 
    # there are autoincrement sequences in the database; this should not be
 
    # compared.
 
    if engine.dialect.name == 'sqlite':
 
        if 'sqlite_sequence' in db_metadata.tables:
 
            db_metadata.remove(db_metadata.tables['sqlite_sequence'])
 

	
 
    return SchemaDiff(metadata, db_metadata,
 
                      labelA='model',
 
                      labelB='database',
 
                      excludeTables=excludeTables)
 

	
 

	
 
def getDiffOfModelAgainstModel(metadataA, metadataB, excludeTables=None):
rhodecode/lib/dbmigrate/migrate/versioning/templates/manage/default.py_tmpl
Show inline comments
 
@@ -4,7 +4,9 @@ from migrate.versioning.shell import mai
 
{{py:
 
_vars = locals().copy()
 
del _vars['__template_name__']
 
_vars.pop('repository_name', None)
 
defaults = ", ".join(["%s='%s'" % var for var in _vars.iteritems()])
 
}}
 

	
 
if __name__ == '__main__':
 
main({{ defaults }})
rhodecode/lib/dbmigrate/migrate/versioning/templates/manage/pylons.py_tmpl
Show inline comments
 
@@ -23,7 +23,8 @@ defaults = ", ".join(["%s='%s'" % var fo
 
}}
 

	
 
conf_dict = ConfigLoader(conf_path).parser._sections['app:main']
 

	
 
# migrate supports passing url as an existing Engine instance (since 0.6.0)
 
# usage: migrate -c path/to/config.ini COMMANDS
 
if __name__ == '__main__':
 
main(url=engine_from_config(conf_dict), repository=migrations.__path__[0],{{ defaults }})
rhodecode/lib/dbmigrate/migrate/versioning/version.py
Show inline comments
 
@@ -87,15 +87,13 @@ class Collection(pathed.Pathed):
 
    @property
 
    def latest(self):
 
        """:returns: Latest version in Collection"""
 
        return max([VerNum(0)] + self.versions.keys())
 

	
 
    def _next_ver_num(self, use_timestamp_numbering):
 
        print use_timestamp_numbering
 
        if use_timestamp_numbering == True:
 
            print "Creating new timestamp version!"
 
            return VerNum(int(datetime.utcnow().strftime('%Y%m%d%H%M%S')))
 
        else:
 
            return self.latest + 1
 

	
 
    def create_new_python_version(self, description, **k):
 
        """Create Python files for new version"""
rhodecode/lib/dbmigrate/schema/db_1_3_0.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
"""
 
    rhodecode.model.db
 
    ~~~~~~~~~~~~~~~~~~
 

	
 
    Database Models for RhodeCode
 

	
 
    :created_on: Apr 08, 2010
 
    :author: marcink
 
    :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
 
    :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 <http://www.gnu.org/licenses/>.
 
\ No newline at end of file
rhodecode/lib/dbmigrate/versions/003_version_1_2_0.py
Show inline comments
 
@@ -18,13 +18,13 @@ def upgrade(migrate_engine):
 
    Don't create your own engine; bind migrate_engine to your metadata
 
    """
 

	
 
    #==========================================================================
 
    # Add table `groups``
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_2_0 import Group
 
    from rhodecode.lib.dbmigrate.schema.db_1_2_0 import RepoGroup as Group
 
    Group().__table__.create()
 

	
 
    #==========================================================================
 
    # Add table `group_to_perm`
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_2_0 import UserRepoGroupToPerm
rhodecode/lib/dbmigrate/versions/004_version_1_3_0.py
Show inline comments
 
new file 100644
 
import logging
 
import datetime
 

	
 
from sqlalchemy import *
 
from sqlalchemy.exc import DatabaseError
 
from sqlalchemy.orm import relation, backref, class_mapper
 
from sqlalchemy.orm.session import Session
 

	
 
from rhodecode.lib.dbmigrate.migrate import *
 
from rhodecode.lib.dbmigrate.migrate.changeset import *
 

	
 
from rhodecode.model.meta import 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
 
    """
 

	
 
    
 

	
 
    return
 

	
 

	
 
def downgrade(migrate_engine):
 
    meta = MetaData()
 
    meta.bind = migrate_engine
0 comments (0 inline, 0 general)