update.sh 1.5 KB

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