VOOZH about

URL: https://deepwiki.com/gp247net/shop/1.3-database-schema

⇱ Database Schema | gp247net/shop | DeepWiki


Loading...
Menu

Database Schema

Purpose and Scope

This document provides a comprehensive reference for the database schema of the GP247/Shop e-commerce package. It documents the structure of all tables created by the migration file, including column definitions, data types, indexes, foreign key relationships, and multi-store isolation mechanisms. This schema supports complex e-commerce operations including product variants, order management, customer accounts, and multi-tenant store architecture.

For information about how configuration data is stored and managed, see Configuration-Driven System Behavior. For details on multi-store query filtering logic, see Multi-Store and Multi-Vendor Architecture.

Schema Overview

The database schema consists of 30+ tables organized into five logical domains. Tables use UUID primary keys for most entities (except reference data which uses auto-increment integers). The schema supports internationalization through separate description tables that use composite keys of entity_id and lang.

Domain Organization


Sources: src/DB/migrations/00_00_00_create_tables_shop.php1-506

Catalog Domain Tables

shop_product

The core product entity table supporting three product types via the kind column: single products (0), bundle products (1), and group products (2).

ColumnTypeDefaultDescription
idUUID-Primary key
skuVARCHAR(50)-Stock keeping unit (indexed)
upc, ean, jan, isbn, mpnVARCHARNULLProduct identification codes
imageVARCHAR(255)NULLPrimary product image path
brand_idUUID0Foreign key to shop_brand (indexed)
supplier_idUUID0Foreign key to shop_supplier (indexed)
priceDECIMAL(15,2)0Base selling price
costDECIMAL(15,2)0Cost of goods sold
stockINTEGER0Available inventory quantity
soldINTEGER0Total units sold
minimumINTEGER0Minimum order quantity
weight_class, weightVARCHAR/DECIMALNULL/0Weight for shipping
length_class, length, width, heightVARCHAR/DECIMALNULL/0Dimensions for shipping
kindTINYINT0Product type: 0=single, 1=bundle, 2=group (indexed)
tagVARCHAR(50)'physical'Product tag classification (indexed)
tax_idVARCHAR(50)0Tax rule: 0=no tax, 'auto'=default tax (indexed)
statusTINYINT0Visibility status (indexed)
approveTINYINT1Approval status for vendors (indexed)
sortINTEGER0Display sort order
viewINTEGER0View counter
aliasVARCHAR(120)-URL-friendly slug (indexed)
date_lastviewTIMESTAMPNULLLast viewed timestamp
date_availableDATENULLProduct availability date
created_at, updated_atTIMESTAMP-Laravel timestamps

Note: Products do not have a direct store_id column. Multi-store associations use the junction table shop_product_store.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php186-221

shop_product_description

Internationalized product content using composite primary key of product_id and lang.

ColumnTypeDescription
product_idUUIDForeign key to shop_product
langVARCHAR(10)Language code (indexed)
nameVARCHAR(255)Localized product name
keywordVARCHAR(200)SEO keywords
descriptionVARCHAR(500)Short description
contentMEDIUMTEXTFull product description HTML

Unique constraint: (product_id, lang)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php223-234

shop_product_image

Product image gallery supporting multiple images per product.

ColumnTypeDescription
idUUIDPrimary key
imageVARCHAR(255)Image file path
product_idUUIDForeign key to shop_product (indexed)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php236-243

shop_product_build

Bundle product composition table. When a product has kind=1 (bundle), this table defines which component products are included and their quantities.

ColumnTypeDescription
build_idUUIDForeign key to parent bundle product
product_idUUIDForeign key to component product
quantityINTEGERQuantity of component in bundle

Composite primary key: (build_id, product_id)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php245-253

shop_product_group

Product variant grouping table. When a product has kind=2 (group), this table links related product variants (e.g., different sizes/colors of same item).

ColumnTypeDescription
group_idUUIDGroup identifier
product_idUUIDForeign key to variant product

Composite primary key: (group_id, product_id)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php255-262

shop_product_attribute

Configurable product options (e.g., size, color) that can add to the base price. Each attribute belongs to an attribute group which defines the input type (radio, select, checkbox).

