#!/bin/bash

# Source the utilities
source "$(dirname "$0")/postgres/db_utils.sh"

# Remove the data folder...
rm -rf "$(dirname "$0")/../data"

# Get credentials
get_credentials

# Drop all postgres tables
psql "$(get_pg_url teranode)"  -c "SET client_min_messages TO WARNING; drop table if exists state; drop table if exists utxos; drop table if exists txmeta; drop table if exists blocks; drop table if exists block_ids; drop table if exists outputs; drop table if exists inputs; drop table if exists transactions CASCADE; drop table if exists bans;"
psql "$(get_pg_url coinbase)" -c "SET client_min_messages TO WARNING; drop table if exists coinbase_utxos; drop table if exists spendable_utxos_balance; drop table if exists spendable_utxos_log; drop table if exists spendable_utxos; drop table if exists blocks; drop table if exists state;"

# Flush aerospike
# aql -c "truncate test.utxo;"

asinfo -h localhost -v "truncate-namespace:namespace=teranode-store"
asinfo -h localhost -v "truncate-namespace:namespace=test"

docker exec kafka-server /bin/bash -c '
TOPICS=$(/opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092)
for topic in $TOPICS; do
  echo "Deleting topic $topic"
  /opt/bitnami/kafka/bin/kafka-topics.sh --delete --topic $topic --bootstrap-server localhost:9092
done
'
# mkdir -p data/aerospike
# touch data/aerospike/aerospike-1.dat
# touch data/aerospike/aerospike-2.dat
# touch data/aerospike/aerospike-3.dat
