public function __construct($config, $adapter) { echo CLI::h1('Repel adapter', HEADER_FILL); $this->config = $config; $this->adapter = $adapter; }
echo CLI::color("done", green); echo "\n"; if ($old_schema !== null) { echo CLI::h1('copy data', HEADER_FILL); $public_schema_adapter = new Adapter\Adapter($config['databases'], $c['adapter']); $public_schema_adapter->addFetcher(new Adapter\Fetcher\PostgreSQLFetcher($key)); $public_schema_adapter->fetch($manager->db); $old_config = $config['databases']; $old_config[$key]['schema_name'] = $old_schema; $old_schema_adapter = new Adapter\Adapter($old_config, $c['adapter']); $old_schema_adapter->addFetcher(new Adapter\Fetcher\PostgreSQLFetcher($key)); $old_schema_adapter->fetch($manager->db); $copier = new Repel\Adapter\Copier\Copier($old_schema_adapter, $public_schema_adapter, $key, $key); $queries = $copier->copy($manager->db); file_put_contents(__DIR__ . '/update.sql', $queries); echo CLI::h1('initializing', HEADER_FILL); $initiator = new Initiator\Initiator($manager->db); $initiator->addSource(__DIR__ . '/update.sql'); if (key_exists("views_dir", $c)) { echo CLI::dotFill('loading views', DOT_FILL); $views = array_merge(glob($c['views_dir'] . "/**/*.sql"), glob($c['views_dir'] . "/*.sql")); foreach ($views as $view) { $initiator->addSource($view); } echo CLI::color("done", green); echo "\n"; } if (key_exists("functions_dir", $c)) { echo CLI::dotFill('loading functions', DOT_FILL); $functions = array_merge(glob($c['functions_dir'] . "/**/*.sql"), glob($c['functions_dir'] . "/*.sql")); foreach ($functions as $function) {
$config = (require $config_file); if (!key_exists('databases', $config) || !Framework\RDatabaseConfigChecker::checkConfig($config["databases"])) { echo "Incorrect database config file."; die; } } else { echo "Database config file not found."; die; } } else { echo "No database config file."; die; } $drivers = array(); foreach ($config['databases'] as $key => $c) { echo CLI::h1('create default database', HEADER_FILL); // Connecting echo CLI::dotFill('connecting', DOT_FILL); $manager = new DatabaseManager($c); echo CLI::color("done", green); echo "\n"; $result = $manager->db->exec('BEGIN;'); if ($result === false) { $errorInfo = $this->db->errorInfo(); throw new Exception('SQL ERROR: ' . "\n" . $errorInfo[2]); } if (!in_array($c["driver"], $drivers)) { // Creating schema $count = 0; echo CLI::dotFill('creating schema', DOT_FILL); $manager->createSchema();
$config = (require $config_file); if (!key_exists('databases', $config) || !Framework\RDatabaseConfigChecker::checkConfig($config["databases"])) { echo "Incorrect database config file."; die; } } else { echo "Database config file not found."; die; } } else { echo "No database config file."; die; } foreach ($config['databases'] as $key => $config) { $initiator = new Initiator\Initiator($config); echo CLI::h1('initialize database', HEADER_FILL); echo CLI::h2('add sources', HEADER_FILL); if (key_exists("views_dir", $config)) { echo CLI::dotFill('loading views', DOT_FILL); if (is_array($config['views_dir'])) { $views = array(); foreach ($config['views_dir'] as $view_dir) { $views = array_merge($views, array_merge(glob($view_dir . DIRECTORY_SEPARATOR . "**" . DIRECTORY_SEPARATOR . "*.sql"), glob($view_dir . DIRECTORY_SEPARATOR . "*.sql"))); } } else { $views = array_merge(glob($config['views_dir'] . DIRECTORY_SEPARATOR . "**" . DIRECTORY_SEPARATOR . "*.sql"), glob($config['views_dir'] . DIRECTORY_SEPARATOR . "*.sql")); } foreach ($views as $view) { $initiator->addSource($view); } echo CLI::color("done", green);