ColumnTypeDefaultDescription
idBIGINT-Auto-increment primary key
nameVARCHAR(255)-Attribute option name
attribute_group_idINTEGER-Foreign key to shop_attribute_group
product_idUUID-Foreign key to shop_product
add_priceDECIMAL(15,2)0Price adjustment for this option
sortINTEGER0Display order
statusTINYINT1Active status

Composite index: (product_id, attribute_group_id)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php285-297

shop_attribute_group

Defines types of product attributes and their input controls.

ColumnTypeDefaultDescription
idINTEGER-Auto-increment primary key
nameVARCHAR(255)-Group name (e.g., "Size", "Color")
statusTINYINT0Active status
sortINTEGER0Display order
typeVARCHAR(50)-Input type: radio, select, checkbox
created_at, updated_atTIMESTAMP-Laravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php273-283

shop_product_promotion

Time-limited price promotions for products.

ColumnTypeDefaultDescription
product_idUUID-Primary key, foreign key to shop_product
price_promotionDECIMAL(15,2)-Promotional price
date_startTIMESTAMPNULLPromotion start date
date_endTIMESTAMPNULLPromotion end date
status_promotionINTEGER1Active status
created_at, updated_atTIMESTAMP-Laravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php397-407

shop_product_download

Digital download files associated with products (for digital goods).

ColumnTypeDescription
idUUIDPrimary key
product_idUUIDForeign key to shop_product
pathVARCHAR(255)File path or URL

Sources: src/DB/migrations/00_00_00_create_tables_shop.php409-416

shop_category

Hierarchical category tree supporting unlimited nesting via self-referential parent column.

ColumnTypeDefaultDescription
idUUID-Primary key
imageVARCHAR(255)NULLCategory image
aliasVARCHAR(120)-URL-friendly slug (indexed)
parentUUIDNULLParent category ID (NULL for root)
topINTEGER0Display in top menu flag
statusTINYINT0Visibility status
sortINTEGER0Display order
created_at, updated_atTIMESTAMP-Laravel timestamps

Note: Categories do not have a direct store_id column. Multi-store associations use the junction table shop_category_store.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php34-46

shop_category_description

Internationalized category content.

ColumnTypeDescription
category_idUUIDForeign key to shop_category
langVARCHAR(10)Language code (indexed)
titleVARCHAR(255)Localized category name
keywordVARCHAR(200)SEO keywords
descriptionVARCHAR(500)Category description

Unique constraint: (category_id, lang)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php48-58

shop_brand

Product manufacturer/brand information.

ColumnTypeDefaultDescription
idUUID-Primary key
nameVARCHAR(255)-Brand name
aliasVARCHAR(120)-URL-friendly slug (indexed)
imageVARCHAR(255)NULLBrand logo
urlVARCHAR(100)NULLBrand website
statusTINYINT0Active status
sortINTEGER0Display order
created_at, updated_atTIMESTAMP-Laravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php20-32

shop_supplier

Vendor/supplier information for multi-vendor marketplace functionality.

ColumnTypeDefaultDescription
idUUID-Primary key
nameVARCHAR(255)-Supplier name
aliasVARCHAR(120)-URL-friendly slug (indexed)
emailVARCHAR(150)NULLContact email
phoneVARCHAR(20)NULLContact phone
imageVARCHAR(255)NULLSupplier logo
addressVARCHAR(100)NULLPhysical address
urlVARCHAR(100)NULLSupplier website
statusTINYINT1Active status
store_idUUID1Store isolation (indexed)
sortINTEGER0Display order
created_at, updated_atTIMESTAMP-Laravel timestamps

Note: This table has direct store_id column for multi-store isolation.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php370-386

Transaction Domain Tables

shop_order

Main order record containing customer information, shipping address, and financial totals.


Key Financial Fields:

  • subtotal: Sum of line item prices before adjustments
  • discount: Total discount amount applied
  • shipping: Shipping cost
  • tax: Total tax amount
  • other_fee: Additional fees (e.g., payment processing)
  • total: Final order total (subtotal + shipping + tax + other_fee - discount)
  • received: Amount paid by customer
  • balance: Outstanding balance (total - received)

Multi-Currency Support:

  • currency: Three-letter currency code (e.g., "USD", "EUR")
  • exchange_rate: Exchange rate at time of order

