Updating and Communicating Between Databases

Script Overview for Updating Databases

There are serveral shell scripts and SQL queries run as cron jobs (automatically run scripts). These scripts automatically update databases by pulling data from ODK Central.

odk_to_update.sh

  • This is a bash script that automates API calls to ODK Central, unpacks CSV files and calls an SQL script to load the data onto the update schema. This shell script is run as a cron job twice per day.
  • The script must be updated to include the correct project and form ids. Where the API calls ODK Central, the API endpoint should follow the following format:
    https://ilrg.ddns.net/v1/projects/[project_ID]/forms/[XML_form_ID]/submissions.csv.zip?attachments=false
    

    ex:

      https://ilrg.ddns.net/v1/projects/3/forms/Village_Governance_v4/submissions.csv.zip?attachments=false
    
  • The API calls for forms with images in them will look slightly different, as the attachment=false is no longer true:
    https://ilrg.ddns.net/v1/projects/[project_ID]/forms/[XML_form_ID]/submissions.csv.zip?
    

    ex:

      https://ilrg.ddns.net/v1/projects/3/forms/Claims/submissions.csv.zip?
    
  • You can find the project ID and XML form ID by going to ODK Central, opening the form and looking at the URL in the address bar, it will look similar to the URL above.

ilrg_fzs.sh

  • Connects to the ilrg_fzs database and runs all of the update SQL scripts (described below), then commits those changes to the ilrg_fzs database.
  • To use this code yourself, you will need to upload all of the update_form…sql scripts into a folder on your server, and then adjust the code in ilrg_fzs.sh to match your file path and log in.
psql --host=localhost --port=5432 --dbname=yourdbname --username=yourusername     <<OMG
BEGIN;

\i yourFilePath/update_form_b_village_governance.sql
  • Run as a cron job 5 times per day.

update_form…sql Scripts

All of these scripts can be also be found under cron jobs in Webmin. In the next section, the documentation covers how parties are validated in a Microsoft Access tool.

Previous <> Next


This site serves as the technical documentation for the set up and use of ILRG's customary land documentation technology, an adaptation of USAID's MAST project.