Hyundai Ecommerce

Database Schema

Complete database schema with ERD for Hyundai E-commerce project (auto-generated from Drizzle)

Database Schema

Generated automatically from Drizzle schema on 2026-05-01


Entity Relationship Diagram (ERD)

erDiagram
    accounts ||--o{ user : "user_id"
    cartItems ||--o{ cart : "cartId"
    cartItems ||--o{ product : "productId"
    carts ||--o{ user : "userId"
    categories ||--o{ category : "parentId"
    orderItems ||--o{ order : "orderId"
    orderItems ||--o{ product : "productId"
    orders ||--o{ user : "userId"
    payments ||--o{ order : "orderId"
    products ||--o{ brand : "brandId"
    products ||--o{ category : "categoryId"
    sessions ||--o{ user : "user_id"
    shippingBids ||--o{ order : "orderId"
    userAddresses ||--o{ user : "userId"
    users ||--o{ dealer_tier : "dealerTierId"
    warehouseStocks ||--o{ warehouse : "warehouseId"
    warehouseStocks ||--o{ product : "productId"

    accounts {
        text id PK
        uuid user_id FK
        text account_id
        text provider_id
        text access_token
        text refresh_token
    }
    brands {
        uuid id PK
        timestamptz createdAt
        timestamptz updatedAt
        text name
        text slug
    }
    cartItems {
        uuid id PK
        uuid cartId FK
        uuid productId FK
        timestamptz createdAt
        timestamptz updatedAt
        int quantity
    }
    carts {
        uuid id PK
        uuid userId FK
        timestamptz createdAt
        timestamptz updatedAt
    }
    categories {
        uuid id PK
        uuid parentId FK
        timestamptz createdAt
        timestamptz updatedAt
        text name
        text slug
    }
    dealerTiers {
        uuid id PK
        timestamptz createdAt
        timestamptz updatedAt
        text name
        numeric discountPercentage
    }
    orderItems {
        uuid id PK
        uuid orderId FK
        uuid productId FK
        timestamptz createdAt
        timestamptz updatedAt
        text productName
        text productSku
    }
    orders {
        uuid id PK
        uuid userId FK
        timestamptz createdAt
        timestamptz updatedAt
        enum status
        numeric shippingFee
    }
    outboxEvents {
        uuid id PK
        timestamptz createdAt
        timestamptz updatedAt
        enum eventType
        jsonb payload
    }
    payments {
        uuid id PK
        uuid orderId FK
        timestamptz createdAt
        timestamptz updatedAt
        timestamptz deletedAt
        numeric amount
    }
    products {
        uuid id PK
        uuid brandId FK
        uuid categoryId FK
        timestamptz createdAt
        timestamptz updatedAt
        timestamptz deletedAt
        text name
    }
    sessions {
        text id PK
        uuid user_id FK
        timestamptz expires_at
        text token
        timestamptz created_at
        timestamptz updated_at
    }
    shippingBids {
        uuid id PK
        uuid orderId FK
        timestamptz createdAt
        timestamptz updatedAt
        text vendorName
        numeric quotedPrice
    }
    userAddresses {
        uuid id PK
        uuid userId FK
        timestamptz createdAt
        timestamptz updatedAt
        timestamptz deletedAt
        text receiverName
    }
    users {
        uuid id PK
        uuid dealerTierId FK
        timestamptz createdAt
        timestamptz updatedAt
        timestamptz deletedAt
        text name
    }
    verifications {
        text id PK
        text identifier
        text value
        timestamptz expires_at
        timestamptz created_at
    }
    warehouseStocks {
        uuid warehouseId FK
        uuid productId FK
        int stock
        int minStockWarning
        timestamptz createdAt
        timestamptz updatedAt
    }
    warehouses {
        uuid id PK
        timestamptz createdAt
        timestamptz updatedAt
        text name
        text streetAddress
    }

Tables Overview


accounts

Columns

ColumnTypeNullableDefaultPrimary
idtextNO-YES
account_idtextNO--
provider_idtextNO--
user_iduuidNO--
access_tokentextYES--
refresh_tokentextYES--
id_tokentextYES--
access_token_expires_attimestamptzYES--
refresh_token_expires_attimestamptzYES--
scopetextYES--
passwordtextYES--
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-

Foreign Keys

  • user_iduser.id (ON DELETE cascade)

Indexes

  • account_user_id_idx: (user_id)

brands

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
nametextNO--
slugtextNO--
logotextYES--
descriptiontextYES--
isActiveboolNOtrue-

cartItems

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
cartIduuidNO--
productIduuidNO--
quantityintNO1-

Foreign Keys

  • cartIdcart.id (ON DELETE cascade)
  • productIdproduct.id (ON DELETE cascade)

Indexes

  • cart_product_unique_idx: (cartId, productId)

carts

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
userIduuidYES--

Foreign Keys

  • userIduser.id (ON DELETE cascade)

categories

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
nametextNO--
slugtextNO--
parentIduuidYES--
descriptiontextYES--
imagetextYES--
isActiveboolNOtrue-

Foreign Keys

  • parentIdcategory.id (ON DELETE set null)

dealerTiers

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
nametextNO--
discountPercentagenumericNO--
minimumSpendnumericNO0-

orderItems

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
orderIduuidNO--
productIduuidNO--
productNametextNO--
productSkutextNO--
quantityintNO0-
unitPricenumericNO--

Foreign Keys

  • orderIdorder.id (ON DELETE cascade)
  • productIdproduct.id (ON DELETE restrict)

orders

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
userIduuidNO--
statusenumNOpending-
shippingFeenumericNO--
shippingAddresstextNO--
totalAmountnumericNO--

Foreign Keys

  • userIduser.id (ON DELETE restrict)

outboxEvents

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
eventTypeenumNO--
payloadjsonbNO--
statusenumNOPENDING-
retryCountintNO0-
lastErrortextYES--
processedAttimestamptzYES--

payments

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
deletedAttimestamptzYES--
orderIduuidNO--
amountnumericNO--
methodenumNO--
statusenumNOPENDING-
transactionIdtextYES--
rawPayloadtextYES--

Foreign Keys

  • orderIdorder.id (ON DELETE restrict)

products

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
deletedAttimestamptzYES--
nametextNO--
slugtextNO--
pricenumericNO--
descriptiontextYES--
shortDescriptiontextYES--
imagestextNOComplex Object-
brandIduuidYES--
categoryIduuidYES--
specsjsonbYESComplex Object-
totalStockCacheintNO0-
isQuoteOnlyboolNOfalse-

Foreign Keys

  • brandIdbrand.id (ON DELETE set null)
  • categoryIdcategory.id (ON DELETE set null)

Indexes

  • product_slug_active_idx: (slug)
  • product_name_active_idx: (name)
  • product_brand_idx: (brandId)
  • product_category_idx: (categoryId)

sessions

Columns

ColumnTypeNullableDefaultPrimary
idtextNO-YES
expires_attimestamptzNO--
tokentextNO--
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
ip_addresstextYES--
user_agenttextYES--
user_iduuidNO--

Foreign Keys

  • user_iduser.id (ON DELETE cascade)

Indexes

  • session_user_id_idx: (user_id)

shippingBids

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
orderIduuidNO--
vendorNametextNO--
quotedPricenumericNO--
internalNotetextYES--
isSelectedboolYESfalse-

Foreign Keys

  • orderIdorder.id (ON DELETE cascade)

Indexes

  • one_selected_bid_order_idx: (orderId)

userAddresses

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
deletedAttimestamptzYES--
userIduuidNO--
receiverNametextNO--
phoneNumbertextNO--
streetAddresstextNO--
districttextNO--
citytextNO--
isDefaultboolNOfalse-

Foreign Keys

  • userIduser.id (ON DELETE cascade)

users

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
deletedAttimestamptzYES--
nametextNO--
emailtextNO--
emailVerifiedboolNOfalse-
imagetextYES--
roleenumNOcustomer-
dealerTierIduuidYES--

Foreign Keys

  • dealerTierIddealer_tier.id (ON DELETE set null)

verifications

Columns

ColumnTypeNullableDefaultPrimary
idtextNO-YES
identifiertextNO--
valuetextNO--
expires_attimestamptzNO--
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-

Indexes

  • verification_identifier_idx: (identifier)

warehouseStocks

Columns

ColumnTypeNullableDefaultPrimary
warehouseIduuidNO--
productIduuidNO--
stockintNO0-
minStockWarningintNO2-
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-

Foreign Keys

  • warehouseIdwarehouse.id (ON DELETE cascade)
  • productIdproduct.id (ON DELETE cascade)

warehouses

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
createdAttimestamptzNOSQL: now()-
updatedAttimestamptzNOAuto-update-
nametextNO--
streetAddresstextNO--
districttextNO--
citytextNO--
isActiveboolNOtrue-

Indexes

  • warehouse_name_idx: (name)

On this page