MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / createClickHouseDatabase

Function createClickHouseDatabase

programs/docker-init/docker-init.cpp:511–533  ·  view source on GitHub ↗

Returns false on first error (fail-fast, matches shell `set -e`).

Source from the content-addressed store, hash-verified

509
510/// Returns false on first error (fail-fast, matches shell `set -e`).
511bool createClickHouseDatabase(
512 const std::vector<std::string> & client_base,
513 const std::string & clickhouse_db)
514{
515 if (clickhouse_db.empty())
516 return true;
517 if (!isValidIdentifier(clickhouse_db))
518 {
519 std::cerr << "docker-init: error: CLICKHOUSE_DB '" << clickhouse_db
520 << "' contains characters not safe for use in SQL; "
521 "use only alphanumeric characters and underscores\n";
522 return false;
523 }
524 std::cerr << "docker-init: create database '" << clickhouse_db << "'\n";
525 std::vector<std::string> args = client_base;
526 args.insert(args.end(), {"-q", "CREATE DATABASE IF NOT EXISTS " + clickhouse_db});
527 if (runCommand(args) != 0)
528 {
529 std::cerr << "docker-init: error: failed to create database '" << clickhouse_db << "'\n";
530 return false;
531 }
532 return true;
533}
534
535/// Returns false on first script failure (fail-fast, matches shell `set -e`).
536bool runInitScripts(const std::vector<std::string> & client_base)

Callers 1

initClickHouseDBFunction · 0.85

Calls 5

runCommandFunction · 0.85
isValidIdentifierFunction · 0.70
emptyMethod · 0.45
insertMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected