<commit_before><?php
namespace LazyRecord\Migration;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class MigrationRunner
{
    public $dataSourceIds = array();

    public function __construct($dsIds)
    {
        $this->dataSourceIds = $dsIds;
    }

    public function addDataSource( $dsId ) 
    {
        $this->dataSourceIds[] = $dsId;
    }

    public function load($directory) 
    {
        $loaded = array();
        $iterator = new RecursiveIteratorIterator( 
            new RecursiveDirectoryIterator($directory) , RecursiveIteratorIterator::CHILD_FIRST
        );
        foreach( $iterator as $path ) {
            if($path->isFile() && $path->getExtension() === 'php' ) {
                $code = file_get_contents($path);
                if( preg_match('#Migration#',$code) ) {
                    require_once($path);
                    $loaded[] = $path;
                }
            }
        }
        return $loaded;
    }

    public function getMigrationScripts() {
        $classes = get_declared_classes();
        return array_filter($classes, function($class) { 
            return is_a($class,'LazyRecord\\Migration\\Migration',true);
        });
    }

    public function runDowngrade()
    {
        $scripts = $this->getMigrationScripts();
    }

    public function runUpgrade()
    {
        $scripts = $this->getMigrationScripts();
    }


}

<commit_msg>implement migration runner methods<commit_after><?php
namespace LazyRecord\Migration;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use LazyRecord\Console;

class MigrationRunner
{


    public $logger;

    public $dataSourceIds = array();

    public function __construct($dsIds)
    {
        $this->logger = Console::getInstance()->getLogger();
        $this->dataSourceIds = $dsIds;
    }

    public function addDataSource( $dsId ) 
    {
        $this->dataSourceIds[] = $dsId;
    }

    public function load($directory) 
    {
        $loaded = array();
        $iterator = new RecursiveIteratorIterator( 
            new RecursiveDirectoryIterator($directory) , RecursiveIteratorIterator::CHILD_FIRST
        );
        foreach( $iterator as $path ) {
            if($path->isFile() && $path->getExtension() === 'php' ) {
                $code = file_get_contents($path);
                if( preg_match('#Migration#',$code) ) {
                    require_once($path);
                    $loaded[] = $path;
                }
            }
        }
        return $loaded;
    }

    public function getMigrationScripts() {
        $classes = get_declared_classes();
        return array_filter($classes, function($class) { 
            return is_a($class,'LazyRecord\\Migration\\Migration',true);
        });
    }

    public function runDowngrade()
    {
        $scripts = $this->getMigrationScripts();
        foreach( $scripts as $script ) {
            foreach( $this->dataSourceIds as $dsId ) {
                $migration = new $script( $dsId );
                $migration->downgrade();
            }
        }
    }

    public function runUpgrade()
    {
        $scripts = $this->getMigrationScripts();
        foreach( $scripts as $script ) {
            foreach( $this->dataSourceIds as $dsId ) {
                $this->logger->info("Running migration script $script on $dsId");
                $migration = new $script( $dsId );
                $migration->upgrade();
            }
        }
    }

}


{'fraction_non_alphanumeric': 0.12413194444444445, 'fraction_numerical': 0.0, 'mean_word_length': 2.0431338028169015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2969765', 'n_tokens_mistral': 970, 'n_tokens_neox': 941, 'n_words': 181}