Skip to content

Commit

Permalink
clickhouse schema test
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-bodavskiy committed Feb 7, 2024
1 parent 3c9f083 commit a614a1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
26 changes: 23 additions & 3 deletions nix/clickhouse_test.nix
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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";
};
}
3 changes: 3 additions & 0 deletions nix/clickhouse_test.sql
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit a614a1d

Please sign in to comment.