update.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. ENDPOINT="https://sirekanian.github.io/warmongr"
  5. SCHEMAS="app/schemas/org.sirekanyan.warmongr.data.local.Database"
  6. SCHEMA=$(find "$SCHEMAS" -name "*.json" | sort -V | tail -1)
  7. # transform data.json to csv
  8. wget --header="Accept-Encoding: gzip" -qO- "$ENDPOINT/data.json" | gunzip |
  9. jq -r 'map([.["0"],.["1"],.["4"],(.["5"] | join(" "))])[] | @csv' \
  10. >"app/schemas/WarmongerEntity.csv"
  11. # transform tags.json to csv
  12. wget -qO- "$ENDPOINT/tags.json" |
  13. jq -r 'map([.["id"],.["enShortName"],.["ruShortName"]])[] | @csv' \
  14. >"app/schemas/TagEntity.csv"
  15. # transform index.json to csv
  16. wget -qO- "$ENDPOINT/index.json" |
  17. jq -r 'to_entries[] | [.key, .value] | @csv' \
  18. >"app/schemas/IndexEntity.csv"
  19. # copy setupQueries from schema
  20. jq -r ".database.setupQueries[]" "$SCHEMA" |
  21. sed 's/$/;/' \
  22. >app/schemas/init.sql
  23. for TABLE in WarmongerEntity TagEntity IndexEntity; do
  24. # copy createSql from schema
  25. jq -r ".database.entities[] | select(.tableName==\"$TABLE\") | .createSql" "$SCHEMA" |
  26. sed "s/\${TABLE_NAME}/$TABLE/" |
  27. sed 's/$/;/'
  28. # generate import csv command
  29. echo ".mode csv"
  30. echo ".import app/schemas/$TABLE.csv $TABLE"
  31. done >>app/schemas/init.sql
  32. # recreate pre-packaged database
  33. rm -f app/src/main/assets/warmongers.db
  34. sqlite3 app/src/main/assets/warmongers.db <app/schemas/init.sql
  35. # commit changes
  36. git add app/schemas/*.csv
  37. git add app/schemas/init.sql
  38. git add app/src/main/assets/warmongers.db
  39. git commit -m "updated pre-packaged database" || true