#!/usr/bin/env zsh set -eu die() { echo "$0: $*" 1>&2 ; false; } root_dir="$(dirname $(dirname "$0:A"))" pid_file="$root_dir/tmp/cockroach.pid" log_file="$root_dir/tmp/cockroachdb.log" mkdir -p "$root_dir/tmp" rm -f "$pid_file" if ! (( ${+commands[cockroach]} )); then die 'the `cockroach` toolchain is not installed. See https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html' fi cockroach start-single-node \ --insecure --store=type=mem,size=0.25 --advertise-addr=localhost --pid-file "$pid_file" \ &> "$log_file" & cockroach_pid=$! until [[ -f "$pid_file" ]]; do sleep 1 done cat <<-SQL | cockroach sql --insecure --host=localhost:26257 > /dev/null -- https://www.cockroachlabs.com/docs/stable/local-testing.html SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = true; SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms'; SET CLUSTER SETTING jobs.registry.interval.gc = '30s'; SET CLUSTER SETTING jobs.registry.interval.cancel = '180s'; SET CLUSTER SETTING jobs.retention_time = '15s'; SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false; SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s'; ALTER RANGE default CONFIGURE ZONE USING "gc.ttlseconds" = 600; ALTER DATABASE system CONFIGURE ZONE USING "gc.ttlseconds" = 600; CREATE DATABASE activerecord_unittest; CREATE DATABASE activerecord_unittest2; SQL tail -f "$log_file" trap "kill $cockroach_pid" EXIT