<commit_before><?php
namespace LazyRecord\Command;
use CLIFramework\Command;

class MigrateCommand extends Command
{

    public function options($opts) 
    {
        $opts->add('new:','create new migration script.');
        $opts->add('diff:','use schema diff to generate script automatically.');
        $opts->add('status','show current migration status.');
        $opts->add('up','upgrade');
        $opts->add('down','downgrade');
        $opts->add('D|data-source:','data source id.');
    }

    public function execute() 
    {
        $optNew = $this->options->new;
        $optDiff = $this->options->diff;
        $optUp = $this->options->up;
        $optDown = $this->options->down;
        $optStatus = $this->options->status;
        $dsId = $this->options->{'data-source'} ?: 'default';

        CommandUtils::set_logger($this->logger);
        CommandUtils::init_config_loader();

        if( $optNew ) {
            $generator = new \LazyRecord\Migration\MigrationGenerator('db/migrations');
            $this->logger->info( "Creating migration script for '" . $optNew . "'" );
            list($class,$path) = $generator->generate($optNew);
            $this->logger->info( "Migration script is generated: $path" );
        }
        elseif( $optDiff ) {
            $generator = new \LazyRecord\Migration\MigrationGenerator('db/migrations');

            $this->logger->info( "Loading schema objects..." );
            $finder = new \LazyRecord\Schema\SchemaFinder;
            $finder->find();

            $this->logger->info( "Creating migration script from diff" );
            list($class,$path) = $generator->generateWithDiff('DiffMigration',$dsId,$finder->getSchemas());
            $this->logger->info( "Migration script is generated: $path" );

        }
        elseif( $optStatus ) {
            $runner = new \LazyRecord\Migration\MigrationRunner($dsId);
            $runner->load('db/migrations');
            $scripts = $runner->getMigrationScripts();
            $this->logger->info("Found " . count($scripts) . " migrations to be executed.");
            foreach( $scripts as $script ) {
                $this->logger->info( '- ' . $script , 1 );
            }
        }
        elseif( $optUp ) {
            // XXX: record the latest ran migration id,
            $runner = new \LazyRecord\Migration\MigrationRunner($dsId);
            $runner->load('db/migrations');
            $this->logger->info('Running migration scripts to upgrade...');
            $runner->runUpgrade();
            $this->logger->info('Done.');
        }

    }
}
<commit_msg>use migration task name for diff.<commit_after><?php
namespace LazyRecord\Command;
use CLIFramework\Command;

class MigrateCommand extends Command
{

    public function options($opts) 
    {
        $opts->add('new:','create new migration script.');
        $opts->add('diff:','use schema diff to generate script automatically.');
        $opts->add('status','show current migration status.');
        $opts->add('up','upgrade');
        $opts->add('down','downgrade');
        $opts->add('D|data-source:','data source id.');
    }

    public function execute() 
    {
        $optNew = $this->options->new;
        $optDiff = $this->options->diff;
        $optUp = $this->options->up;
        $optDown = $this->options->down;
        $optStatus = $this->options->status;
        $dsId = $this->options->{'data-source'} ?: 'default';

        CommandUtils::set_logger($this->logger);
        CommandUtils::init_config_loader();

        if( $optNew ) {
            $generator = new \LazyRecord\Migration\MigrationGenerator('db/migrations');
            $this->logger->info( "Creating migration script for '" . $optNew . "'" );
            list($class,$path) = $generator->generate($optNew);
            $this->logger->info( "Migration script is generated: $path" );
        }
        elseif( $optDiff ) {
            $generator = new \LazyRecord\Migration\MigrationGenerator('db/migrations');

            $this->logger->info( "Loading schema objects..." );
            $finder = new \LazyRecord\Schema\SchemaFinder;
            $finder->find();

            $this->logger->info( "Creating migration script from diff" );
            list($class,$path) = $generator->generateWithDiff( $optDiff ,$dsId,$finder->getSchemas());
            $this->logger->info( "Migration script is generated: $path" );

        }
        elseif( $optStatus ) {
            $runner = new \LazyRecord\Migration\MigrationRunner($dsId);
            $runner->load('db/migrations');
            $scripts = $runner->getMigrationScripts();
            $this->logger->info("Found " . count($scripts) . " migrations to be executed.");
            foreach( $scripts as $script ) {
                $this->logger->info( '- ' . $script , 1 );
            }
        }
        elseif( $optUp ) {
            // XXX: record the latest ran migration id,
            $runner = new \LazyRecord\Migration\MigrationRunner($dsId);
            $runner->load('db/migrations');
            $this->logger->info('Running migration scripts to upgrade...');
            $runner->runUpgrade();
            $this->logger->info('Done.');
        }

    }
}

{'fraction_non_alphanumeric': 0.1670194342890129, 'fraction_numerical': 0.00038483740619588223, 'mean_word_length': 2.3003174603174603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 93, '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': '6070391', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1443, 'n_words': 281}