Data Modelling

Nithesh Raaj
2 min readJul 4, 2017

--

Now that the prototype has been made for the app idea, and the dev environment has been setup (in which hasura local development was installed), the next step is the data modelling part.

Data modelling is the process of designing/creating the different tables that are needed along with the relation between the elements of the table.

I used PonyORM which has an online tool for designing data models.

Data Model created using PonyORM

This is the data model for my app Life saver. It consists of three tables: User, Service_Provider and Request.

When the user signs up, the name and phone number is saved in the User table.

When a service provider signs up, the name, phone number, type(Ambulance/Police/Fire Service), and their FCM Registration token is saved in the Service_Provider table. I am using Firebase Cloud Messaging to send the requests to the service providers. The FCM registration token is used to identify the service provider. The status attribute of Service_Provider stores information about if the service provider is free to accept a request. The lat and long attributes are updated as the location of the service provider changes.

When a user requests an emergency service, a new entry is made in the Request table. The user_id, lat_user, long_user, status, time_start attributes are set when the new entry is created. The status attribute is used to track the status of the request like request received/service provider assigned/request completed, etc. The time_start defaults to the time when the request is made. It can be used in future for analytics purpose.

Once a request is made, the server queries the Service_Provider table and uses Google Maps Distance Matrix API to determine the service provider who can reach the user quickest. This service provider gets the request as an alert through FCM, which can be accepted or rejected. If accepted the request details are sent to the user. If rejected the next quickest service provider gets the request.

The data model might undergo minor changes during the course of app development. I will update this article with the changes.

UPDATE:

During the development of the app, I realised that I had to send some data to the user via FCM, and thus I would need the FCM registration token of the user. I have added fcm_token attribute to User table to store the registration token. The updated Data Model is as below:

Data Model for Life Saver

--

--