Work with a MDS provider
Postgres database.
This container uses the following environment variables to connect to the MDS database:
POSTGRES_HOSTNAME=server
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres_password
MDS_DB=mds_provider
MDS_USER=mds_provider
MDS_PASSWORD=mds_provider_password
This container comes with a number of sub-commands for interacting with a database using the configured environment.
docker-compose run db reset
docker-compose run db init
Setup postgres functions used in other views and calculations.
docker-compose run db functions
Run a migration script with the given version number.
docker-compose run db migrate VERSION
Where VERSION
is a version number like x.y.z
.
Create the availability
view and associated infrastructure.
Trips must be configured first.
docker-compose run db availability
docker-compose run db availability refresh
Create the deployments
views.
docker-compose run db deployments
From the current contents of the status_changes
table.
docker-compose run db deployments refresh
Create additional trips
and routes views.
docker-compose run db trips
docker-compose run db trips refresh
Run psql
commands in the container against $MDS_DB
as $MDS_USER
.
Enter into the psql
prompt:
$ docker-compose run db psql
server is available
psql <version info>
Type "help" for help.
mds_provider=> help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
mds_provider=>
Run a single query or command (e.g. the psql --command
option):
$ docker-compose run db query "select distinct provider_name from trips;"
server is available
provider_name
---------------
bird
Lime
JUMP
Lyft
(4 rows)
Execute queries or commands from a file (e.g. the psql --file
option):
$ docker-compose run db file trips/daily.sql
server is available
psql:trips/daily.sql:1: NOTICE: view "trips_daily" does not exist, skipping
DROP VIEW
CREATE VIEW