#!/usr/bin/env bash set -eau -o pipefail NEEDED_COLUMNS=("IdentifiantImmeuble" "EtatImmeuble" "CoordonneeImmeubleX" "CoordonneeImmeubleY" "NumeroVoieImmeuble" "TypeVoieImmeuble" "NomVoieImmeuble" "CodePostalImmeuble" "CommuneImmeuble" "DateDebutAcceptationCmdAcces" "DateMiseEnServiceCommercialeImmeuble") if [ "$#" -ne 2 ]; then echo "Usage: ingest path-to-directory-containing-IPE-CSVs path-to-generated-db" echo "" exit 1 fi fullIpeDirPath=$(realpath "${1}") fullDbPath=$(realpath "${2}") tmpSql=$(mktemp) clean_tmp () { rm "${tmpSql}" } trap clean_tmp EXIT echo "[+] Ingesting IPE data." echo " The following files will be ingested." echo "" ipeFiles=$(find "${fullIpeDirPath}" -name '*.csv') cat > "${tmpSql}" < ${ipeFile}.cut useIpeFile=${ipeFile}.cut fi cat >> "${tmpSql}" <&1 | grep -v "filling the rest with NULL" || rc="${PIPESTATUS[0]}" if [[ $rc -ne 0 ]]; then echo "Error executing sqlite import" exit "$rc" fi echo "[+] Create separate table with id immeuble index and its state." cat > "${tmpSql}" < "${tmpSql}" < "${tmpSql}" <