From 44a0f928981d7ffe04468173b2e27f731d73a098 Mon Sep 17 00:00:00 2001 From: Robert Helmer Date: Mon, 17 Dec 2012 01:18:30 -0800 Subject: [PATCH] bug 822161 - better error checking for CSV import script --- tools/dataload/import.sh | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/dataload/import.sh b/tools/dataload/import.sh index ba438b44ac..e48c96753c 100755 --- a/tools/dataload/import.sh +++ b/tools/dataload/import.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -6,16 +6,35 @@ TABLES="os_names os_name_matches process_types products release_channels product_release_channels raw_adu release_channel_matches releases_raw uptime_levels windows_versions reports os_versions product_productid_map release_repositories crontabber_state" -for table in $TABLES -do - psql -c "COPY $table FROM '`pwd`/${table}.csv' WITH CSV HEADER" breakpad +function db { + sql=$1 + psql -c "$sql" breakpad > last_psql.log 2>&1 exit_code=$? if [ $exit_code != 0 ] then - echo "Failed to import ${table}" + echo "ERROR: SQL failed - $sql" + cat last_psql.log exit $exit_code fi + + # catch failures from SPs like backfill_matviews + grep "ERROR" last_psql.log + if [ $? == 0 ] + then + echo "ERROR: error found in output for $sql" + cat last_psql.log + exit 1 + fi +} + +echo "loading CSVs..." +for table in $TABLES +do + db "COPY $table FROM '`pwd`/${table}.csv' WITH CSV HEADER" done -psql -c "SELECT backfill_matviews('2012-12-11', '2012-12-12')" breakpad -psql -c "UPDATE product_versions SET featured_version = true" breakpad +echo "running backfill_matviews..." +db "SELECT backfill_matviews('2012-12-11', '2012-12-12')" +echo "setting all versions to featured..." +db "UPDATE product_versions SET featured_version = true" +echo "Done."