<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joseph Obukofe on Medium]]></title>
        <description><![CDATA[Stories by Joseph Obukofe on Medium]]></description>
        <link>https://medium.com/@josephobukofe?source=rss-8aa1b7d4bd95------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iIBpRrNkcms7H9Dmfyy9Ig.jpeg</url>
            <title>Stories by Joseph Obukofe on Medium</title>
            <link>https://medium.com/@josephobukofe?source=rss-8aa1b7d4bd95------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:25:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@josephobukofe/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a Bus Rapid Transit (BRT) Database]]></title>
            <link>https://medium.com/@josephobukofe/creating-a-bus-rapid-transit-brt-database-e8ec8e0309f5?source=rss-8aa1b7d4bd95------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8ec8e0309f5</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[database-development]]></category>
            <dc:creator><![CDATA[Joseph Obukofe]]></dc:creator>
            <pubDate>Mon, 12 Dec 2022 04:03:58 GMT</pubDate>
            <atom:updated>2022-12-12T04:03:58.144Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>A Database Engineering project using PostgreSQL</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_5r66mXycrkzd8PkFHt4g.jpeg" /><figcaption>Photo by Thgusstavo Santana: <a href="https://www.pexels.com/photo/bus-driving-on-road-at-night-5216911/">https://www.pexels.com/photo/bus-driving-on-road-at-night-5216911/</a></figcaption></figure><p>Preparatory steps taken to create the BRT database were to answer a number of questions and provide clarity on the context of the database and its use cases. They included:</p><ol><li>To define the purpose of the database. It included identifying the context around its definition.</li><li>To identify the users that would interact with the database. Data professionals like Data Analysts, Data Scientists and Data Engineers seeking to provide a system to store related information.</li></ol><p>Once these were duly answered and clarified, the next phase was to investigate the entities that would make up our database.</p><h4>Identifying the Entities</h4><p>An important step to consider when identifying the entities was to visualize how a BRT system works in a concise manner to avoid early data redundancies. In a metropolis like Lagos, users or passengers in this case book a trip, then board a bus going to their trip destination. The driver on the other hand conveys passengers with similar trip info and then drops them at their destination.</p><h4>Visualizing the Process Flow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IxfWuYiJPqz1x97OHmalTw.png" /><figcaption>BRT Database Process Flow by (Obukofe Joseph)</figcaption></figure><p>Major entities in our flow are the</p><ol><li>Passengers</li><li>Drivers</li><li>Vehicles</li><li>Trips</li><li>Route Locations</li></ol><p>Our database tables are complete! Or so we thought, but how about we answer the following questions to ascertain that?</p><ol><li>How are trips initialised? If it is due to payments made, then what would the payment method be to effectively limit it to a payment per passenger?</li><li>Are there payment methods possible for a group trip?</li><li>How do we show records of trips taken by passengers? Do duplicate records have to be inserted?</li><li>How do we make sure that the drivers we have are qualified for the job? Age? License status? Vehicle status?</li><li>Since we have a record of vehicles, what method do we initiate to pair a driver with a vehicle? And so if a pairing is done, how do we show that?</li></ol><p>Seems almost impossible with our “complete” database right? The possibilities of redundancies and inconsistencies are endless, thus we would need to introduce new entities to tackle the functionality issue, as well making our database tables normalized.</p><p>Firstly, I introduced a card entity named (passenger_cards). This introduces a payment method which lets passengers pay for their trips on the go, as well as acts as a form of identification to uniquely identify a passenger as it is linked to the phone number of the passenger. Similar to the Cowry cards used in BRT trips in Lagos, Nigeria. However, it is possible that a passenger would have more than one card as passengers could have multiple phone numbers.</p><p>All payments would be done via a single card linked to a single passenger as the payment is for a single trip. Hence no options are available for group trips or “sub trips”</p><pre>CREATE TABLE &quot;passenger_cards&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;card_number&quot; varchar(10) UNIQUE NOT NULL,<br>  &quot;issue_date&quot; date DEFAULT NOW(),<br>  &quot;phone_number&quot; varchar(12) UNIQUE NOT NULL,<br>  &quot;passenger_id&quot; integer NOT NULL,<br>  FOREIGN KEY (&quot;passenger_id&quot;) REFERENCES &quot;passengers&quot; (&quot;id&quot;) ON DELETE CASCADE ON UPDATE CASCADE<br>);</pre><p>When I further attempted to “denormalize” the database by adding both the passenger data with the trip data, it led to a lot of data discrepancy as duplicate values would be recorded for the passenger data. Assuming I added columns for trips taken given as trips1, trips2, trips3 … trips(n) on the denormalized passenger&#39;s table, there’s no guarantee that passengers would have that much number of trips. Hence the denormalized table would have null values for those records. For this, I needed to introduce a weak entity that acted as a bridge table between the (passengers) table and the (trips) table. I named this entity (passenger_trips).</p><pre>CREATE TABLE &quot;passenger_trips&quot; (<br>  &quot;id&quot; SERIAL,<br>  &quot;passenger_id&quot; integer NOT NULL,<br>  &quot;trip_id&quot; integer NOT NULL,<br>  &quot;price&quot; decimal NOT NULL,<br>  PRIMARY KEY (&quot;passenger_id&quot;, &quot;trip_id&quot;), -- Composite keys bearing the not null and unique attributes due the primary key characteristics<br>  FOREIGN KEY (&quot;passenger_id&quot;) REFERENCES &quot;passengers&quot; (&quot;id&quot;) ON UPDATE CASCADE ON DELETE CASCADE,<br>  FOREIGN KEY (&quot;trip_id&quot;) REFERENCES &quot;trips&quot; (&quot;id&quot;) ON DELETE RESTRICT -- Deleting from the trips table would lead to a violation of this foreign key constraint<br>);</pre><p>But hold on, there’s more. A passenger wouldn’t physically appear on two trips with the same trip info, right? However, it’s possible for a single trip to house various passengers. Hence the need to add a primary composite key on both the “passenger_id” and the “trip_id” columns. This prevents duplicate keys from being entered for both columns. Recall that the trip from the passenger&#39;s point of view is a single instance; meaning a passenger pays for one and only one trip at a time. But for the driver, a trip involves multiple passengers with related trip info. In the database, the trip granularity would be in focus from the driver&#39;s point of view as it denotes multiple instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Njc5mrrg1TRo4sgOQ_DIUw.png" /><figcaption>Dependency Instances between passengers and drivers for trips taken by (Obukofe Joseph)</figcaption></figure><p>The same concept goes for (vehicle — driver) pairings. However, it is possible that a driver may be paired with a particular vehicle more than once. As well as a vehicle being driven by more than one driver.</p><pre>CREATE TABLE &quot;driver_vehicle_logs&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;driver_id&quot; integer NOT NULL,<br>  &quot;vehicle_id&quot; integer NOT NULL,<br>  &quot;pair_date&quot; date DEFAULT NOW(), -- Left untouched for future records. <br>  FOREIGN KEY (&quot;driver_id&quot;) REFERENCES &quot;drivers&quot; (&quot;id&quot;) ON UPDATE CASCADE ON DELETE CASCADE,<br>  FOREIGN KEY (&quot;vehicle_id&quot;) REFERENCES &quot;vehicles&quot; (&quot;id&quot;) ON UPDATE CASCADE ON DELETE CASCADE<br>);</pre><p>A driver may only be paired on one condition; the status of the vehicle is listed as “Available”. A vehicle that is paired with a driver is denoted with an “In use” status. Consider the code snippet below.</p><pre>CREATE TABLE &quot;vehicles&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;vin&quot; varchar(20) UNIQUE NOT NULL,<br>  &quot;plate_number&quot; varchar(10) UNIQUE NOT NULL,<br>  &quot;model&quot; varchar(50) NOT NULL,<br>  &quot;capacity&quot; integer NOT NULL,<br>  &quot;status&quot; varchar(20) NOT NULL CHECK(status IN (&#39;Available&#39;, &#39;In use&#39;, &#39;Under maintenance&#39;, &#39;Out of use&#39;))<br>);</pre><blockquote>The policy of pairings denotes that on registration, a driver is paired with a vehicle if it’s free and unpaired, as well as the driver being duly qualified for the job.</blockquote><p>The records in the “pair_date” column should also be less than or equal to the “departure_date” column for the (trips) tables. For a driver to be qualified for trips, he/she must be duly identified with a</p><ol><li>A National Identity Number (NIN)</li><li>An Identification card issued by the BRT company</li><li>A valid driver&#39;s license</li></ol><p>A driver upon registration is issued an ID card bearing a unique 5-character code. He/She must also be above 25 years of age and should have a valid driver&#39;s license. The policy also denotes that he/she must have been driving a year or more after being issued a license.</p><pre>CREATE TABLE &quot;driver_identification_cards&quot; (<br>  &quot;id&quot; SERIAL,<br>  &quot;card_no&quot; char(5) PRIMARY KEY,<br>  &quot;issue_date&quot; date DEFAULT NOW(),<br>  &quot;driver_id&quot; integer UNIQUE NOT NULL, -- Enforcing a 1-1 relationship <br>  FOREIGN KEY (&quot;driver_id&quot;) REFERENCES &quot;drivers&quot; (&quot;id&quot;) ON UPDATE CASCADE ON DELETE CASCADE<br>);</pre><p>Also, I needed to keep track of the driver’s contact lines as it is possible a driver would have more than one phone number. To this effect, I introduced an entity called (driver_additional_details). This keeps records of phone numbers with their associated driver (driver_id).</p><pre>CREATE TABLE &quot;driver_additional_details&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;phone_number&quot; varchar(12) UNIQUE NOT NULL,<br>  &quot;driver_id&quot; integer NOT NULL,<br>  FOREIGN KEY (&quot;driver_id&quot;) REFERENCES &quot;drivers&quot; (&quot;id&quot;) ON UPDATE CASCADE ON DELETE CASCADE<br>);</pre><p>So far, the database became more robust as issues based on functionality were rectified. For clarity the following new entities were introduced to our database:</p><ol><li>passenger_cards</li><li>passenger_trips</li><li>driver_vehicle_logs</li><li>driver_identification_cards</li><li>driver_additional_details</li><li>license</li></ol><h4>Identifying the Relationships</h4><p>The next step would be to identify the relationships between the entities in our BRT database and if present, <em>map the cardinalities</em> for each.</p><p>As aforementioned, a solid foundation for relationships between a few entities was established by the introduction of bridge tables with a 1:M relationship; (passenger_trips) and (driver_vehicle_logs). However, let’s consider the drivers and trips table. A driver could make zero or many trips but a trip can only be done by one and only one driver. This relationship is denoted as a <em>One-to-Many relationship</em>, as the parent table in this case would be the driver&#39;s table, and the child table would be the trips table.</p><p>If we consider a typical parent—child relationship, the foreign key in the child table acts like DNA, a strand that references the existence of the parent in the child’s body. So without the parent, the child would not exist. This concept is something I’d like to call <strong><em>“Existence Dependency”</em></strong>. Cool right?</p><p>Consider the related entities and their relationships</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63EqAbQkp83bo8gTUPdQbg.png" /><figcaption>Table showing related entities and the relationships between them</figcaption></figure><p>The only standalone entity in the database is the (corridor_location) entity that lists the various corridor locations accessible for bus transits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xZ3e2ri81OZJjV77i0NHg.png" /><figcaption>ERD showing the entities and the relationships between them</figcaption></figure><p>One major thing to note is the CASCADING function for FK’s (Foreign Keys). To “cascade” in SQL means to ensure that changes made to the parent table (particularly updates and deletes) should directly affect the child table due to the existence of a reference made by the FK. The essence of cascading the keys is to maintain what is known as Referential Integrity.</p><h4>Adding Default Values</h4><blockquote>Default Values are user-defined values that are imposed to be inserted to a NULL column in a table</blockquote><p>Some of the default values I added to the columns of my database included:</p><ol><li>NOW( )</li><li>‘TBD’ (To be determined)</li></ol><p>The NOW( ) function determines the current date information. This was used to determine the issue date for (passenger_cards) as new card information was inserted into the database. It was also used in a CHECK constraint to determine the qualifications for drivers in our database.</p><p>‘TBD’ is a string value that is added to the license status as a default value, as the column would be left untouched during data insertion.</p><pre>&quot;license_status&quot; varchar(7) DEFAULT(&#39;TBD&#39;), -- Left untouched</pre><h4>Adding Constraints</h4><blockquote>Constraints are sets of rules imposed on a table (or column) that prevents the entry of improperly formatted data.</blockquote><p>The following constraints were added to the database tables to ensure data consistency and integrity.</p><ol><li>FOREIGN KEY</li><li>NOT NULL</li><li>UNIQUE</li><li>CHECK</li></ol><p>Check constraints are user-defined constraints to impose more specific rules to be followed. For example in the license table, check constraints were inserted to ensure</p><ol><li>Drivers were driving a year after their licenses were issued</li><li>Expiry dates are greater than issue dates</li><li>The difference between the expiry and issue dates is equal to 5 (to conform to the national standard of a 5-year validity)</li></ol><pre>CREATE TABLE &quot;license&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;license_number&quot; varchar(12) UNIQUE NOT NULL,<br>  &quot;issue_date&quot; date NOT NULL CHECK((date_part(&#39;year&#39;, NOW()) - date_part(&#39;year&#39;, issue_date)) &gt; 1),<br>  &quot;expiry_date&quot; date NOT NULL CHECK(expiry_date &gt; issue_date),<br>  &quot;license_status&quot; varchar(7) DEFAULT(&#39;TBD&#39;), -- Left untouched<br>  &quot;driver_id&quot; integer UNIQUE, -- Enforcing a 1-1 relationship<br>  FOREIGN KEY (&quot;driver_id&quot;) REFERENCES &quot;drivers&quot; (&quot;id&quot;)  ON UPDATE CASCADE ON DELETE CASCADE<br>);</pre><p>Licenses are invalid (expired) if the present date of use is outside the validity period. To denote that, I inserted a CASE block to run checks based on a condition. I initially aimed to insert a CASE block into a CHECK constraint but it only accepts scalar arguments, hence the need to run the check in an UPDATE syntax.</p><pre>UPDATE brt.license<br>SET license_status = (CASE WHEN date_part(&#39;year&#39;, NOW() &gt; date_part(&#39;year&#39;, expiry_date) THEN &#39;Expired&#39; ELSE &#39;Valid&#39; END) <br>WHERE license_status = &#39;TBD&#39;;</pre><p>CHECK constraints were also imposed on the driver&#39;s and passenger&#39;s table to check genders being either M (Male), F (Female) or Others (O).</p><pre>CREATE TABLE &quot;drivers&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;first_name&quot; varchar(20) NOT NULL,<br>  &quot;last_name&quot; varchar(20) NOT NULL,<br>  &quot;gender&quot; char(1) NOT NULL CHECK(gender IN (&#39;M&#39;, &#39;F&#39;, &#39;0&#39;)),<br>  &quot;email_address&quot; varchar(50) UNIQUE NOT NULL,<br>  &quot;address&quot; varchar(100) NOT NULL,<br>  &quot;date_of_birth&quot; date CHECK((date_part(&#39;year&#39;, NOW()) - date_part(&#39;year&#39;, date_of_birth)) &gt; 25), -- This validates that any driver recorded should be above 25 years of age<br>  &quot;national_identity_number&quot; char(11) UNIQUE NOT NULL<br>);<br><br>CREATE TABLE &quot;passengers&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;first_name&quot; varchar(20) NOT NULL,<br>  &quot;last_name&quot; varchar(20) NOT NULL,<br>  &quot;gender&quot; char(1) NOT NULL CHECK(gender IN (&#39;M&#39;, &#39;F&#39;, &#39;O&#39;)),<br>  &quot;email_address&quot; varchar(50) UNIQUE NOT NULL,<br>  &quot;address&quot; varchar(100) NOT NULL <br>); </pre><p>Also on the trips table to ensure the following.</p><ol><li>The arrival location is not the same as the departure location</li><li>The arrival time is greater than the departure time</li><li>Trip capacity is a positive number (greater than 0)</li></ol><pre>CREATE TABLE &quot;trips&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;departure_location&quot; varchar(20) NOT NULL,<br>  &quot;arrival_location&quot; varchar(20) NOT NULL CHECK(arrival_location &lt;&gt; departure_location), -- This validates that arrival location is not equal to departure location<br>  &quot;departure_time&quot; timestamp NOT NULL,<br>  &quot;arrival_time&quot; timestamp NOT NULL CHECK(arrival_time &gt; departure_time), -- This ensures that arrival time is greater than departure time<br>  &quot;driver_id&quot; integer NOT NULL,<br>  &quot;trip_capacity&quot; integer NOT NULL CHECK(trip_capacity &gt; 0), -- This ensures that no driver conveys zero passengers<br>  FOREIGN KEY (&quot;driver_id&quot;) REFERENCES &quot;drivers&quot; (&quot;id&quot;) ON UPDATE CASCADE ON DELETE CASCADE<br>);</pre><p>As earlier mentioned where the status column in the vehicles relation plays a major role in the pairing of vehicles to drivers, CHECK constraints are inserted to impose the status of vehicles as either “Available”, “In use”, “Under maintenance” or “Out of use”.</p><pre>CREATE TABLE &quot;vehicles&quot; (<br>  &quot;id&quot; SERIAL PRIMARY KEY,<br>  &quot;vin&quot; varchar(20) UNIQUE NOT NULL,<br>  &quot;plate_number&quot; varchar(10) UNIQUE NOT NULL,<br>  &quot;model&quot; varchar(50) NOT NULL,<br>  &quot;capacity&quot; integer NOT NULL,<br>  &quot;status&quot; varchar(20) NOT NULL CHECK(status IN (&#39;Available&#39;, &#39;In use&#39;, &#39;Under maintenance&#39;, &#39;Out of use&#39;))<br>);</pre><p>So far, we’ve been able to successfully build a database from scratch by Identifying the major entities, Identifying relationships between them, mapping cardinalities as shown in the ERD diagram, Creating constraints and integrity regulations to protect our database from improperly formatted data and so on. But what is a database without data right?</p><p>In order to fully test the integrity and functionality of our database, test data has to be inserted.</p><blockquote>Disclaimer: In order to protect sensitive information that would fit the context of our database tables and functionality, dummy data were created. These are randomly generated values to enable us work with data and test our database effectively</blockquote><p>Kindly find the test data <a href="https://drive.google.com/drive/folders/165ZvcTz81stNGoVjG5t7dfZp_umqhYnh?usp=share_link"><strong>here</strong></a></p><p><strong>Tools used: MS Excel</strong></p><p>For example, consider the following tables</p><ol><li>passengers</li><li>drivers</li><li>vehicles</li></ol><p>The passenger table has the following columns</p><ol><li>first_name</li><li>last_name</li><li>gender</li><li>email_address</li><li>address</li></ol><p>Considerations made were ethnicities would be between the major ethnic groups in Nigeria; Hausa, Igbo and Yoruba, so randomly generated names were made to that effect. As well as genders to the names; either <strong>M</strong> or <strong>F</strong>. Email addresses were in the following format: <strong>[first_name].[last_name] @example.com</strong>. Random addresses were generated as well with a possibility of two or more passengers staying in the same location.</p><p>The vehicle table on the other hand contains the following columns:</p><ol><li>VIN — CK</li><li>plate_number — CK</li><li>model</li><li>capacity</li><li>status</li></ol><p>Research shows that known models for transit passenger buses range from <em>Model Primero</em> to <em>Marcopolo</em> models. The primary model used in the Lagos BRT is the <em>Marcopolo Scania</em>. Other models like the <em>Marcopolo Ideale</em> were also considered. VIN and plate_number records were generated according to international and national standards and formats respectively.</p><p>One thing to note was to consider the method by which the data would be imported to PostgreSQL (which was by the direct import option). In response to this, I had to consider the following rules for a successful import operation.</p><ol><li>Datasets had to be saved in a CSV format as the data was created using MS Excel.</li><li>The column headers in the CSV file should be the column names in the database tables</li><li>The data types in the columns also had to match the ones in the columns of the database tables</li></ol><p>Once rules were met, the direct import was successful</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bCIEK9bnRoVmyqpsJRj1OA.png" /><figcaption>Import Processes in PostgreSQL by (Obukofe Joseph)</figcaption></figure><h4>Running Test Queries</h4><p>In order to test the functionality of the database, I ran some simple queries. One of which was to run a query that aims to find the top ten passengers with the highest number of trips. The company is looking to run a discount for frequent passengers with respect to the number of trips taken. Note that the database at this point is already normalized so we’d have to join two tables in this case; the passenger_trips and the passenger&#39;s table. The query would look like this:</p><pre>WITH CTE1 AS <br>(<br>  SELECT <br>   DISTINCT passenger_id,<br>   COUNT(trip_id) as no_of_trips<br>  FROM brt.passenger_trips<br>  GROUP BY distinct passenger_id<br>)<br><br>SELECT <br> first_name,<br> last_name,<br> gender,<br> email_address,<br> no_of_trips<br>FROM brt.passengers p<br>JOIN CTE1<br> ON CTE1.passenger_id = p.id<br>ORDER BY no_of_trips DESC<br>LIMIT 10;</pre><p>This would yield:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*elOG8-epjclfZmBe6dExRQ.png" /></figure><p>Using the PostgreSQL Visualizer to create a data visualization based on the query results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GPBEc25C4L1bOQXaGMYyOw.png" /><figcaption>Bar Chart showing the passengers and number of trips taken by (Obukofe Joseph)</figcaption></figure><p>Or we would like to continue with the vehicle—driver pairings so we want to know the available vehicles, we could run a query like this:</p><pre>SELECT *<br>FROM brt.vehicles<br>WHERE status = &#39;Available&#39;;</pre><p>The results of the query are given as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8UDODh_c1Gp3Fy30q4YDwQ.png" /></figure><h4>Creating Indexes</h4><p>So far, we have been able to run basic tests on our newly formed database with simple queries, but most times searching and filtering operations would begin to underperform as our database scales vertically. Since we have a fairly small database with the largest tuples of our dataset of about 1000, we could disregard the need for adding indexes as the DBMS would rather run a sequential scan than a bitmap index (especially in cases where the filter returns multiple values). However, we should consider the possibility of scaling and hence indexes were added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SfNI3HyIwzsmsesjZX_bMg.png" /><figcaption>Table showing Index Definitions by (Obukofe Joseph)</figcaption></figure><p>The comprehensive index definition is given in the snippet below:</p><pre>-- INDEX DEFINITION<br><br>DROP INDEX IF EXISTS brt_vehicles_id_idx;<br>CREATE INDEX brt_vehicles_id_idx<br>ON brt.vehicles(id);<br><br>CLUSTER brt.vehicles USING brt_vehicles_id_idx;<br><br>DROP INDEX IF EXISTS brt_driver_vehicle_logs_driver_id_vehicle_id_idx;<br>CREATE INDEX brt_driver_vehicle_logs_driver_id_vehicle_id_idx<br>ON brt.driver_vehicle_logs (driver_id, vehicle_id);<br><br>DROP INDEX IF EXISTS brt_drivers_first_name_last_name_idx;<br>CREATE INDEX brt_drivers_first_name_last_name_idx<br>ON brt.drivers (first_name, last_name);<br><br>DROP INDEX IF EXISTS brt_driver_identification_cards_driver_id;<br>CREATE INDEX brt_driver_identification_cards_driver_id<br>ON brt.driver_identification_cards (driver_id);<br><br>DROP INDEX IF EXISTS brt_driver_additional_details_driver_id_idx;<br>CREATE INDEX brt_driver_additional_details_driver_id_idx<br>ON brt.driver_additional_details (driver_id);<br><br>DROP INDEX IF EXISTS brt_license_driver_id;<br>CREATE INDEX brt_license_driver_id<br>ON brt.license (driver_id);<br><br>DROP INDEX IF EXISTS brt_trips_id;<br>CREATE INDEX brt_trips_id<br>ON brt.trips (id);<br><br>CLUSTER brt.trips USING brt_trips_id;<br><br>DROP INDEX IF EXISTS brt_trips_driver_id;<br>CREATE INDEX brt_trips_driver_id<br>ON brt.trips (driver_id);<br><br>DROP INDEX IF EXISTS brt_passenger_trips_passenger_id_trip_id_idx;<br>CREATE INDEX brt_passenger_trips_passenger_id_trip_id_idx<br>ON brt.passenger_trips (passenger_id, trip_id);<br><br>DROP INDEX IF EXISTS brt_passenger_cards_passenger_id_idx;<br>CREATE INDEX brt_passenger_cards_passenger_id_idx<br>ON brt.passenger_cards (passenger_id);</pre><h4>Backup Processes</h4><p>A database should always be backed up in case of file damage or loss. Here I backed up the database with a (.tar) file setting and a read-data permission, as well as UTF-8 encoding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8ec8e0309f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>