feat(bin) add import.sh

This commit is contained in:
dancingCycle 2023-08-09 07:01:14 +02:00
parent f5c26dc2a0
commit b752a3cab6
1 changed files with 28 additions and 0 deletions

28
bin/import.sh Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
#
echo "Started..."
#Started...
#
# special variable $# is the number of arguments
if [ $# -lt 4 ] ; then
echo 'Call ./<script> <db name> <db user> <db schema> <CSV import file>'
exit 1
fi
#
DB_NAME="$1"
echo "DB_NAME: $DB_NAME"
DB_USER="$2"
echo "DB_USER: $DB_USER"
DB_SCHEMA="$3"
echo "DB_SCHEMA: ${DB_SCHEMA}"
IMPORT="$4"
echo "IMPORT: ${IMPORT}"
TABLE="${DB_SCHEMA}.stops"
echo "TABLE: ${TABLE}"
#
psql -h localhost -p 5432 -U $DB_USER -f ../sql/create-table.sql -d $DB_NAME -v schema=$DB_SCHEMA
#
psql -h localhost -p 5432 -U $DB_USER -c "\\copy $TABLE FROM '$IMPORT' DELIMITER ',' CSV HEADER;" -d $DB_NAME
#
echo "Done."
#done.