Returns false on first error (fail-fast, matches shell `set -e`).
| 509 | |
| 510 | /// Returns false on first error (fail-fast, matches shell `set -e`). |
| 511 | bool 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`). |
| 536 | bool runInitScripts(const std::vector<std::string> & client_base) |
no test coverage detected