Beispiel #1
0
 def upgrade(engine):
     schema = ControlledSchema(engine, self.repo_path)
     changeset = schema.changeset(None)
     for version, change in changeset:
         log.msg('migrating schema version %s -> %d'
                 % (version, version + 1))
         schema.runchange(version, change, 1)
Beispiel #2
0
 def upgrade(engine):
     schema = ControlledSchema(engine, self.repo_path)
     changeset = schema.changeset(None)
     for version, change in changeset:
         log.msg('migrating schema version %s -> %d' %
                 (version, version + 1))
         schema.runchange(version, change, 1)
Beispiel #3
0
 def upgrade(engine):
     schema = ControlledSchema(engine, self.repo_path)
     changeset = schema.changeset(None)
     with sautils.withoutSqliteForeignKeys(engine):
         for version, change in changeset:
             log.msg('migrating schema version %s -> %d'
                     % (version, version + 1))
             schema.runchange(version, change, 1)
Beispiel #4
0
 def upgrade(engine):
     schema = ControlledSchema(engine, self.repo_path)
     changeset = schema.changeset(None)
     with sautils.withoutSqliteForeignKeys(engine):
         for version, change in changeset:
             log.msg('migrating schema version %s -> %d' %
                     (version, version + 1))
             schema.runchange(version, change, 1)
Beispiel #5
0
def run_batch(host, scripts, **kw):
    engine = kw['engine']
    previous = ""
    schema = None
    for repo, ver, script, _ in scripts:
        if repo != previous:
            schema = ControlledSchema(engine, repo)
            previous = repo
        schema.runchange(ver, script, step=1)
Beispiel #6
0
def get_migration_files(host, repo, **kw):
    engine = kw['engine']
    try:
        schema = ControlledSchema(engine, repo)
    except DatabaseNotControlledError:
        ControlledSchema.create(engine, repo)
        schema = ControlledSchema(engine, repo)
    changeset = schema.changeset()
    scripts = []
    for ver_num, script in changeset.items():
        needs = None
        if isinstance(script, PythonScript):
            needs = (script.module.needs
                     if hasattr(script.module, 'needs') else None)
        elif isinstance(script, SqlScript):
            with open(script.path) as f:
                first_line = f.readline()
                if first_line.startswith('-- needs: '):
                    needs = tuple(
                        map(
                            tuple,
                            loads(
                                first_line.strip('\n').replace(
                                    '-- needs: ', ''))))
        scripts.append((repo, ver_num, script, needs))
    scripts.sort()
    return scripts
Beispiel #7
0
        def thd(engine):
            # we don't even have to look at the old version table - if there's
            # no migrate_version, then we're not up to date.
            repo = migrate.versioning.repository.Repository(self.repo_path)
            repo_version = repo.latest
            try:
                # migrate.api doesn't let us hand in an engine
                schema = ControlledSchema(engine, self.repo_path)
                db_version = schema.version
            except exceptions.DatabaseNotControlledError:
                return False

            return db_version == repo_version
Beispiel #8
0
 def version_control(engine, version=None):
     ControlledSchema.create(engine, self.repo_path, version)
Beispiel #9
0
 def version_control(engine, version=None):
     ControlledSchema.create(engine, self.repo_path, version)
