diff --git a/nix/clickhouse_test.nix b/nix/clickhouse_test.nix index 4c5978ca..d0c2f03f 100644 --- a/nix/clickhouse_test.nix +++ b/nix/clickhouse_test.nix @@ -1,14 +1,30 @@ { pkgs, config, ... }: { - services.clickhouse."clickhouse" = { + services.clickhouse."clickhouse1" = { enable = true; + port = 9000; extraConfig = '' http_port: 9050 ''; }; + services.clickhouse."clickhouse2" = { + enable = true; + port = 9001; + extraConfig = '' + http_port: 9051 + ''; + initialDatabases = [ + { + name = "sample_db"; + schemas = [ ./clickhouse_test.sql ]; + } + ]; + }; + # avoid both the processes trying to create `data` directory at the same time + settings.processes."clickhouse2-init".depends_on."clickhouse1-init".condition = "process_completed_successfully"; settings.processes.test = let - cfg = config.services.clickhouse."clickhouse"; + cfg = config.services.clickhouse."clickhouse1"; in { command = pkgs.writeShellApplication { @@ -27,9 +43,13 @@ # Test clickhouse http port curl http://localhost:9050 | grep Ok + + # schemas test + clickhouse-client --host 127.0.0.1 --port 9001 --query "SELECT * FROM sample_db.ride WHERE short_id = 'test_ride';" | grep test_ride + ''; name = "clickhouse-test"; }; - depends_on."clickhouse".condition = "process_healthy"; + depends_on."clickhouse2".condition = "process_healthy"; }; } diff --git a/nix/clickhouse_test.sql b/nix/clickhouse_test.sql new file mode 100644 index 00000000..b8b7fca3 --- /dev/null +++ b/nix/clickhouse_test.sql @@ -0,0 +1,3 @@ +CREATE TABLE sample_db.ride (`id` Int64, `short_id` String) ENGINE = MergeTree() PRIMARY KEY (id); + +INSERT INTO sample_db.ride values (1, 'test_ride');