Chatbot database table reference
Created: 2026-11-07 (Asia/Dhaka), following the user's instruction to create the new tables.
Post-restore status (2026-11-07)
The user restored mart at localhost:3308, including all six chatbot tables. Read-only verification found every chatbot table empty, all six foreign-key constraints present, and definitions equivalent to docs/chatbot-schema.sql (restored DDL explicitly states the same utf8mb4 charset). The restore initially omitted chatbot migration records. Following user approval, those six records were reconciled in batch 10; Laravel now reports all six as Ran. The original 25 migration records are preserved. No table definitions or business records were changed. Audit: docs/chatbot-migration-reconciliation.json. Earlier schema snapshot: docs/mart-schema-discovery.json. The original implementation notes below describe the pre-restore state.
The repair utility is CLI-only and checks by default:
php database/scripts/reconcile-chatbot-migrations.php
The --apply repair has already been run. Repeated execution exits without inserting records when tracking is complete. Future migrations must remain scoped to database/migrations/chatbot and the chatbot connection. Do not rollback batch 10 on the shared store database: it records adopted restored tables.
Created and migrated
The six Phase 1 tables below now exist in the currently configured local MySQL database, mart. All are empty. Existing table definitions were not changed; Laravel recorded six new entries in the existing migrations table.
| Table name | Purpose |
|---|---|
chatbot_sessions |
Conversation ownership-token hash, locale, consent evidence, activity timestamps and outcomes |
chatbot_messages |
Ordered finalized customer/agent/system messages, language, nullable STT confidence and provider metadata |
chatbot_extractions |
Per-message intent/entities, candidate/selected external product IDs and nullable confidence |
chatbot_tool_calls |
Sanitized tool inputs/results, status, timing and message/session references |
chatbot_product_synonyms |
Multilingual aliases referencing external product, brand or category IDs |
chatbot_follow_up_requests |
Persisted handoff reason and pending/in-progress/resolved/cancelled state |
Every new table uses the chatbot_ prefix. External Mart identifiers are strings without foreign keys into store tables; their actual mappings remain unverified. No starter synonyms were inserted with guessed IDs. No consent timestamp or confidence score is invented by a database default.
Message sequence numbers are unique within a session. Composite foreign keys prevent an extraction or tool call from referencing a message in a different session. Foreign keys connect only these chatbot-owned tables. Session deletion cascades to its dependent records; the application must apply the approved retention policy before permitting deletion.
The exact MySQL schema, without data or credentials, is saved in docs/chatbot-schema.sql. It is a reference snapshot, not a command to re-import into the database where these tables already exist.
Connection and migration commands
config/database.php defines a named chatbot connection. Optional CHATBOT_DB_* settings override the existing local DB_* settings, allowing a separate database later. The current .env was not changed. The application's original default connection and framework tables stay in place for this additive database work. A separate, least-privilege Mart read connection is still needed once the actual source is identified.
Chatbot migrations are kept in their own directory so this command selects only the new table migrations:
php artisan migrate --database=chatbot --path=database/migrations/chatbot
php artisan migrate:status --database=chatbot --path=database/migrations/chatbot
Do not run migrate:fresh, general rollback or seed commands against an existing store database. Normal php artisan migrate does not discover the nested chatbot migration directory; use the explicit command above.
Planned later, not created
These names are reserved proposals for the corresponding approved phases:
| Table name | Phase/purpose |
|---|---|
chatbot_draft_carts |
Phase 2: owned draft and cart version |
chatbot_draft_cart_items |
Phase 2: sellable references, requested quantities/units and selected packs |
chatbot_checkout_details |
Phase 2: protected customer/delivery details |
chatbot_checkout_quotes |
Phase 2: immutable authoritative/estimated terms and expiry |
chatbot_order_requests |
Phase 2: confirmed local request and review state |
chatbot_request_confirmations |
Phase 2: direct, version-bound customer evidence |
chatbot_staff_audit_events |
Phase 2: staff review actions and protected change records |
chatbot_submission_attempts |
Phase 3: remote idempotency, receipt and reconciliation |
Staff authentication will reuse local users with explicit authorization when implemented. No store product, customer, stock, payment or order table has been created or altered. Audio metadata and storage are deferred to Phase 4.
Verification
- SQLite-isolated automated suite: seven tests passed, 30 assertions.
- Schema tests cover connection separation, repeatable migration/rollback in test memory, cross-session reference rejection, duplicate message sequences and external references without real Mart tables.
- MySQL dry run reviewed; all six migrations then applied successfully in batch 2.
- Actual MySQL verification: six new empty tables and six local foreign-key constraints.
- Pint passed for modified PHP configuration, migrations and tests.
- Test-only APP_URL now uses a root URL, fixing the existing homepage-test failure without editing the development
.env.
This completes the requested Phase 1 schema additions. Product mappings, application models/tools, agent and chat UI are not implemented by this database-only change.