Ejemplo n.º 1
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
    def __init__(self, db, model=None):

        #/**
        # * The database connection that sould be used
        # * @var Kohana_Database
        # */
        self._db = None

        #/**
        # * Model used to interact with the migrations table in the database
        # * @var Model_Minion_Migration
        # */
        self._model = None

        #/**
        # * Whether this is a dry run migration
        # * @var boolean
        # */
        self._dry_run = False

        #/**
        # * A set of SQL queries that were generated on the dry run
        # * @var array
        # */
        self._dry_run_sql = {}

        #/**
        # * Set of migrations that were executed
        # */
        self._executed_migrations = []

        if model is None:
            model = migration_model(db)

        self._db = db
        self._model = model