feat: improve error handling in HTTP requests and database fixture loading
This commit is contained in:
+28
-9
@@ -16,16 +16,35 @@ if [ ! -f "$DB_PATH" ] && [ -f "$LEGACY_DB_PATH" ]; then
|
||||
cp "$LEGACY_DB_PATH" "$DB_PATH"
|
||||
fi
|
||||
|
||||
if [ ! -f "$DB_PATH" ] && [ "${LOAD_FIXTURE_ON_EMPTY_DB:-true}" = "true" ]; then
|
||||
python manage.py migrate
|
||||
if [ -f "$DUMP_SRC" ]; then
|
||||
TMP_DUMP="$(mktemp)"
|
||||
python /app/scripts/rewrite_dumps.py "$DUMP_SRC" "$TMP_DUMP"
|
||||
python manage.py loaddata "$TMP_DUMP"
|
||||
rm -f "$TMP_DUMP"
|
||||
python manage.py migrate
|
||||
|
||||
should_load_fixture=0
|
||||
if [ "${LOAD_FIXTURE_ON_EMPTY_DB:-true}" = "true" ] && [ -f "$DUMP_SRC" ]; then
|
||||
if [ ! -s "$DB_PATH" ]; then
|
||||
should_load_fixture=1
|
||||
else
|
||||
entity_conf_count="$(python manage.py shell -c '
|
||||
from django.db import connection
|
||||
table = "spid_cie_oidc_entity_federationentityconfiguration"
|
||||
with connection.cursor() as cursor:
|
||||
tables = connection.introspection.table_names(cursor)
|
||||
if table not in tables:
|
||||
print(0)
|
||||
else:
|
||||
cursor.execute(f"SELECT COUNT(*) FROM {table}")
|
||||
print(cursor.fetchone()[0])
|
||||
')"
|
||||
if [ "${entity_conf_count:-0}" = "0" ]; then
|
||||
should_load_fixture=1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
python manage.py migrate
|
||||
fi
|
||||
|
||||
if [ "$should_load_fixture" = "1" ]; then
|
||||
TMP_DUMP="$(mktemp)"
|
||||
python /app/scripts/rewrite_dumps.py "$DUMP_SRC" "$TMP_DUMP"
|
||||
python manage.py loaddata "$TMP_DUMP"
|
||||
rm -f "$TMP_DUMP"
|
||||
fi
|
||||
|
||||
python /app/scripts/normalize_db_urls.py "$DB_PATH"
|
||||
|
||||
Reference in New Issue
Block a user