Status Fields:

  • status: Overall order status (references shop_order_status)
  • payment_status: Payment state (references shop_payment_status)
  • shipping_status: Shipment state (references shop_shipping_status)

Device Tracking:

  • device_type: Device classification (indexed for analytics)
  • user_agent: Browser user agent string
  • ip: Customer IP address

Multi-Store Isolation:

  • store_id: Store identifier (indexed, default 1)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php77-118

shop_order_detail

Individual line items in an order. Each row represents one product purchased.

ColumnTypeDefaultDescription
idUUID-Primary key
order_idUUID-Foreign key to shop_order
product_idUUID-Foreign key to shop_product
nameVARCHAR(255)-Product name snapshot
priceDECIMAL(15,2)0Unit price at time of order
qtyINTEGER0Quantity ordered
store_idUUID1Store identifier for multi-vendor
total_priceDECIMAL(15,2)0Line total (price × qty)
taxDECIMAL(15,2)0Tax amount for this line
skuVARCHAR(50)-SKU snapshot
currencyVARCHAR(10)-Currency code
exchange_rateFLOATNULLExchange rate snapshot
attributeVARCHAR(100)NULLSelected product attributes (JSON)
created_at, updated_atTIMESTAMP-Laravel timestamps

Note: Product name and SKU are denormalized to preserve historical data even if product is later modified or deleted.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php120-138

shop_order_history

Audit trail for order status changes and administrative notes.

ColumnTypeDefaultDescription
idUUID-Primary key
order_idUUID-Foreign key to shop_order
contentVARCHAR(300)-History entry description
admin_idUUID0Admin user who made the change
customer_idUUID0Customer who made the change
order_status_idINTEGER0Order status after change
add_dateTIMESTAMP-Timestamp of entry

Sources: src/DB/migrations/00_00_00_create_tables_shop.php140-151

shop_order_total

Financial breakdown of order total including subtotal, shipping, tax, discounts, and other fees. Each row represents one component of the order total.

ColumnTypeDefaultDescription
idUUID-Primary key
order_idUUID-Foreign key to shop_order (indexed)
titleVARCHAR(255)-Line item description
codeVARCHAR(100)-Component code (e.g., "subtotal", "shipping")
valueDECIMAL(15,2)0Amount
textVARCHAR(200)NULLFormatted display text
sortINTEGER1Display order
created_at, updated_atTIMESTAMP-Laravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php162-174

shop_shoppingcart

Persistent shopping cart storage. Supports multiple cart instances (default cart, wishlist, compare).

ColumnTypeDefaultDescription
identifierVARCHAR(100)-Session ID or customer ID
instanceVARCHAR(100)-Cart type (default, wishlist, compare)
contentTEXT-Serialized cart data
store_idUUID1Store identifier (indexed)
created_at, updated_atTIMESTAMP-Laravel timestamps

Composite index: (identifier, instance)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php308-318

Customer Domain Tables

shop_customer

Customer account information. Supports optional fields based on configuration settings (see Configuration-Driven System Behavior).

ColumnTypeDefaultDescription
idUUID-Primary key
first_nameVARCHAR(100)-Required first name
last_nameVARCHAR(100)NULLOptional last name
first_name_kanaVARCHAR(100)NULLJapanese phonetic first name
last_name_kanaVARCHAR(100)NULLJapanese phonetic last name
emailVARCHAR(150)NULLUnique email address
sexTINYINTNULLGender: 0=women, 1=men
birthdayDATENULLDate of birth
passwordVARCHAR(100)NULLHashed password
address_idUUID0Default address (indexed)
postcodeVARCHAR(10)NULLPostal code
address1VARCHAR(100)NULLAddress line 1
address2VARCHAR(100)NULLAddress line 2
address3VARCHAR(100)NULLAddress line 3
companyVARCHAR(100)NULLCompany name
countryVARCHAR(10)VNCountry code
phoneVARCHAR(20)NULLPhone number
store_idUUID1Store identifier (indexed)
remember_tokenVARCHAR(100)NULLLaravel remember token
statusTINYINT1Account status (active/inactive)
groupTINYINT1Customer group
email_verified_atTIMESTAMPNULLEmail verification timestamp
created_at, updated_atTIMESTAMP-Laravel timestamps

