Skip to content

Commit

Permalink
Merge pull request #1013 from rhelmer/bug822161-better-error-checking
Browse files Browse the repository at this point in the history
bug 822161 - better error checking for CSV import script
  • Loading branch information
lonnen committed Dec 17, 2012
2 parents 7241426 + 44a0f92 commit 97585f2
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions tools/dataload/import.sh
@@ -1,21 +1,40 @@
#!/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/.


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."

0 comments on commit 97585f2

Please sign in to comment.