Skip to content

Commit

Permalink
Merge pull request #12184 from bjester/unpreseed-db
Browse files Browse the repository at this point in the history
Don't deprovision within running Kolibri to create preseeded DBs
  • Loading branch information
rtibbles authored May 21, 2024
2 parents b3cb256 + 641e804 commit a5ec048
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_whl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install Ubuntu dependencies
run: |
apt-get -y -qq update
apt-get install -y gettext sudo
apt-get install -y gettext sudo sqlite3
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ writeversion:
@echo "Current version is now `cat kolibri/VERSION`"

preseeddb:
PYTHONPATH=".:$PYTHONPATH" python build_tools/preseed_home.py
./build_tools/preseed_home.sh

setrequirements:
rm -r requirements.txt || true # remove requirements.txt
Expand Down
32 changes: 0 additions & 32 deletions build_tools/preseed_home.py

This file was deleted.

48 changes: 48 additions & 0 deletions build_tools/preseed_home.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -eux -o pipefail

# Assumes this script is run from the project root
PROJECT_ROOT="$(pwd)"
KOLIBRI_HOME="$(mktemp -d)"
PYTHONPATH="${PYTHONPATH:-}"

# Prepend project root to python path
if [ -n "$PYTHONPATH" ]; then
PYTHONPATH="${PROJECT_ROOT}:${PYTHONPATH}"
else
PYTHONPATH="${PROJECT_ROOT}"
fi

export KOLIBRI_HOME
export PYTHONPATH

# Clean existing DBs and generate fresh DBs
rm -rf kolibri/dist/home
(cd kolibri && python -m kolibri manage deprovision --destroy-all-user-data --permanent-irrevocable-data-loss)
mkdir -p kolibri/dist/home
cp $KOLIBRI_HOME/*.sqlite3 kolibri/dist/home/
rm -rf $KOLIBRI_HOME

# disable command echoing
set +x

# Verify DBs
declare -A QUERY_MATRIX
QUERY_MATRIX["select count(*) from morango_databaseidmodel;"]="db.sqlite3"
QUERY_MATRIX["select count(*) from morango_instanceidmodel;"]="db.sqlite3"
QUERY_MATRIX["select count(*) from discovery_networklocation;"]="networklocation.sqlite3"
QUERY_MATRIX["select count(*) from jobs;"]="job_storage.sqlite3"

echo "Verifying databases..."

for QUERY in "${!QUERY_MATRIX[@]}"; do
DB=${QUERY_MATRIX[$QUERY]}
ROW_COUNT=$(sqlite3 -cmd ".headers off" kolibri/dist/home/$DB "$QUERY")
if [ "$ROW_COUNT" -ne 0 ]; then
echo "Preseeded DBs have existing data | $ROW_COUNT = $QUERY"
exit 1
fi
done

echo "Done! Preseeded databases generated"

0 comments on commit a5ec048

Please sign in to comment.