-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfetch-chinook-data.sh
executable file
·28 lines (23 loc) · 1.04 KB
/
fetch-chinook-data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# Pull the Chinook music SQLite database and load it into PostgreSQL.
# From The Art of Postgres: Chapter 5, A Small Application
CHINOOK_POSTGRESQL_DB_NAME=chinook
CHINOOK_SQLITE_DATASOURCE=https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite_AutoIncrementPKs.sqlite
until pg_isready 2>/dev/null; do
echo "Waiting for postgres to start"
sleep 1
done
if psql -lqt | cut -d \| -f 1 | grep -qw $CHINOOK_POSTGRESQL_DB_NAME; then
if [[ $1 == "--recreate" ]]; then
echo "--recreate flag was given, dropping database $CHINOOK_POSTGRESQL_DB_NAME"
dropdb $CHINOOK_POSTGRESQL_DB_NAME
else
echo "Chinook PostgreSQL database already exists, skipping"
echo "Include the --recreate flag if you want to drop and reseed the database"
exit 1
fi
fi
# echo "Creating PostgreSQL database"
createdb $CHINOOK_POSTGRESQL_DB_NAME
# echo "Fetching Chinook data and loading into local database"
pgloader $CHINOOK_SQLITE_DATASOURCE pgsql://[email protected]:5432/$CHINOOK_POSTGRESQL_DB_NAME