<commit_before><?php

class CM_Db_Cli extends CM_Cli_Runnable_Abstract {

	/**
	 * @param string $namespace
	 */
	public function dump($namespace) {
		$namespace = (string) $namespace;
		$tables = CM_Db_Db::exec("SHOW TABLES LIKE ?", array(strtolower($namespace) . '_%'))->fetchAllColumn();
		sort($tables);
		$dump = CM_Db_Db::getDump($tables, true);
		CM_File::create(CM_Util::getNamespacePath($namespace) . '/resources/db/structure.sql', $dump);
	}

	public function runUpdates() {
		$app = CM_App::getInstance();
		$output = $this->_getOutput();
		$versionBumps = $app->runUpdateScripts(function ($version) use ($output) {
			$output->writeln('Running update ' . $version . '...');
		});
		if ($versionBumps > 0) {
			$db = CM_Config::get()->CM_Db_Db->db;
			CM_Db_Db::exec('DROP DATABASE IF EXISTS `' . $db . '_test`');
		}
		$app->setReleaseStamp();
	}

	/**
	 * @param integer $version
	 * @param string|null  $namespace
	 */
	public function runUpdate($version, $namespace = null) {
		$versionBumps = CM_App::getInstance()->runUpdateScript($namespace, $version);
		if ($versionBumps > 0) {
			$db = CM_Config::get()->CM_Db_Db->db;
			CM_Db_Db::exec('DROP DATABASE IF EXISTS `' . $db . '_test`');
		}
	}

	public static function getPackageName() {
		return 'db';
	}<commit_msg>Add fileToDb, rename dump to dbToFile<commit_after><?php

class CM_Db_Cli extends CM_Cli_Runnable_Abstract {

	/**
	 * @param string $namespace
	 */
	public function dbToFile($namespace) {
		$namespace = (string) $namespace;
		$tables = CM_Db_Db::exec("SHOW TABLES LIKE ?", array(strtolower($namespace) . '_%'))->fetchAllColumn();
		sort($tables);
		$dump = CM_Db_Db::getDump($tables, true);
		CM_File::create(CM_Util::getNamespacePath($namespace) . '/resources/db/structure.sql', $dump);
	}

	public function fileToDb() {
		$configDb = CM_Config::get()->CM_Db_Db;
		$client = new CM_Db_Client($configDb->server['host'], $configDb->server['port'], $configDb->username, $configDb->password);

		$databaseExists = (bool) $client->createStatement('SHOW DATABASES LIKE ?')->execute(array($configDb->db))->fetch();
		if (!$databaseExists) {
			$client->createStatement('CREATE DATABASE ' . $client->quoteIdentifier($configDb->db))->execute();
		}
		foreach (CM_Util::getResourceFiles('db/structure.sql') as $dump) {
			CM_Db_Db::runDump($configDb->db, $dump);
		}
	}

	public function runUpdates() {
		$app = CM_App::getInstance();
		$output = $this->_getOutput();
		$versionBumps = $app->runUpdateScripts(function ($version) use ($output) {
			$output->writeln('Running update ' . $version . '...');
		});
		if ($versionBumps > 0) {
			$db = CM_Config::get()->CM_Db_Db->db;
			CM_Db_Db::exec('DROP DATABASE IF EXISTS `' . $db . '_test`');
		}
		$app->setReleaseStamp();
	}

	/**
	 * @param integer $version
	 * @param string|null  $namespace
	 */
	public function runUpdate($version, $namespace = null) {
		$versionBumps = CM_App::getInstance()->runUpdateScript($namespace, $version);
		if ($versionBumps > 0) {
			$db = CM_Config::get()->CM_Db_Db->db;
			CM_Db_Db::exec('DROP DATABASE IF EXISTS `' . $db . '_test`');
		}
	}

	public static function getPackageName() {
		return 'db';
	}
{'fraction_non_alphanumeric': 0.18951358180669614, 'fraction_numerical': 0.0012634238787113076, 'mean_word_length': 4.73731884057971, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '5247748', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1098, 'n_words': 203}