# Cloudflare D1 + KV Setup — NEXORA × Little Lemon V10

## Exact resource names and binding variables

| Resource type | Cloudflare resource name | Binding variable |
|---|---|---|
| D1 | `nexora-mobile-production` | `NEXORA_DB` |
| D1 | `little-lemon-booking-production` | `LITTLE_LEMON_DB` |
| Workers KV | `nexora-little-lemon-app-kv` | `APP_KV` |

Do not use R2 in this edition.

## Dashboard setup for ZIP / drag-and-drop deployment

1. Create D1 database `nexora-mobile-production`.
2. Create D1 database `little-lemon-booking-production`.
3. Create KV namespace `nexora-little-lemon-app-kv`.
4. Open **Workers & Pages → your Pages project → Settings → Bindings**.
5. Add D1 binding:
   - Variable name: `NEXORA_DB`
   - Database: `nexora-mobile-production`
6. Add D1 binding:
   - Variable name: `LITTLE_LEMON_DB`
   - Database: `little-lemon-booking-production`
7. Add KV binding:
   - Variable name: `APP_KV`
   - Namespace: `nexora-little-lemon-app-kv`
8. Repeat the same bindings for **Production** and **Preview** if both environments are used.
9. Redeploy the V10 ZIP.
10. Open `/api/health`. All three bindings should report `ready: true`.

The `_worker.js` file creates the required tables automatically when the API is first used.

## Optional Wrangler commands

```powershell
npx wrangler login
npx wrangler d1 create nexora-mobile-production
npx wrangler d1 create little-lemon-booking-production
npx wrangler kv namespace create nexora-little-lemon-app-kv --binding APP_KV
```

To apply the included SQL manually:

```powershell
npx wrangler d1 execute nexora-mobile-production --remote --file=./database/nexora-schema.sql
npx wrangler d1 execute little-lemon-booking-production --remote --file=./database/little-lemon-schema.sql
```

## Storage behavior

- NEXORA text messages, contacts, language settings, and themes sync to `NEXORA_DB`.
- Little Lemon reservations persist in `LITTLE_LEMON_DB`.
- Lightweight suite configuration, preferences, and recent-status keys use `APP_KV`.
- Image attachments remain local-only because R2 is not configured.
- LocalStorage remains an offline fallback.
