Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

D1 Database Schema

Defined in migrations/0001_create_schema.sql.

Tables

tenants

ColumnDefinition
idTEXT PRIMARY KEY
emailTEXT UNIQUE
nameTEXT
facebook_idTEXT
planTEXT DEFAULT 'paid'
localeTEXT NOT NULL DEFAULT 'en-IN'
currencyTEXT NOT NULL DEFAULT 'INR'
created_atTEXT DEFAULT (datetime('now'))
updated_atTEXT DEFAULT (datetime('now'))

sessions

ColumnDefinition
tokenTEXT PRIMARY KEY
tenant_idTEXT NOT NULL
expires_atINTEGER NOT NULL
created_atTEXT NOT NULL

whatsapp_accounts

ColumnDefinition
idTEXT PRIMARY KEY
tenant_idTEXT NOT NULL
nameTEXT NOT NULL
phone_number_idTEXT NOT NULL UNIQUE
display_phone_numberTEXT NOT NULL
waba_idTEXT
reply_jsonTEXT NOT NULL
canned_safety_jsonTEXT NOT NULL
created_atTEXT NOT NULL

tenant_onboarding

ColumnDefinition
tenant_idTEXT PRIMARY KEY
state_jsonTEXT NOT NULL
updated_atTEXT NOT NULL

signup_states

ColumnDefinition
stateTEXT PRIMARY KEY
tenant_idTEXT NOT NULL
expires_atINTEGER NOT NULL

conversation_sessions

ColumnDefinition
session_keyTEXT PRIMARY KEY
session_jsonTEXT NOT NULL
expires_atINTEGER NOT NULL
updated_atTEXT NOT NULL

rate_limits

ColumnDefinition
bucket_keyTEXT PRIMARY KEY
countINTEGER NOT NULL
expires_atINTEGER NOT NULL

pending_inbound

ColumnDefinition
idTEXT PRIMARY KEY
batch_keyTEXT NOT NULL
message_jsonTEXT NOT NULL
created_at_msINTEGER NOT NULL

messages

ColumnDefinition
idTEXT PRIMARY KEY
tenant_idTEXT NOT NULL
channelTEXT NOT NULL
channel_account_idTEXT NOT NULL DEFAULT ''
directionTEXT NOT NULL
senderTEXT NOT NULL
recipientTEXT NOT NULL
action_takenTEXT
conversation_idTEXT
created_atTEXT NOT NULL DEFAULT (datetime('now'))

payments

ColumnDefinition
idTEXT PRIMARY KEY
tenant_idTEXT
razorpay_payment_idTEXT
razorpay_order_idTEXT
amountINTEGER NOT NULL
creditsINTEGER NOT NULL DEFAULT 0
currencyTEXT NOT NULL
statusTEXT NOT NULL
created_atTEXT NOT NULL DEFAULT (datetime('now'))

tenant_billing

ColumnDefinition
tenant_idTEXT PRIMARY KEY
credits_jsonTEXT NOT NULL DEFAULT '[]'
replies_usedINTEGER NOT NULL DEFAULT 0
updated_atTEXT NOT NULL DEFAULT (datetime('now'))

Indexes

IndexTableColumnsUnique
idx_tenants_emailtenantsemailYes
idx_tenants_facebooktenantsfacebook_idNo
idx_sessions_tenantsessionstenant_idNo
idx_sessions_expiressessionsexpires_atNo
idx_whatsapp_accounts_tenantwhatsapp_accountstenant_idNo
idx_whatsapp_accounts_phonewhatsapp_accountsphone_number_idYes
idx_signup_states_expiressignup_statesexpires_atNo
idx_conversation_sessions_expiresconversation_sessionsexpires_atNo
idx_rate_limits_expiresrate_limitsexpires_atNo
idx_pending_inbound_batchpending_inboundbatch_key, created_at_msNo
idx_messages_tenantmessagestenant_id, created_atNo
idx_messages_channelmessageschannel, tenant_id, created_atNo
idx_messages_channel_accountmessageschannel_account_idNo
idx_messages_conversationmessagesconversation_id, created_atNo
idx_payments_tenantpaymentstenant_id, created_atNo
idx_payments_razorpay_idpaymentsrazorpay_payment_idYes