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-03


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"
    orderItems ||--o{ order : "order_id"
    orderItems ||--o{ product : "product_id"
    orders ||--o{ user : "user_id"
    payments ||--o{ order : "order_id"
    products ||--o{ brand : "brand_id"
    products ||--o{ category : "category_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
        text slug
    }
    dealerTiers {
        uuid id PK
        timestamptz created_at
        timestamptz updated_at
        text name
        numeric discount_percentage
    }
    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
    }
    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
    }
    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
        timestamptz deleted_at
        text receiver_name
    }
    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
        text street_address
    }

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--
descriptiontextYES--
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_iduuidYES--

Foreign Keys

  • user_iduser.id (ON DELETE cascade)

categories

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
nametextNO--
slugtextNO--
parent_iduuidYES--
descriptiontextYES--
imagetextYES--
is_activeboolNOtrue-

Foreign Keys

  • parent_idcategory.id (ON DELETE set null)

dealerTiers

Columns

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

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)

orders

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
user_iduuidNO--
statusenumNOpending-
shipping_feenumericNO--
shipping_addresstextNO--
total_amountnumericNO--

Foreign Keys

  • user_iduser.id (ON DELETE restrict)

outboxEvents

Columns

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

payments

Columns

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

Foreign Keys

  • order_idorder.id (ON DELETE restrict)

products

Columns

ColumnTypeNullableDefaultPrimary
iduuidNODynamic FnYES
created_attimestamptzNOSQL: now()-
updated_attimestamptzNOAuto-update-
deleted_attimestamptzYES--
nametextNO--
slugtextNO--
pricenumericNO--
descriptiontextYES--
short_descriptiontextYES--
imagestextNOComplex Object-
brand_iduuidYES--
category_iduuidYES--
specsjsonbYESComplex Object-
total_stock_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)
  • product_brand_idx: (brand_id)
  • product_category_idx: (category_id)

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-
deleted_attimestamptzYES--
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--

Foreign Keys

  • dealer_tier_iddealer_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
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)

warehouses

Columns

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

Indexes

  • warehouse_name_idx: (name)

On this page