<commit_before><?php
namespace LazyRecord\Migration;
use SQLBuilder\Universal\Query\AlterTableQuery;
use SQLBuilder\ToSqlInterface;
use SQLBuilder\Universal\Syntax\Column;
use SQLBuilder\ArgumentArray;
use SQLBuilder\Bind;
use SQLBuilder\Driver\BaseDriver;
use LazyRecord\ConnectionManager;
use LazyRecord\Console;
use LazyRecord\Migration\Migratable;
use LazyRecord\Schema\DeclareColumn;
use LazyRecord\Schema\DeclareSchema;
use LazyRecord\Schema\DynamicSchemaDeclare;
use LazyRecord\Schema\SchemaInterface;
use LazyRecord\SqlBuilder\SqlBuilder;
use LazyRecord\ServiceContainer;
use PDO;
use PDOException;
use Exception;
use LogicException;
use InvalidArgumentException;
use BadMethodCallException;

class Migration implements Migratable
{
    /**
     * @var QueryDriver
     */
    public $driver;


    /**
     * @var PDO object
     */
    public $connection;

    /**
     * @var CLIFramework\Logger
     */
    public $logger;

    /**
     * @var LazyRecord\SqlBuilder\BaseBuilder
     */
    public $builder;

    public function __construct(BaseDriver $driver, PDO $connection)
    {
        $c = ServiceContainer::getInstance();
        $this->driver = $driver;
        $this->connection = $connection;
        $this->logger  = $c['logger'] ?: Console::getInstance()->getLogger();
        $this->builder = SqlBuilder::create($driver);
    }

    public static function getId()
    {
        $name = get_called_class() ?: get_class($this);
        if (preg_match('#_(\d+)$#',$name,$regs)) {
            return $regs[1];
        }
        // throw new Exception("Can't parse migration script ID from class name: " . $name);
    }


    /**
     * Deprecated, use query method instead.
     *
     * @deprecated
     */
    public function executeSql($sql)
    {
        return $this->query($sql);
    }


    public function executeQuery(ToSqlInterface $query)
    {
        $sql = $query->toSql($this->driver, new ArgumentArray);
        $this->showSql($sql);
        $this->query($sql);
    }


    public function showSql($sql, $title = '')
    {
        if (strpos($sql,"\n") !== false) {
            $this->logger->info('Performing Query: ' . $title);
            $this->logger->info($sql);
        } else {
            $this->logger->info('Performing Query: ' . $sql);
        }
    }

    /**
     * Execute sql for migration
     *
     * @param string $sql
     */
    public function query($sql, $title = '') 
    {
        $sqls = (array) $sql;
        foreach ($sqls as $q) {
            $this->showSql($q, $title);<commit_msg>The query method already execute showSql() method<commit_after><?php
namespace LazyRecord\Migration;
use SQLBuilder\Universal\Query\AlterTableQuery;
use SQLBuilder\ToSqlInterface;
use SQLBuilder\Universal\Syntax\Column;
use SQLBuilder\ArgumentArray;
use SQLBuilder\Bind;
use SQLBuilder\Driver\BaseDriver;
use LazyRecord\ConnectionManager;
use LazyRecord\Console;
use LazyRecord\Migration\Migratable;
use LazyRecord\Schema\DeclareColumn;
use LazyRecord\Schema\DeclareSchema;
use LazyRecord\Schema\DynamicSchemaDeclare;
use LazyRecord\Schema\SchemaInterface;
use LazyRecord\SqlBuilder\SqlBuilder;
use LazyRecord\ServiceContainer;
use PDO;
use PDOException;
use Exception;
use LogicException;
use InvalidArgumentException;
use BadMethodCallException;

class Migration implements Migratable
{
    /**
     * @var QueryDriver
     */
    public $driver;


    /**
     * @var PDO object
     */
    public $connection;

    /**
     * @var CLIFramework\Logger
     */
    public $logger;

    /**
     * @var LazyRecord\SqlBuilder\BaseBuilder
     */
    public $builder;

    public function __construct(BaseDriver $driver, PDO $connection)
    {
        $c = ServiceContainer::getInstance();
        $this->driver = $driver;
        $this->connection = $connection;
        $this->logger  = $c['logger'] ?: Console::getInstance()->getLogger();
        $this->builder = SqlBuilder::create($driver);
    }

    public static function getId()
    {
        $name = get_called_class() ?: get_class($this);
        if (preg_match('#_(\d+)$#',$name,$regs)) {
            return $regs[1];
        }
        // throw new Exception("Can't parse migration script ID from class name: " . $name);
    }


    /**
     * Deprecated, use query method instead.
     *
     * @deprecated
     */
    public function executeSql($sql)
    {
        return $this->query($sql);
    }


    public function executeQuery(ToSqlInterface $query)
    {
        $sql = $query->toSql($this->driver, new ArgumentArray);
        $this->query($sql);
    }


    public function showSql($sql, $title = '')
    {
        if (strpos($sql,"\n") !== false) {
            $this->logger->info('Performing Query: ' . $title);
            $this->logger->info($sql);
        } else {
            $this->logger->info('Performing Query: ' . $sql);
        }
    }

    /**
     * Execute sql for migration
     *
     * @param string $sql
     */
    public function query($sql, $title = '') 
    {
        $sqls = (array) $sql;
        foreach ($sqls as $q) {
            $this->showSql($q, $title);
{'fraction_non_alphanumeric': 0.1369514106583072, 'fraction_numerical': 0.00039184952978056425, 'mean_word_length': 2.6647523330940417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '916743', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1516, 'n_words': 326}