MovR is a fictional vehicle-sharing company created to demonstrate CockroachDB's features.
The MovR example consists of the following:
movrdataset, which contains rows of data that populate tables in the
movrdataset is built into
- The MovR application, a fully-functional vehicle-sharing application, written in Python. All of MovR application source code is open-source, and available on the movr GitHub repository.
The six tables in the
movr database store user, vehicle, and ride data for MovR:
||People registered for the service.|
||The pool of vehicles available for the service.|
||When and where users have rented a vehicle.|
||Promotional codes for users.|
||Promotional codes in use by users.|
||Vehicle location history.|
Generating schemas and data for MovR
You can use the
cockroach demo and
cockroach workload commands to load the
movr database and dataset into a CockroachDB cluster.
$ cockroach demo movr
cockroach workload loads sample datasets and workloads into running clusters. To load the
movr database and some sample data into a running cluster, do the following:
- Start a secure or insecure local cluster.
cockroach workloadto load the
$ cockroach workload init movr 'postgresql://root@localhost:26257?sslcert=certs%2Fclient.root.crt&sslkey=certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=certs%2Fca.crt'copy
$ cockroach workload init movr 'postgresql://root@localhost:26257?sslmode=disable'
$ cockroach sql --certs-dir=certs --host=localhost:26257copy
> USE movr;copy
$ cockroach sql --insecure --host=localhost:26257copy
> USE movr;
How the MovR application works
The workflow for MovR is as follows (with approximations of the corresponding SQL for each step):
A user loads the app and sees the 25 closest vehicles:
> SELECT id, city, status, ... FROM vehicles WHERE city = <user location>
The user signs up for the service:
> INSERT INTO users (id, name, address, ...) VALUES ...
In some cases, the user adds their own vehicle to share:
> INSERT INTO vehicles (id, city, type, ...) VALUES ...
More often, the user reserves a vehicle and starts a ride, applying a promo code, if available and valid:
> SELECT code FROM user_promo_codes WHERE user_id = ...
> UPDATE vehicles SET status = 'in_use' WHERE ...
> INSERT INTO rides (id, city, start_addr, ...) VALUES ...
During the ride, MovR tracks the location of the vehicle:
> INSERT INTO vehicle_location_histories (city, ride_id, timestamp, lat, long) VALUES ...
The user ends the ride and releases the vehicle:
> UPDATE vehicles SET status = 'available' WHERE ...
> UPDATE rides SET end_address = <value> ...
For a tutorial about performance tuning in CockroachDB, see Performance Tuning.
For a tutorial on developing and deploying a multi-region web application for MovR, see Develop and Deploy a Multi-Region Web Application.