def main():
    import camelot
    import logging
    logging.basicConfig(level=logging.INFO)
    #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
    parser = CommandOptionParser(usage=usage,
                                 description=description,
                                 version=camelot.__version__)
    (_options, args) = parser.parse_args()
    if not args:
        parser.print_help()
    elif args[0] == 'console':
        setup_model()
        sh = Shell()
        sh.interact()
    elif args[0] == 'schema_display':
        setup_model()
        schema_display()
    elif args[0] in ('version_control', 'db_version', 'version', 'upgrade'):
        import settings
        from migrate.versioning.repository import Repository
        from migrate.versioning.schema import ControlledSchema
        from migrate.versioning.exceptions import DatabaseNotControlledError
        from sqlalchemy.exceptions import NoSuchTableError
        migrate_engine = settings.ENGINE()
        repository = Repository(settings.REPOSITORY)
        schema = None
        try:
            schema = ControlledSchema(migrate_engine, repository)
        except (NoSuchTableError, DatabaseNotControlledError):
            print 'database not yet under version control, putting it under version_control first.'
        if args[0] == 'version_control' or schema is None:
            migrate_connection = migrate_engine.connect()
            transaction = migrate_connection.begin()
            try:
                schema = ControlledSchema.create(migrate_engine, repository)
                transaction.commit()
            except:
                transaction.rollback()
                raise
            finally:
                migrate_connection.close()
            print 'database was put under version control'
        if schema:
            if args[0] == 'db_version':
                print schema.version
            elif args[0] == 'version':
                print repository.latest
            elif args[0] == 'upgrade':
                migrate_connection = migrate_engine.connect()
                if len(args) >= 2:
                    version = int(args[1])
                else:
                    version = repository.latest
                #
                # perform each upgrade step in a separate transaction, since
                # one upgrade might depend on an other being fully executed
                #
                try:
                    if schema.version == version:
                        print 'database is allready at requested version'
                    if schema.version <= version:
                        step = 1
                    else:
                        step = -1
                    for i in range(schema.version + step, version + step,
                                   step):
                        transaction = migrate_connection.begin()
                        try:
                            schema.upgrade(i)
                            transaction.commit()
                            if step == 1:
                                print 'upgrade %s' % i
                            else:
                                print 'downgrade %s' % i
                        except:
                            transaction.rollback()
                            raise
                finally:
                    migrate_connection.close()
    else:
        parser.print_help()
Beispiel #11
0
def main():
    import camelot
    import logging
    logging.basicConfig(level=logging.INFO)
    #logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
    parser = CommandOptionParser(usage=usage,
                                 description=description, 
                                 version=camelot.__version__)
    (_options, args) = parser.parse_args()
    if not args:
        parser.print_help()
    elif args[0]=='console':
        setup_model()
        sh = Shell()
        sh.interact()
    elif args[0]=='schema_display':
        setup_model()
        schema_display()
    elif args[0] in ('version_control', 'db_version', 'version', 'upgrade'):
        import settings
        from migrate.versioning.repository import Repository
        from migrate.versioning.schema import ControlledSchema
        from migrate.versioning.exceptions import DatabaseNotControlledError
        from sqlalchemy.exceptions import NoSuchTableError
        migrate_engine = settings.ENGINE()
        repository = Repository(settings.REPOSITORY)
        schema = None
        try:
            schema = ControlledSchema(migrate_engine, repository)
        except (NoSuchTableError, DatabaseNotControlledError):
            print 'database not yet under version control, putting it under version_control first.'
        if args[0]=='version_control' or schema is None:
            migrate_connection = migrate_engine.connect()
            transaction = migrate_connection.begin()
            try:
                schema = ControlledSchema.create(migrate_engine, repository)
                transaction.commit()
            except:
                transaction.rollback()
                raise
            finally:
                migrate_connection.close()
            print 'database was put under version control'
        if schema:
            if args[0]=='db_version':
                print schema.version
            elif args[0]=='version':
                print repository.latest
            elif args[0]=='upgrade':
                migrate_connection = migrate_engine.connect()
                if len(args)>=2:
                    version = int(args[1])
                else:
                    version = repository.latest
                #
                # perform each upgrade step in a separate transaction, since
                # one upgrade might depend on an other being fully executed
                #
                try:
                    if schema.version == version:
                        print 'database is allready at requested version'
                    if schema.version <= version:
                        step = 1
                    else:
                        step = -1
                    for i in range(schema.version+step, version+step, step):
                        transaction = migrate_connection.begin()
                        try:
                            schema.upgrade(i)
                            transaction.commit()
                            if step==1:
                                print 'upgrade %s'%i
                            else:
                                print 'downgrade %s'%i
                        except:
                            transaction.rollback()
                            raise
                finally:
                    migrate_connection.close()
    else:
        parser.print_help()