Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
critiquebrainz/frontend/external/bookbrainz_db/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.pool import NullPool | ||
|
||
DEFAULT_CACHE_EXPIRATION = 12 * 60 * 60 # seconds (12 hours) | ||
bb_engine = None | ||
|
||
|
||
def init_db_engine(connect_str): | ||
global bb_engine | ||
bb_engine = create_engine(connect_str, poolclass=NullPool) | ||
|
||
|
||
def run_sql_script(sql_file_path): | ||
with open(sql_file_path) as sql: | ||
connection = bb_engine.connect() | ||
connection.execute(sql.read()) | ||
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
CREATE USER bookbrainz WITH SUPERUSER PASSWORD 'bookbrainz'; | ||
CREATE DATABASE bookbrainz; | ||
GRANT ALL PRIVILEGES ON DATABASE bookbrainz TO bookbrainz; | ||
EOSQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
CREATE USER critiquebrainz WITH SUPERUSER PASSWORD 'critiquebrainz'; | ||
CREATE DATABASE critiquebrainz; | ||
GRANT ALL PRIVILEGES ON DATABASE critiquebrainz TO critiquebrainz; | ||
EOSQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
DB_HOSTNAME=db | ||
DB_PORT=5432 | ||
DB_USER=bookbrainz | ||
DB_NAME=bookbrainz | ||
DB_PASSWORD=bookbrainz | ||
|
||
DUMP_DIR=/tmp/bookbrainz-dumps | ||
DUMP_FILE=$DUMP_DIR/latest.sql.bz2 | ||
|
||
if [ -f $DUMP_FILE ]; then | ||
echo "A bookbrainz dump file, already exists. Using that to import." | ||
echo "To force a re-download of the data, please remove $DUMP_FILE" | ||
else | ||
mkdir -p $DUMP_DIR | ||
curl -o $DUMP_FILE ftp://ftp.musicbrainz.org/pub/musicbrainz/bookbrainz/latest.sql.bz2 | ||
if [ $? -ne 0 ] | ||
then | ||
echo "Downloading the bookbrainz data dump failed." | ||
exit $? | ||
fi | ||
fi | ||
|
||
bzcat $DUMP_FILE | PGPASSWORD=$DB_PASSWORD psql -h $DB_HOSTNAME -p $DB_PORT -U $DB_USER -d $DB_NAME | ||
if [ $? -ne 0 ] | ||
then | ||
echo "Importing the bookbrainz database failed." | ||
exit $? | ||
fi | ||
|
||
# Clean up the dump file if it imported correctly. | ||
rm -f $DUMP_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters