<commit_before><?php

/**
* @todo break this apart to handle multiple types of databases.  Now it is set to handle mysql.
* @todo this really is just hacked out, I really need to refactor this.  It fits my needs for now.
* The stack should turn into a hash of stacks, the key would be the timestamp with milliseconds every time 
* createTable or updateTable is called.  That way messages can then be queue.
*/
abstract class Migration extends Model
{
	private $table;
	private $stack;
	private $alter_stack = array();
	private $valid_options = array('limit'=>'', 'null'=>false, 'primary'=>false, 'auto'=>false, 'index'=>false, 'unique'=>false, 'default'=>'', 'after'=>false);
	private $statement;
	private $config;
	public $operations;
	/**
	 * The type relects if we are doing alter or create.
	 */
	private $type;
	
	/**
	 * Migration class.
	 *
	 * 
	 * @return Migration
	 * @author <NAME>
	 */
	function __construct()
	{
		parent::__construct();
		$this->config = DatabaseConfiguration::getConfig();
		$this->stack = array();
	}
	
	
	/**
	 * Create table
	 *
	 * @return void
	 * @author <NAME>
	 **/
	public function createTable($name, $primary='id', $engine='INNODB', $charset='utf8', $collation='utf8_general_ci')
	{

		$this->type = 'create';
		$name = Inflections::tableize($name);

		$this->migrateIfNeeded();

		$this->operations .= "\033[0;36;1m$name\033[0m | \033[0;35;1m$engine\033[0m | \033[0;36;1m$charset\033[0m | \033[0;35;1m$collation\033[0m\n";
		$this->stack = array();
		$this->alter_stack = array();
		$this->table = $name;
		$this->statement = "CREATE TABLE `" . $this->config->database . "`.`" . $name . "`(\n\t%s\n)ENGINE=$engine CHARACTER SET $charset COLLATE $collation";
		$this->integer($primary, 'auto:true');
	}
	
	/**
	 * Alter table
	 *
	 * @return void
	 * @author <NAME>
	 **/
	public function alterTable($name, $engine=null, $charset=null, $collation=null)
	{
		$this->type = 'alter';

		$this->migrateIfNeeded();

		$this->stack = array();
		$this->alter_stack = array();
		$operation = '';
		if($engine !== null)
			$operation .= "ENGINE=$engine";
		if($charset !== null)
			$operation .= " CHARACTER SET $charset";
		if($collation !== null)
			$operation .= " COLLATE $collation";

		$this->table = $name;
		$this->statement = "ALTER TABLE `" . $this->config->database . "`.`" . Inflections::tableize($name) . "` \n\t%s\n $operation";
	}
	

	/**
	 * Executes migrations if there are any to run 
	 *
	 * @author <NAME>
	 * @access private
	 */
	private function migrateIfNeeded() {
		if($this->statement != "") {
			$this->migrateTable();
		}
		if (!empty($this->alter_stack)) {
			$this->migrateIndex();
		}
	}

	/**
	 * Drop table
	 *
	 * @author <NAME>
	 * @access public
	 */
  public function dropTable($name) {<commit_msg>Added raw option to alter table for passing raw table names<commit_after><?php

/**
* @todo break this apart to handle multiple types of databases.  Now it is set to handle mysql.
* @todo this really is just hacked out, I really need to refactor this.  It fits my needs for now.
* The stack should turn into a hash of stacks, the key would be the timestamp with milliseconds every time 
* createTable or updateTable is called.  That way messages can then be queue.
*/
abstract class Migration extends Model
{
	private $table;
	private $stack;
	private $alter_stack = array();
	private $valid_options = array('limit'=>'', 'null'=>false, 'primary'=>false, 'auto'=>false, 'index'=>false, 'unique'=>false, 'default'=>'', 'after'=>false);
	private $statement;
	private $config;
	public $operations;
	/**
	 * The type relects if we are doing alter or create.
	 */
	private $type;
	
	/**
	 * Migration class.
	 *
	 * 
	 * @return Migration
	 * @author <NAME>
	 */
	function __construct()
	{
		parent::__construct();
		$this->config = DatabaseConfiguration::getConfig();
		$this->stack = array();
	}
	
	
	/**
	 * Create table
	 *
	 * @return void
	 * @author <NAME>
	 **/
	public function createTable($name, $primary='id', $engine='INNODB', $charset='utf8', $collation='utf8_general_ci')
	{

		$this->type = 'create';
		$name = Inflections::tableize($name);

		$this->migrateIfNeeded();

		$this->operations .= "\033[0;36;1m$name\033[0m | \033[0;35;1m$engine\033[0m | \033[0;36;1m$charset\033[0m | \033[0;35;1m$collation\033[0m\n";
		$this->stack = array();
		$this->alter_stack = array();
		$this->table = $name;
		$this->statement = "CREATE TABLE `" . $this->config->database . "`.`" . $name . "`(\n\t%s\n)ENGINE=$engine CHARACTER SET $charset COLLATE $collation";
		$this->integer($primary, 'auto:true');
	}
	
	/**
	 * Alter table
	 *
	 * @return void
	 * @author <NAME>
	 **/
	public function alterTable($name, $engine=null, $charset=null, $collation=null, $raw=null)
	{
		$this->type = 'alter';

		$this->migrateIfNeeded();

		$this->stack = array();
		$this->alter_stack = array();
		$operation = '';
		if($engine !== null)
			$operation .= "ENGINE=$engine";
		if($charset !== null)
			$operation .= " CHARACTER SET $charset";
		if($collation !== null)
			$operation .= " COLLATE $collation";
		if($raw != true) 
			$name = Inflections::tableize($name);

		$this->table = $name;
		$this->statement = "ALTER TABLE `" . $this->config->database . "`.`" . $name . "` \n\t%s\n $operation";
	}
	

	/**
	 * Executes migrations if there are any to run 
	 *
	 * @author <NAME>
	 * @access private
	 */
	private function migrateIfNeeded() {
		if($this->statement != "") {
			$this->migrateTable();
		}
		if (!empty($this->alter_stack)) {
			$this->migrateIndex();
		}
	}

	/**
	 * Drop table
	 *
	 * @author <NAME>
	 * @access public
	 */
  public function dropTable($name) {
{'fraction_non_alphanumeric': 0.18398153081157875, 'fraction_numerical': 0.01633812821878885, 'mean_word_length': 3.7327731092436975, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 77, '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': '4499818', 'n_tokens_mistral': 2125, 'n_tokens_neox': 1893, 'n_words': 487}