Skip to content

Database Schema

Complete documentation of the MyWarranties database entities and relationships.

Entity Relationship Diagram

┌─────────────┐       ┌─────────────────┐       ┌──────────────┐
│    User     │──────<│     Product     │──────<│   Receipt    │
└─────────────┘       └─────────────────┘       └──────────────┘
      │                       │
      │                       │
      ▼                       ▼
┌─────────────┐       ┌─────────────────┐
│ DeviceToken │       │ WarrantyClaim   │──────<┌──────────────┐
└─────────────┘       └─────────────────┘       │ ClaimMessage │
                              │                 └──────────────┘


                      ┌─────────────────────────┐
                      │ WarrantyNotificationLog │
                      └─────────────────────────┘

Entities

User

Stores user accounts including customers, suppliers, and administrators.

Table: users

ColumnTypeNullableDescription
idINTNoPrimary key (auto-increment)
emailVARCHAR(180)NoEmail address (unique, lowercase)
rolesJSONNoArray of user roles
passwordVARCHAR(255)YesHashed password
nameVARCHAR(255)YesFull name
streetVARCHAR(255)YesStreet address
postal_codeVARCHAR(20)YesPostal code
cityVARCHAR(100)YesCity
countryVARCHAR(100)YesCountry
notifications_enabledBOOLEANNoPush notifications (default: true)
email_notifications_enabledBOOLEANNoEmail notifications (default: true)
profile_pictureVARCHAR(255)YesProfile picture filename
created_atDATETIMENoCreation timestamp

Indexes:

  • UNIQUE on email

Available Roles:

  • ROLE_USER - Default role for all users
  • ROLE_SUPPLIER - Can manage warranty claims
  • ROLE_ADMIN - Full system access

Product

Stores product information with warranty details.

Table: products

ColumnTypeNullableDescription
idINTNoPrimary key
user_idINTNoOwner user (FK)
nameVARCHAR(255)NoProduct name
brandVARCHAR(255)NoBrand name
categoryVARCHAR(100)NoProduct category
purchase_dateDATENoPurchase date
storeVARCHAR(255)NoStore name
warranty_period_monthsINTNoWarranty duration
warranty_end_dateDATEYesCalculated end date
serial_numberVARCHAR(255)YesSerial number
serial_number_photoTEXTYesBase64 encoded photo
notesTEXTYesAdditional notes
supplier_emailVARCHAR(255)YesSupplier contact
created_atDATETIMENoCreation timestamp
updated_atDATETIMENoLast update

Relationships:

  • Many-to-One → User (owner)
  • One-to-Many → Receipt
  • One-to-Many → WarrantyClaim
  • One-to-One → ProductImage

Warranty Status Calculation:

php
// Returns: 'expired', 'expiring-soon', or 'active'
$status = $product->getWarrantyStatus();

WarrantyClaim

Stores warranty claims with status tracking.

Table: warranty_claims

ColumnTypeNullableDescription
idINTNoPrimary key
product_idINTNoRelated product (FK)
customer_idINTYesCustomer user (FK)
supplier_idINTYesAssigned supplier (FK)
statusVARCHAR(50)NoClaim status
descriptionTEXTYesIssue description
created_atDATETIMENoCreation timestamp
updated_atDATETIMENoLast update

Status Values:

StatusDescription
openNew claim, awaiting supplier
in_progressSupplier is handling
resolvedIssue resolved
closedClaim closed (final)

Relationships:

  • Many-to-One → Product
  • Many-to-One → User (customer)
  • Many-to-One → User (supplier)
  • One-to-Many → ClaimMessage

ClaimMessage

Stores messages in claim conversations.

Table: claim_messages

ColumnTypeNullableDescription
idINTNoPrimary key
claim_idINTNoParent claim (FK)
sender_idINTYesSender user (FK)
messageTEXTYesMessage content
attachment_filenameVARCHAR(255)YesAttachment filename
attachment_mime_typeVARCHAR(100)YesMIME type
attachment_sizeINTYesFile size (bytes)
is_readBOOLEANNoRead status
read_atDATETIMEYesRead timestamp
created_atDATETIMENoCreation timestamp

Cascade: Messages are deleted when claim is deleted.


Receipt

Stores purchase receipts for products.

Table: receipts

ColumnTypeNullableDescription
idINTNoPrimary key
product_idINTNoRelated product (FK)
file_nameVARCHAR(255)YesOriginal filename
file_typeVARCHAR(20)YesFile extension
data_urlTEXTYesBase64 encoded data
uploaded_atDATETIMENoUpload timestamp

DeviceToken

Stores push notification device tokens.

Table: device_tokens

ColumnTypeNullableDescription
idINTNoPrimary key
user_idINTNoOwner user (FK)
tokenVARCHAR(500)NoDevice token
platformVARCHAR(20)No'ios' or 'android'
created_atDATETIMENoCreation timestamp
updated_atDATETIMENoLast update

Cascade: Tokens are deleted when user is deleted.


VerificationCode

Stores email verification codes for passwordless login.

Table: verification_codes

ColumnTypeNullableDescription
idINTNoPrimary key
emailVARCHAR(180)YesEmail (lowercase)
codeVARCHAR(8)YesVerification code
expires_atDATETIMEYesExpiration time
created_atDATETIMENoCreation timestamp
usedBOOLEANNoWhether used

Validation Methods:

php
$code->isExpired(); // Check if expired
$code->isValid();   // Check if valid (!used && !expired)

WarrantyNotificationLog

Tracks warranty expiration notifications to prevent duplicates.

Table: warranty_notification_logs

ColumnTypeNullableDescription
idINTNoPrimary key
product_idINTNoRelated product (FK)
days_thresholdINTNoDays before expiration
sent_atDATETIMEYesSend timestamp

Unique Constraint: product_id + days_threshold

This prevents sending duplicate notifications for the same threshold (e.g., 30 days, 7 days, 1 day).


ProductImage

Stores product images.

Table: product_images

ColumnTypeNullableDescription
idINTNoPrimary key
product_idINTYesRelated product (FK)
filenameVARCHAR(255)YesFilename
filepathVARCHAR(500)YesStorage path
mime_typeVARCHAR(100)YesMIME type
file_sizeINTYesSize in bytes
uploaded_atDATETIMENoUpload timestamp

Migrations

Run migrations to set up the database:

bash
# Create database
php bin/console doctrine:database:create

# Run all migrations
php bin/console doctrine:migrations:migrate

# Check migration status
php bin/console doctrine:migrations:status

Indexes & Performance

Key indexes for query optimization:

  • users.email - Unique index for login lookups
  • products.user_id - Foreign key index
  • products.warranty_end_date - For expiring warranty queries
  • warranty_claims.product_id - Foreign key index
  • warranty_claims.status - For status filtering
  • claim_messages.claim_id - Foreign key index
  • device_tokens.user_id - Foreign key index

MyWarranties - Warranty Management System