function setup_db() { switch (DB_DRIVER) { case 'sqlite': require_once __DIR__ . '/Schema/Sqlite.php'; $params = array('driver' => 'sqlite', 'filename' => DB_FILENAME); break; case 'mysql': require_once __DIR__ . '/Schema/Mysql.php'; $params = array('driver' => 'mysql', 'hostname' => DB_HOSTNAME, 'username' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => DB_NAME, 'charset' => 'utf8'); break; case 'postgres': require_once __DIR__ . '/Schema/Postgres.php'; $params = array('driver' => 'postgres', 'hostname' => DB_HOSTNAME, 'username' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => DB_NAME); break; default: die('Database driver not supported'); } $db = new Database($params); if ($db->schema()->check(Schema\VERSION)) { return $db; } else { $errors = $db->getLogMessages(); die('Unable to migrate database schema: <br/><br/><strong>' . (isset($errors[0]) ? $errors[0] : 'Unknown error') . '</strong>'); } }
/** * Execute database migrations * * @static * @access public * @throws RuntimeException * @param Database $db * @return bool */ public static function runMigrations(Database $db) { if (!$db->schema()->check(\Schema\VERSION)) { $messages = $db->getLogMessages(); throw new RuntimeException('Unable to run SQL migrations: ' . implode(', ', $messages) . ' (You may have to fix it manually)'); } return true; }