{"id":1490,"date":"2025-01-20T12:56:25","date_gmt":"2025-01-20T12:56:25","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=1490"},"modified":"2025-01-20T12:56:27","modified_gmt":"2025-01-20T12:56:27","slug":"low-level-design-of-partner-and-renter-relationship-of-vehicle-booking-software","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/low-level-design-of-partner-and-renter-relationship-of-vehicle-booking-software\/","title":{"rendered":"Low Level Design of Partner and Renter Relationship of Vehicle Booking Software"},"content":{"rendered":"\n<p>Based on the partial schema loaded from the provided SQL file, we can analyze and enhance the database design for <strong>Approach-2<\/strong>, where a single user can have multiple roles (e.g., Renter and Partner). Let&#8217;s go step-by-step:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Existing Schema Observations<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>addvechicles<\/code> Table<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Appears to manage vehicle listings with attributes like:\n<ul class=\"wp-block-list\">\n<li><code>id<\/code>, <code>vender_ID<\/code>, <code>shop_id<\/code>, <code>vehical_id<\/code>, <code>brand<\/code>, <code>model<\/code>, etc.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Likely used for Partners to list their vehicles.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Additional tables are likely present for users, bookings, or other entities, but they were not visible in the preview.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Recommended Database Schema for Approach-2<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Core Tables<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Users Table<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Centralized user information.<\/li>\n\n\n\n<li>Fields:\n<ul class=\"wp-block-list\">\n<li><code>id<\/code> (Primary Key)<\/li>\n\n\n\n<li><code>name<\/code><\/li>\n\n\n\n<li><code>email<\/code> (Unique)<\/li>\n\n\n\n<li><code>mobile_number<\/code> (Unique)<\/li>\n\n\n\n<li><code>password<\/code><\/li>\n\n\n\n<li><code>created_at<\/code>, <code>updated_at<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Roles Table<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Stores role definitions (e.g., Renter, Partner).<\/li>\n\n\n\n<li>Fields:\n<ul class=\"wp-block-list\">\n<li><code>id<\/code> (Primary Key)<\/li>\n\n\n\n<li><code>name<\/code> (e.g., &#8216;Renter&#8217;, &#8216;Partner&#8217;)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>UserRoles Table<\/strong> (Many-to-Many Relationship):\n<ul class=\"wp-block-list\">\n<li>Links users with roles.<\/li>\n\n\n\n<li>Fields:\n<ul class=\"wp-block-list\">\n<li><code>id<\/code> (Primary Key)<\/li>\n\n\n\n<li><code>user_id<\/code> (Foreign Key to <code>Users<\/code>)<\/li>\n\n\n\n<li><code>role_id<\/code> (Foreign Key to <code>Roles<\/code>)<\/li>\n\n\n\n<li><code>status<\/code> (e.g., Active\/Inactive)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Additional Role-Specific Tables<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Vehicles Table<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Tracks vehicles listed by Partners.<\/li>\n\n\n\n<li>Fields:\n<ul class=\"wp-block-list\">\n<li><code>id<\/code> (Primary Key)<\/li>\n\n\n\n<li><code>user_id<\/code> (Foreign Key to <code>Users<\/code>)<\/li>\n\n\n\n<li><code>vehicle_name<\/code><\/li>\n\n\n\n<li><code>brand<\/code>, <code>model<\/code>, <code>location<\/code>, etc.<\/li>\n\n\n\n<li><code>is_available<\/code> (Boolean)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Bookings Table<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Tracks vehicle bookings by Renters.<\/li>\n\n\n\n<li>Fields:\n<ul class=\"wp-block-list\">\n<li><code>id<\/code> (Primary Key)<\/li>\n\n\n\n<li><code>vehicle_id<\/code> (Foreign Key to <code>Vehicles<\/code>)<\/li>\n\n\n\n<li><code>renter_id<\/code> (Foreign Key to <code>Users<\/code>)<\/li>\n\n\n\n<li><code>partner_id<\/code> (Foreign Key to <code>Users<\/code>)<\/li>\n\n\n\n<li><code>start_date<\/code>, <code>end_date<\/code><\/li>\n\n\n\n<li><code>status<\/code> (e.g., Pending, Confirmed, Cancelled)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Business Logic Integration<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Ensure Partners Can&#8217;t Book Their Own Vehicles<\/strong>:\n<ul class=\"wp-block-list\">\n<li>In the <code>Bookings<\/code> table, validate that the <code>renter_id<\/code> and <code>partner_id<\/code> are not the same during the booking process.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Role-Based Dashboards<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Dynamically show role-specific data:\n<ul class=\"wp-block-list\">\n<li><strong>Renter Dashboard<\/strong>: Booked vehicles, payment history, etc.<\/li>\n\n\n\n<li><strong>Partner Dashboard<\/strong>: Listed vehicles, earnings, etc.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>SQL Table Definitions<\/strong><\/h3>\n\n\n\n<p>Here\u2019s an SQL implementation for the recommended schema:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Users Table\nCREATE TABLE Users (\n    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(255) NOT NULL,\n    email VARCHAR(255) UNIQUE NOT NULL,\n    mobile_number VARCHAR(20) UNIQUE NOT NULL,\n    password VARCHAR(255) NOT NULL,\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n);\n\n-- Roles Table\nCREATE TABLE Roles (\n    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(50) NOT NULL\n);\n\n-- UserRoles Table\nCREATE TABLE UserRoles (\n    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    user_id BIGINT UNSIGNED NOT NULL,\n    role_id BIGINT UNSIGNED NOT NULL,\n    status ENUM('Active', 'Inactive') DEFAULT 'Active',\n    FOREIGN KEY (user_id) REFERENCES Users(id),\n    FOREIGN KEY (role_id) REFERENCES Roles(id)\n);\n\n-- Vehicles Table\nCREATE TABLE Vehicles (\n    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    user_id BIGINT UNSIGNED NOT NULL,\n    vehicle_name VARCHAR(255) NOT NULL,\n    brand VARCHAR(255),\n    model VARCHAR(255),\n    location VARCHAR(255),\n    is_available BOOLEAN DEFAULT TRUE,\n    FOREIGN KEY (user_id) REFERENCES Users(id)\n);\n\n-- Bookings Table\nCREATE TABLE Bookings (\n    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    vehicle_id BIGINT UNSIGNED NOT NULL,\n    renter_id BIGINT UNSIGNED NOT NULL,\n    partner_id BIGINT UNSIGNED NOT NULL,\n    start_date DATE NOT NULL,\n    end_date DATE NOT NULL,\n    status ENUM('Pending', 'Confirmed', 'Cancelled') DEFAULT 'Pending',\n    FOREIGN KEY (vehicle_id) REFERENCES Vehicles(id),\n    FOREIGN KEY (renter_id) REFERENCES Users(id),\n    FOREIGN KEY (partner_id) REFERENCES Users(id),\n    CHECK (renter_id != partner_id)\n);\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Advantages of the Recommended Design<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Scalability<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Supports future roles by adding entries in the <code>Roles<\/code> table without significant redesign.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Clean Separation<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Data for roles is logically separated using <code>UserRoles<\/code>, while maintaining a unified user base.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Flexibility<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Role switching is seamless via the <code>UserRoles<\/code> table.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Integrity<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Business rules (e.g., Partners cannot book their own vehicles) are enforced directly in the schema.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Would you like help in migrating data from the existing schema to the new design or implementing this structure in your application? Let me know!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Based on the partial schema loaded from the provided SQL file, we can analyze and enhance the database design for<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1490","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/1490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=1490"}],"version-history":[{"count":1,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/1490\/revisions"}],"predecessor-version":[{"id":1491,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/1490\/revisions\/1491"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=1490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=1490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=1490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}