Unique constraint: email

Multi-Store Isolation: Direct store_id column isolates customers by store.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php320-348

shop_customer_address

Multiple shipping/billing addresses per customer. Customers can maintain an address book of saved addresses.

ColumnTypeDefaultDescription
idUUID-Primary key
customer_idUUID-Foreign key to shop_customer (indexed)
first_nameVARCHAR(100)-Recipient first name
last_nameVARCHAR(100)NULLRecipient last name
first_name_kanaVARCHAR(100)NULLJapanese phonetic first name
last_name_kanaVARCHAR(100)NULLJapanese phonetic last name
postcodeVARCHAR(10)NULLPostal code
address1VARCHAR(100)NULLAddress line 1
address2VARCHAR(100)NULLAddress line 2
address3VARCHAR(100)NULLAddress line 3
countryVARCHAR(10)VNCountry code
phoneVARCHAR(20)NULLPhone number
created_at, updated_atTIMESTAMP-Laravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php350-367 src/Admin/Models/AdminCustomer.php82-95

Reference Domain Tables

Reference tables store lookup data and workflow states. These tables use auto-increment integer primary keys rather than UUIDs.

shop_currency

Multi-currency support with exchange rates and formatting options.

ColumnTypeDefaultDescription
idINTEGER-Auto-increment primary key
nameVARCHAR(255)-Currency name (e.g., "US Dollar")
codeVARCHAR(10)-ISO currency code (unique)
symbolVARCHAR(10)-Currency symbol (e.g., "$")
exchange_rateFLOAT-Exchange rate to base currency
precisionTINYINT2Decimal places for display
symbol_firstTINYINT0Symbol position: 0=after, 1=before
thousandsVARCHAR','Thousands separator
statusTINYINT0Active status
sortINTEGER0Display order
created_at, updated_atTIMESTAMP-Laravel timestamps

Unique constraint: code

Sources: src/DB/migrations/00_00_00_create_tables_shop.php60-75

shop_order_status

Order workflow states (e.g., Pending, Processing, Completed, Cancelled).

ColumnTypeDescription
idINTEGERAuto-increment primary key
nameVARCHAR(255)Status name
created_at, updated_atTIMESTAMPLaravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php153-160

shop_payment_status

Payment states (e.g., Unpaid, Partial, Paid, Refunded).

ColumnTypeDescription
idINTEGERAuto-increment primary key
nameVARCHAR(255)Status name
created_at, updated_atTIMESTAMPLaravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php176-183

shop_shipping_status

Shipping states (e.g., Pending, Shipped, Delivered).

ColumnTypeDescription
idINTEGERAuto-increment primary key
nameVARCHAR(255)Status name
created_at, updated_atTIMESTAMPLaravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php299-306

shop_tax

Tax rule definitions with percentage values.

ColumnTypeDefaultDescription
idINTEGER-Auto-increment primary key
nameVARCHAR(255)-Tax rule name (e.g., "VAT 20%")
valueINTEGER0Tax percentage (stored as integer, e.g., 20 for 20%)
created_at, updated_atTIMESTAMP-Laravel timestamps

Sources: src/DB/migrations/00_00_00_create_tables_shop.php388-396

Multi-Store Junction Tables

Junction tables enable many-to-many relationships and multi-store catalog sharing. These tables use composite primary keys.

shop_product_category

Many-to-many relationship between products and categories. A product can belong to multiple categories.

ColumnTypeDescription
product_idUUIDForeign key to shop_product
category_idUUIDForeign key to shop_category

Composite primary key: (product_id, category_id)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php264-271

shop_product_store

Multi-store catalog sharing. Links products to specific stores, allowing catalog visibility control per store.

ColumnTypeDescription
product_idUUIDForeign key to shop_product
store_idUUIDStore identifier

Composite primary key: (product_id, store_id)

Note: Query builders automatically join this table when multi-store mode is enabled.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php418-425

shop_category_store

Multi-store catalog sharing for categories.

ColumnTypeDescription
category_idUUIDForeign key to shop_category
store_idUUIDStore identifier

Composite primary key: (category_id, store_id)

Sources: src/DB/migrations/00_00_00_create_tables_shop.php427-434

Support Tables

shop_sessions

Custom session storage table for shop-specific sessions.

