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-06-18


Entity Relationship Diagram (ERD)

erDiagram
    accounts ||--o{ user : "user_id"
    cartItems ||--o{ cart : "cart_id"
    cartItems ||--o{ product : "product_id"
    carts ||--o{ user : "user_id"
    categories ||--o{ category : "parent_id"
    creditLimitHistory ||--o{ user : "user_id"
    creditLimitHistory ||--o{ user : "changed_by"
    debtRepayments ||--o{ user : "user_id"
    debtRepayments ||--o{ user : "verified_by"
    orderItems ||--o{ order : "order_id"
    orderItems ||--o{ product : "product_id"
    orders ||--o{ user : "user_id"
    paymentTransactions ||--o{ order : "order_id"
    paymentTransactions ||--o{ user : "verified_by"
    payments ||--o{ order : "order_id"
    products ||--o{ brand : "brand_id"
    products ||--o{ category : "category_id"
    quoteItems ||--o{ quote : "quote_id"
    quoteItems ||--o{ product : "product_id"
    quoteMessages ||--o{ quote : "quote_id"
    quoteMessages ||--o{ user : "sender_id"
    quotes ||--o{ user : "user_id"
    quotes ||--o{ order : "order_id"
    sessions ||--o{ user : "user_id"
    shippingBids ||--o{ order : "order_id"
    userAddresses ||--o{ user : "user_id"
    users ||--o{ dealer_tier : "dealer_tier_id"
    warehouseStocks ||--o{ warehouse : "warehouse_id"
    warehouseStocks ||--o{ product : "product_id"

    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 created_at
        timestamptz updated_at
        text name
        text slug
    }
    cartItems {
        uuid id PK
        uuid cart_id FK
        uuid product_id FK
        timestamptz created_at
        timestamptz updated_at
        int quantity
    }
    carts {
        uuid id PK
        uuid user_id FK
        timestamptz created_at
        timestamptz updated_at
    }
    categories {
        uuid id PK
        uuid parent_id FK
        timestamptz created_at
        timestamptz updated_at
        text name_vi
        text name_en
    }
    creditLimitHistory {
        uuid id PK
        uuid user_id FK
        uuid changed_by FK
        timestamptz created_at
        timestamptz updated_at
        timestamptz deleted_at
        numeric old_limit
    }
    dealerTiers {
        uuid id PK
        timestamptz created_at
        timestamptz updated_at
        text name_vi
        text name_en
    }
    debtRepayments {
        uuid id PK
        uuid user_id FK
        uuid verified_by FK
        timestamptz created_at
        timestamptz updated_at
        timestamptz deleted_at
        numeric amount
    }
    orderItems {
        uuid id PK
        uuid order_id FK
        uuid product_id FK
        timestamptz created_at
        timestamptz updated_at
        text product_name
        text product_sku
    }
    orders {
        uuid id PK
        uuid user_id FK
        timestamptz created_at
        timestamptz updated_at
        enum status
        numeric shipping_fee
    }
    outboxEvents {
        uuid id PK
        timestamptz created_at
        timestamptz updated_at
        enum event_type
        jsonb payload
    }
    paymentTransactions {
        uuid id PK
        uuid order_id FK
        uuid verified_by FK
        timestamptz created_at
        timestamptz updated_at
        timestamptz deleted_at
        numeric amount
    }
    payments {
        uuid id PK
        uuid order_id FK
        timestamptz created_at
        timestamptz updated_at
        timestamptz deleted_at
        numeric amount
    }
    products {
        uuid id PK
        uuid brand_id FK
        uuid category_id FK
        timestamptz created_at
        timestamptz updated_at
        timestamptz deleted_at
        text name_vi
    }
    quoteItems {
        uuid id PK
        uuid quote_id FK
        uuid product_id FK
        timestamptz created_at
        timestamptz updated_at
        int quantity
        numeric requested_price
    }
    quoteMessages {
        uuid id PK
        uuid quote_id FK
        uuid sender_id FK
        timestamptz created_at
        timestamptz updated_at
        text message
    }
    quotes {
        uuid id PK
        uuid user_id FK
        uuid order_id FK
        timestamptz created_at
        timestamptz updated_at
        enum status
        numeric total_quoted_price
    }
    sessions {
        text id PK
        uuid user_id FK
        timestamptz expires_at
        text token
        timestamptz created_at
        timestamptz updated_at
    }
    shippingBids {
        uuid id PK
        uuid order_id FK
        timestamptz created_at
        timestamptz updated_at
        text vendor_name
        numeric quoted_price
    }
    userAddresses {
        uuid id PK
        uuid user_id FK
        timestamptz created_at
        timestamptz updated_at
        text receiver_name
        text phone_number
    }
    users {
        uuid id PK
        uuid dealer_tier_id FK
        timestamptz created_at
        timestamptz updated_at
        timestamptz deleted_at
        text name
    }
    verifications {
        text id PK
        text identifier
        text value
        timestamptz expires_at
        timestamptz created_at
    }
    warehouseStocks {
        uuid warehouse_id FK
        uuid product_id FK
        int stock
        int min_stock_warning
        timestamptz created_at
        timestamptz updated_at
    }
    warehouses {
        uuid id PK
        timestamptz created_at
        timestamptz updated_at
        text name_vi
        text name_en
    }

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
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
nametextNO--
slugtextNO--
logotextYES--
description_vitextYES--
description_entextYES--
is_activeboolNOtrue-

cartItems

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
cart_iduuidNO--
product_iduuidNO--
quantityintNO1-

Foreign Keys

  • cart_idcart.id (ON DELETE cascade)
  • product_idproduct.id (ON DELETE cascade)

Indexes

  • cart_product_unique_idx: (cart_id, product_id)

carts

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
user_iduuidNO--

Foreign Keys

  • user_iduser.id (ON DELETE cascade)

categories

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
name_vitextNO--
name_entextYES--
slugtextNO--
parent_iduuidYES--
description_vitextYES--
description_entextYES--
imagetextYES--
is_activeboolNOtrue-

Foreign Keys

  • parent_idcategory.id (ON DELETE set null)

creditLimitHistory

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
deleted_attimestamptzYES--
user_iduuidNO--
old_limitnumericNO--
new_limitnumericNO--
changed_byuuidNO--
reasontextYES--

Foreign Keys

  • user_iduser.id (ON DELETE cascade)
  • changed_byuser.id (ON DELETE restrict)

dealerTiers

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
name_vitextNO--
name_entextYES--
discount_percentagenumericNO--
minimum_spendnumericNO0-

debtRepayments

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
deleted_attimestamptzYES--
user_iduuidNO--
amountnumericNO--
payment_methodenumNO--
statusenumNOPENDING-
order_codebigint:numberYES--
reference_codetextYES--
verified_byuuidYES--

Foreign Keys

  • user_iduser.id (ON DELETE restrict)
  • verified_byuser.id (ON DELETE set null)

orderItems

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
order_iduuidNO--
product_iduuidNO--
product_nametextNO--
product_skutextNO--
quantityintNO0-
unit_pricenumericNO--

Foreign Keys

  • order_idorder.id (ON DELETE cascade)
  • product_idproduct.id (ON DELETE restrict)

Indexes

  • order_item_order_idx: (order_id)
  • order_item_product_idx: (product_id)

orders

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
user_iduuidNO--
statusenumNOPENDING-
shipping_feenumericNO--
shipping_addresstextNO--
total_amountnumericNO--
payment_methodenumNOPAYOS-
payment_statusenumNOUNPAID-
approval_statusenumNOAPPROVED-

Foreign Keys

  • user_iduser.id (ON DELETE restrict)

Indexes

  • order_user_status_created_idx: (user_id, status, created_at)
  • order_active_metrics_idx: (created_at)

outboxEvents

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
event_typeenumNO--
payloadjsonbNO--
statusenumNOPENDING-
retry_countintNO0-
last_errortextYES--
processed_attimestamptzYES--

paymentTransactions

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
deleted_attimestamptzYES--
order_iduuidNO--
amountnumericNO--
payment_methodenumNO--
transaction_typeenumNO--
statusenumNOPENDING-
order_codebigint:numberYES--
reference_codetextYES--
verified_byuuidYES--

Foreign Keys

  • order_idorder.id (ON DELETE cascade)
  • verified_byuser.id (ON DELETE set null)

payments

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
deleted_attimestamptzYES--
order_iduuidNO--
amountnumericNO--
methodenumNO--
statusenumNOPENDING-
raw_payloadtextYES--

Foreign Keys

  • order_idorder.id (ON DELETE restrict)

products

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
deleted_attimestamptzYES--
name_vitextNO--
name_entextYES--
slugtextNO--
pricenumericNO--
description_vijsonbYES--
description_enjsonbYES--
short_description_vitextYES--
short_description_entextYES--
imagestextNOComplex Object-
brand_iduuidYES--
category_iduuidYES--
specsjsonbYESComplex Object-
total_stock_cacheintNO0-
total_sales_cacheintNO0-
is_quote_onlyboolNOfalse-

Foreign Keys

  • brand_idbrand.id (ON DELETE set null)
  • category_idcategory.id (ON DELETE set null)

Indexes

  • product_slug_active_idx: (slug)
  • product_name_active_idx: (name_vi)
  • product_brand_idx: (brand_id)
  • product_category_idx: (category_id)
  • product_sales_cache_idx: (total_sales_cache)
  • product_created_at_idx: (created_at)
  • product_power_idx: (unknown)
  • product_voltage_idx: (unknown)

quoteItems

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
quote_iduuidNO--
product_iduuidNO--
quantityintNO1-
requested_pricenumericNO--
agreed_pricenumericYES--

Foreign Keys

  • quote_idquote.id (ON DELETE cascade)
  • product_idproduct.id (ON DELETE restrict)

Indexes

  • quote_item_quote_idx: (quote_id)
  • quote_item_product_idx: (product_id)

quoteMessages

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
quote_iduuidNO--
sender_iduuidNO--
messagetextNO--

Foreign Keys

  • quote_idquote.id (ON DELETE cascade)
  • sender_iduser.id (ON DELETE restrict)

Indexes

  • quote_message_quote_idx: (quote_id)
  • quote_message_sender_idx: (sender_id)

quotes

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
user_iduuidNO--
statusenumNOpending_review-
total_quoted_pricenumericYES--
expiration_datetimestamptzYES--
notetextYES--
order_iduuidYES--

Foreign Keys

  • user_iduser.id (ON DELETE restrict)
  • order_idorder.id (ON DELETE set null)

Indexes

  • quote_user_idx: (user_id)
  • quote_order_idx: (order_id)
  • quote_created_at_idx: (created_at)

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
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
order_iduuidNO--
vendor_nametextNO--
quoted_pricenumericNO--
internal_notetextYES--
is_selectedboolYESfalse-

Foreign Keys

  • order_idorder.id (ON DELETE cascade)

Indexes

  • one_selected_bid_order_idx: (order_id)

userAddresses

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
user_iduuidNO--
receiver_nametextNO--
phone_numbertextNO--
street_addresstextNO--
districttextNO--
citytextNO--
is_defaultboolNOfalse-

Foreign Keys

  • user_iduser.id (ON DELETE cascade)

users

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
deleted_attimestamptzYES--
nametextNO--
emailtextNO--
email_verifiedboolNOfalse-
imagetextYES--
roleenumNOCUSTOMER-
dealer_tier_iduuidYES--
phonetextNO--
company_nametextYES--
tax_idtextYES--
business_typeenumNOEND_USER-
provincetextYES--
credit_limitnumericNO0.00-
current_debtnumericNO0.00-

Foreign Keys

  • dealer_tier_iddealer_tier.id (ON DELETE set null)

Indexes

  • user_dealer_tier_idx: (dealer_tier_id)
  • user_created_at_idx: (created_at)

verifications

Columns

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

Indexes

  • verification_identifier_idx: (identifier)

warehouseStocks

Columns

ColumnTypeNullableDefaultPrimary
warehouse_iduuidNO--
product_iduuidNO--
stockintNO0-
min_stock_warningintNO2-
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-

Foreign Keys

  • warehouse_idwarehouse.id (ON DELETE cascade)
  • product_idproduct.id (ON DELETE cascade)

Indexes

  • warehouse_stock_product_idx: (product_id)

warehouses

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
name_vitextNO--
name_entextYES--
street_addresstextNO--
districttextNO--
citytextNO--
is_activeboolNOtrue-

Indexes

  • warehouse_name_idx: (name_vi)

On this page