apiVersion: v1
kind: ConfigMap
metadata:
    name: cassandra-init
data:
    init.cql: |
        CREATE KEYSPACE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }} WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.time_test_events (
            instance_id uuid,
            start_date date,
            start_time time,
            id text,
            end_date date,
            end_time time,
            event_batch boolean,
            event_batch_metadata blob,
            event_count int,
            name text,
            parent_id text,
            root boolean,
            success boolean,
            type text,
            PRIMARY KEY ((instance_id, start_date), start_time, id)
        ) WITH CLUSTERING ORDER BY (start_time ASC, id ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.messages_test_events (
            instance_id uuid,
            message_id text,
            test_event_id text,
            batch_id text,
            PRIMARY KEY ((instance_id, message_id), test_event_id)
        ) WITH CLUSTERING ORDER BY (test_event_id ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.root_test_events (
            instance_id uuid,
            start_date date,
            start_time time,
            id text,
            end_date date,
            end_time time,
            event_batch boolean,
            event_count int,
            name text,
            success boolean,
            type text,
            PRIMARY KEY ((instance_id, start_date), start_time, id)
        ) WITH CLUSTERING ORDER BY (start_time ASC, id ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.test_events_children_dates (
            instance_id uuid,
            parent_id text,
            start_date date,
            PRIMARY KEY ((instance_id, parent_id), start_date)
        ) WITH CLUSTERING ORDER BY (start_date ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.time_messages (
            instance_id uuid,
            stream_name text,
            direction text,
            message_date date,
            message_time time,
            message_index bigint,
            PRIMARY KEY ((instance_id, stream_name, direction, message_date), message_time, message_index)
        ) WITH CLUSTERING ORDER BY (message_time ASC, message_index ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.messages (
            instance_id uuid,
            stream_name text,
            direction text,
            message_index bigint,
            compressed boolean,
            first_message_date date,
            first_message_time time,
            last_message_date date,
            last_message_index bigint,
            last_message_time time,
            message_count int,
            stored_date date,
            stored_time time,
            z_content blob,
            PRIMARY KEY ((instance_id, stream_name), direction, message_index)
        ) WITH CLUSTERING ORDER BY (direction ASC, message_index ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.test_events_messages (
            instance_id uuid,
            test_event_id text,
            message_ids frozen<set<text>>,
            PRIMARY KEY ((instance_id, test_event_id), message_ids)
        ) WITH CLUSTERING ORDER BY (message_ids ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.instances (
            name text PRIMARY KEY,
            id uuid
        ) WITH bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.test_events_children (
            instance_id uuid,
            parent_id text,
            start_date date,
            start_time time,
            id text,
            end_date date,
            end_time time,
            event_batch boolean,
            event_batch_metadata blob,
            event_count int,
            name text,
            root boolean,
            success boolean,
            type text,
            PRIMARY KEY ((instance_id, parent_id, start_date), start_time, id)
        ) WITH CLUSTERING ORDER BY (start_time ASC, id ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.test_events (
            instance_id uuid,
            id text,
            compressed boolean,
            end_date date,
            end_time time,
            event_batch boolean,
            event_count int,
            name text,
            parent_id text,
            root boolean,
            start_date date,
            start_time time,
            stored_date date,
            stored_time time,
            success boolean,
            type text,
            z_content blob,
            PRIMARY KEY ((instance_id, id))
        ) WITH bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
        CREATE TABLE {{ lookup('env','SCHEMA_NAMESPACE') | replace('-', '_') }}.processed_messages (
            instance_id uuid,
            stream_name text,
            direction text,
            message_index bigint,
            compressed boolean,
            first_message_date date,
            first_message_time time,
            last_message_date date,
            last_message_index bigint,
            last_message_time time,
            message_count int,
            stored_date date,
            stored_time time,
            z_content blob,
            PRIMARY KEY ((instance_id, stream_name), direction, message_index)
        ) WITH CLUSTERING ORDER BY (direction ASC, message_index ASC)
            AND bloom_filter_fp_chance = 0.01
            AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
            AND comment = ''
            AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
            AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
            AND crc_check_chance = 1.0
            AND dclocal_read_repair_chance = 0.1
            AND default_time_to_live = 0
            AND gc_grace_seconds = 864000
            AND max_index_interval = 2048
            AND memtable_flush_period_in_ms = 0
            AND min_index_interval = 128
            AND read_repair_chance = 0.0
            AND speculative_retry = '99PERCENTILE';
