API ReferenceDatabase Schema

Database Schema

Complete reference for all 14 Supabase tables.

profiles

Extends auth.users with app-specific data.

ColumnTypeConstraintsDescription
idUUIDPK, FK → auth.users(id) ON DELETE CASCADEUser ID
emailTEXTNOT NULLEmail address
full_nameTEXT—Display name
phoneTEXT—Phone number
avatar_urlTEXT—Profile image URL
birthdayTEXT—Birthday
roleTEXTDEFAULT 'customer', CHECK (customer|employee|admin)User role
created_atTIMESTAMPTZDEFAULT NOW()Created
updated_atTIMESTAMPTZDEFAULT NOW()Updated

locations

ColumnTypeConstraintsDescription
idUUIDPK, DEFAULT gen_random_uuid()Location ID
nameTEXTNOT NULLLocation name
addressTEXT—Street address
phoneTEXT—Phone number
emailTEXT—Contact email
is_activeBOOLEANDEFAULT trueActive flag
hoursJSONB—Operating hours
created_atTIMESTAMPTZDEFAULT NOW()Created
updated_atTIMESTAMPTZDEFAULT NOW()Updated

ColumnTypeConstraintsDescription
idUUIDPKCategory ID
nameTEXTNOT NULLDisplay name
slugTEXTNOT NULL, UNIQUEURL-friendly name
descriptionTEXT—Description
image_urlTEXT—Category image
sort_orderINTDEFAULT 0Display order
is_activeBOOLEANDEFAULT trueActive flag

ColumnTypeConstraintsDescription
idUUIDPKItem ID
category_idUUIDFK → menu_categories(id) CASCADECategory
nameTEXTNOT NULLItem name
descriptionTEXT—Description
base_priceINTNOT NULLPrice in cents
image_urlTEXT—Item image
stars_earnedINTDEFAULT 5Stars per purchase
is_featuredBOOLEANDEFAULT falseFeatured on home
is_availableBOOLEANDEFAULT trueIn stock
sort_orderINTDEFAULT 0Display order
nutrition_infoJSONB—Nutrition data

modifier_groups

ColumnTypeConstraintsDescription
idUUIDPKGroup ID
nameTEXTNOT NULLGroup name (e.g., “Milk”)
slugTEXTNOT NULL, UNIQUEURL-friendly name
descriptionTEXT—Description
is_requiredBOOLEANDEFAULT falseMust select
min_selectionsINTDEFAULT 0Minimum choices
max_selectionsINTDEFAULT 1Maximum choices
sort_orderINTDEFAULT 0Display order

modifiers

ColumnTypeConstraintsDescription
idUUIDPKModifier ID
group_idUUIDFK → modifier_groups(id) CASCADEParent group
nameTEXTNOT NULLModifier name
price_adjustmentINTDEFAULT 0Price change (cents)
is_defaultBOOLEANDEFAULT falsePre-selected
is_availableBOOLEANDEFAULT trueIn stock
sort_orderINTDEFAULT 0Display order

item_modifier_groups

Links menu items to their applicable modifier groups.

ColumnTypeConstraints
menu_item_idUUIDFK → menu_items(id) CASCADE
modifier_group_idUUIDFK → modifier_groups(id) CASCADE

PK: (menu_item_id, modifier_group_id)


orders

ColumnTypeConstraintsDescription
idUUIDPKOrder ID
location_idUUIDFK → locations(id)Location
user_idUUIDFK → auth.users(id)Customer
order_numberTEXTNOT NULLDisplay number
statusTEXTDEFAULT 'pending', CHECKOrder status
assigned_toUUIDFK → auth.users(id)Claimed by
claimed_atTIMESTAMPTZ—Claim time
subtotalINTNOT NULLCents
taxINTNOT NULLCents
discountINTDEFAULT 0Cents
tipINTDEFAULT 0Cents
totalINTNOT NULLCents
stars_earnedINTDEFAULT 0Stars awarded
reward_redemption_idUUID—Applied reward
payment_methodTEXT—Payment type
square_payment_idTEXT—Square ref
square_order_idTEXT—Square ref
notesTEXT—Order notes
pickup_timeTIMESTAMPTZ—Scheduled pickup
completed_atTIMESTAMPTZ—Completion time
versionINTDEFAULT 1Optimistic lock
idempotency_keyTEXTUNIQUEDuplicate prevention

order_items

ColumnTypeConstraints
idUUIDPK
order_idUUIDFK → orders(id) CASCADE
menu_item_idUUIDFK → menu_items(id)
nameTEXTNOT NULL
quantityINTNOT NULL
unit_priceINTNOT NULL (cents)
total_priceINTNOT NULL (cents)
notesTEXT—

order_item_modifiers

ColumnTypeConstraints
idUUIDPK
order_item_idUUIDFK → order_items(id) CASCADE
modifier_idUUIDFK → modifiers(id)
nameTEXTNOT NULL
price_adjustmentINTNOT NULL (cents)

loyalty_accounts

ColumnTypeConstraints
idUUIDPK
user_idUUIDUNIQUE, FK → auth.users(id) CASCADE
stars_balanceINTDEFAULT 0
lifetime_starsINTDEFAULT 0
tierTEXTDEFAULT 'green', CHECK (green|gold|platinum)
tier_expiryTIMESTAMPTZ—

star_transactions

ColumnTypeConstraints
idUUIDPK
loyalty_account_idUUIDFK → loyalty_accounts(id) CASCADE
order_idUUIDFK → orders(id)
amountINTNOT NULL (negative for redemptions)
typeTEXTNOT NULL, CHECK (earned|redeemed|expired|bonus|adjustment)
descriptionTEXT—

rewards

ColumnTypeConstraints
idUUIDPK
nameTEXTNOT NULL
descriptionTEXT—
stars_requiredINTNOT NULL
reward_typeTEXTNOT NULL, CHECK (free_drink|free_food|discount_percent|discount_amount)
reward_valueJSONB—
min_tierTEXTDEFAULT 'green', CHECK
is_activeBOOLEANDEFAULT true
sort_orderINTDEFAULT 0

reward_redemptions

ColumnTypeConstraints
idUUIDPK
reward_idUUIDFK → rewards(id)
user_idUUIDFK → auth.users(id)
order_idUUIDFK → orders(id)
stars_spentINTNOT NULL
statusTEXTDEFAULT 'pending', CHECK (pending|applied|cancelled)

Row Level Security Summary

TableSELECTINSERTUPDATE
profilesOwn onlyAuto (trigger)Own only
locationsActive only——
menu_categoriesActive only——
menu_itemsAvailable onlyAdminAdmin
modifier_groupsAll——
modifiersAvailable onlyAdminAdmin
ordersOwn + staffOwnStaff
order_itemsOwn + staffOwn—
loyalty_accountsOwnOwnOwn
star_transactionsOwnOwn—
rewardsActive only——
reward_redemptionsOwnOwn—