def get_database_connection(self):
        config = migration.conf()
        group = self._info['group']

        if config.has_key(group):
            return config[group]

        return db.default
def instance(name = None, config = None):
    if name is None:
        name = minion_database_base.default

    if not minion_database_base.instances.has_key(name):
        if config is None:
            import config.migration as default_conf
            config = default_conf.conf()['connections'][name]
        if not config.has_key('type'):
            raise Exception("Database type not defined in configuration")

        # Create database connection instance
        try:
            db_module = __import__( 'classes.minion.database.%s' % config['type'], fromlist=['classes.minion.database.%s' % config['type']])
        except:
            raise Exception("Unable to load database type.")
        return db_module.instance(name=name, config=config);
    return minion_database_base.instances[name]
예제 #3
0
    def execute(self, config):
        k_config = migration_conf.conf()

        groups = config.get("group")
        target = config.get("to")

        dry_run = False
        quiet = False
        up = False
        down = False

        if config.get("dry-run"):
            dry_run = True
        if config.get("quiet"):
            quiet = True
        if config.get("up"):
            up = True
        if config.get("down"):
            down = True

        groups = self._parse_groups(groups)

        if target is None:
            if down:
                target = False
            else:
                target = True

        db = database.instance()
        model = migration_model(db)

        model.ensure_table_exists()

        manager = minion_migration_manager(db, model)

        # Sync the available migrations with those in the db
        manager.sync_migration_files().set_dry_run(dry_run)

        try:
            # 			// Run migrations for specified groups & versions
            manager.run_migrations(groups, target)
        except minion_migration_exception as e:
            raise e