ColumnTypeDescription
idVARCHAR(100)Session ID (unique)
customer_idUUIDLogged-in customer ID (nullable)
ip_addressVARCHAR(45)Client IP address
user_agentTEXTBrowser user agent
payloadTEXTSerialized session data
last_activityINTEGERUnix timestamp of last activity
created_at, updated_atTIMESTAMPLaravel timestamps

Unique constraint: id

Sources: src/DB/migrations/00_00_00_create_tables_shop.php437-448

shop_password_resets

Temporary token storage for password reset requests.

ColumnTypeDescription
emailVARCHAR(150)Customer email (indexed)
tokenVARCHAR(255)Reset token hash
created_atTIMESTAMPToken creation time

Index: email

Sources: src/DB/migrations/00_00_00_create_tables_shop.php450-458

Entity Relationships

The following diagram illustrates the primary foreign key relationships between entities:


Sources: src/DB/migrations/00_00_00_create_tables_shop.php1-506

Indexing Strategy

The schema implements a comprehensive indexing strategy to optimize query performance:

Primary Indexes

  • UUID Primary Keys: All major entities use UUID primary keys for global uniqueness and distributed system compatibility
  • Integer Primary Keys: Reference tables use auto-increment integers for efficiency
  • Composite Primary Keys: Junction tables use composite keys on both foreign key columns

Secondary Indexes


Performance Optimization:

  • alias indexes on products and categories support SEO-friendly URL lookups
  • store_id indexes on orders, customers, suppliers, and carts enable efficient multi-store filtering
  • kind, tag, status, approve indexes on products support catalog filtering
  • Composite index (identifier, instance) on shopping cart supports session-based cart retrieval
  • lang indexes on description tables optimize localization queries

Sources: src/DB/migrations/00_00_00_create_tables_shop.php1-506

Multi-Store Column Patterns

The schema implements a hybrid multi-tenant architecture with two distinct patterns:

Direct Store ID Columns

Tables with direct store_id columns for hard data isolation:

TableColumnDefaultIsolation Type
shop_orderstore_id1Hard isolation (indexed)
shop_order_detailstore_id1Vendor tracking
shop_customerstore_id1Hard isolation (indexed)
shop_supplierstore_id1Hard isolation (indexed)
shop_shoppingcartstore_id1Session isolation (indexed)

Query Pattern: Models use where('store_id', session('adminStoreId')) to filter results.

Example from AdminCustomer:


Junction Table Store Associations

Catalog entities use junction tables for flexible multi-store visibility:

TableJunction TablePurpose
shop_productshop_product_storeProduct visibility per store
shop_categoryshop_category_storeCategory visibility per store

Query Pattern: Models join junction tables and filter by store_id when multi-store mode is enabled.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php77-506 src/Admin/Models/AdminCustomer.php20-26

Internationalization Schema Pattern

The system uses separate description tables for internationalized content, following this pattern:

  1. Base Entity Table: Contains language-independent data (IDs, numbers, dates, flags)
  2. Description Table: Contains translatable text with composite key (entity_id, lang)

Example: Product Internationalization


Tables Using This Pattern:

  • shop_product + shop_product_description
  • shop_category + shop_category_description

Query Pattern: Models join description tables filtered by lang parameter to retrieve localized content. See Frontend Request Flow for implementation details.

Sources: src/DB/migrations/00_00_00_create_tables_shop.php223-234 src/DB/migrations/00_00_00_create_tables_shop.php48-58

Migration Execution

The migration file is located at src/DB/migrations/00_00_00_create_tables_shop.php and follows Laravel migration conventions:

Connection Configuration:

  • Uses dynamic connection: Schema::connection(GP247_DB_CONNECTION)
  • Uses table prefix: GP247_DB_PREFIX prepended to all table names

Execution Order:

  • File naming convention 00_00_00_ ensures this migration runs before other shop migrations
  • The up() method creates all tables
  • The down() method drops all tables in safe order

Idempotency:

  • Migration calls $this->down() before creating tables to ensure clean state
  • Safe to re-run during development

Sources: src/DB/migrations/00_00_00_create_tables_shop.php14-19 src/DB/migrations/00_00_00_create_tables_shop.php468-505

Refresh this wiki

On this page