Files
maps-saas/infrastructure/scripts/execute_import.sh
T
2026-04-12 22:35:38 +03:00

43 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Script to execute Syria data import on the server
# To be run from /home/hamzadoctor/app
APP_DIR="/home/hamzadoctor/app"
CSV_FILE="syria_final_complete.csv"
SQL_FILE="infrastructure/docker/postgis/import_syria_csv.sql"
echo "📦 Transferring CSV to PostGIS container..."
docker cp "$APP_DIR/$CSV_FILE" map-db:/tmp/syria_data.csv
echo "💾 Running SQL import script..."
# We use docker compose exec db psql to run the logic
# First, update the SQL logic to use the /tmp path for COPY
# We'll create a temporary SQL wrapper to handle the COPY command with the correct path
docker exec -i map-db psql -U mapuser -d mapdb <<EOF
-- Load schema
\i /home/hamzadoctor/app/$SQL_FILE
-- Perform COPY (must be done in the container pointing to /tmp/syria_data.csv)
CREATE TEMP TABLE staging_syria_temp (
name TEXT,
latitude DECIMAL(10, 8),
longitude DECIMAL(11, 8),
category TEXT,
address TEXT,
description TEXT,
created_at TIMESTAMP
);
COPY staging_syria_temp(name, latitude, longitude, category, address, description, created_at)
FROM '/tmp/syria_data.csv'
WITH (FORMAT csv, HEADER false, QUOTE '"', ENCODING 'UTF8');
INSERT INTO staging_syria SELECT * FROM staging_syria_temp;
DROP TABLE staging_syria_temp;
-- Final merge logic is already in the SQL file loaded via \i
EOF
echo "✅ Import completed successfully!"