Skip to content

Commit

Permalink
make data_warning empty instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenglimEar committed Jul 16, 2024
1 parent f10a7a6 commit a0a322f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ do-import-spreadsheets:
echo 'ALTER TABLE "referendums" ADD COLUMN id SERIAL PRIMARY KEY;' | psql $(DATABASE_NAME)
./bin/remove-whitespace $(DATABASE_NAME) referendums Short_Title
./bin/remove-whitespace $(DATABASE_NAME) referendums Summary
./bin/remove-whitespace $(DATABASE_NAME) referendums data_warning
./bin/make-null-empty $(DATABASE_NAME) referendums data_warning

echo 'DROP TABLE IF EXISTS name_to_number CASCADE;' | psql $(DATABASE_NAME)
./bin/create-table $(DATABASE_NAME) $(CSV_PATH) name_to_number
Expand Down
20 changes: 20 additions & 0 deletions bin/make-null-empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Usage: ./bin/make-null-empty [database name] [table name] [column name]
# ./bin/make-null-empty disclosure-backend candidates Candidate
set -euo pipefail

if [ $# -ne 3 ]; then
echo 'Usage: ./bin/make-null-empty [database name] [table name] [column name]'
exit 1
fi

database_name=$1
table_name=$2
column_name=$3

# trim leading and trailing white spaces
cat <<-QUERY | psql ${database_name}
\\set ON_ERROR_STOP on
UPDATE "$table_name" t SET "$column_name" = '' WHERE "$column_name" IS NULL;
QUERY

0 comments on commit a0a322f

Please sign in to comment.