This is the PostgreSQL and PostGIS database for the mobile library project. It stores timetables, stops, driving routes, and estimated live vehicle locations across the UK.
Upstream data is maintained in the LibrariesHacked/mobilelibraries-data repository.
To run this database you will need PostgreSQL (version 10+) with the PostGIS extension installed.
To initialize a brand new database and load all tables, views, functions, and data:
psql --set=sslmode=require -f create.sql -h <host> -p 5432 -U <username> postgresOn Windows, a template script is provided in create.bat.template.
To update an existing live database with the latest stops, routes, and schedule estimates transactionally without recreating schema or views:
psql --set=sslmode=require -f update.sql -h <host> -p 5432 -U <username> mobilesOn Windows, a template script is provided in update.bat.template.
Data files in data/ and data/routes/ are synced from LibrariesHacked/mobilelibraries-data.
To manually sync data locally and regenerate load.sql and update.sql:
# Automatically detects sibling ../mobilelibraries-data or clones from GitHub
python scripts/sync_data.py
# Or specify a custom source directory
python scripts/sync_data.py --source /path/to/mobilelibraries-dataThe sync script automatically:
- Copies all 48 authority stop datasets into
data/. - Copies all corresponding route road geometries into
data/routes/. - Synchronises
data/organisations.csvwith official service and GSS codes. - Generates an alphabetical, deterministic
load.sqlreferencing all active services. - Generates the atomic
update.sqltransaction script.
A GitHub Actions workflow is configured in .github/workflows/sync_and_update.yml.
- Schedule: Runs nightly at 02:00 UTC.
- Manual trigger: Can be triggered at any time via
workflow_dispatchin the GitHub Actions tab. - Webhook dispatch: Can be triggered via
repository_dispatch(event typemobilelibraries_data_updated) frommobilelibraries-data. - Workflow actions:
- Clones the latest data from
LibrariesHacked/mobilelibraries-data. - Runs
scripts/sync_data.pyto sync datasets and regenerateload.sql. - Commits and pushes any changed data back to this repository.
- Connects to PostgreSQL via
psqland executesupdate.sqlto refresh the live database.
- Clones the latest data from
To enable the automated database update step in GitHub Actions, add these repository secrets:
PGHOST: Database server hostname (e.g.librarieshacked.postgres.database.azure.com)PGUSER: Database usernamePGPASSWORD: Database user passwordPGDATABASE: Database name (defaults tomobiles)PGPORT: Port number (defaults to5432)
- Dave Rowe - Initial work - Libraries Hacked
See the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- All UK mobile library services and operators.