#!/bin/bash
set -euo pipefail

#####
#
# This script helps load data into your local Postgres DB
# Typically this data would have been generated by the data_dump.sh script in this dir
#
# -----
# NOTE:
# This script loads data by executing the SQL statements in the 'data' file.
# You will need to take different actions based on - if your 'data' file contains schema generating SQL.
#
# If you have dumped the data using the data_dump.sh script, then it will NOT conatin the schema generating SQL.
# In that case, then schema needs to be created.
# You can do that by fillowing steps.
#     1. Running Kong SpringBoot app and let flyway create the schema
#     2. If the data dump contains flyway table (which it will if you use the data_dump.sh) then use psql and run
#        delete * from flyway_schema_history
#     3. Now you can use this script to load data.
#

if [ $# -ne 1 ]
then
    echo "Usage:: $0 file_name"
    exit 1
fi

file_name=$1
db_name='marvel_dev'
server_name='localhost'

echo "======================="
echo "Starting data load from server:$server_name db:$db_name to $file_name"
echo

psql --host $server_name --username postgres -W --dbname $db_name < $file_name

echo
echo "Finished data load from server:$server_name db:$db_name to $file_name"

