Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't deprovision within running Kolibri to create preseeded DBs #12184

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading