☰
DMCall
slpx2
Edit Rule
Cancel
Title *
Slug
Publicly accessible (AI models can read without auth)
Content (Markdown)
# Database Conventions ## When to Use MongoDB vs MySQL ### MongoDB (Primary for new projects) - Document-oriented data (emails, threads, project configs, logs) - Flexible/evolving schemas - JSON-like data structures - Time-series data - Projects: bMonV3, extension2, dmcall ### MySQL (Use when needed) - Relational data with strong foreign key needs - Legacy projects that already use it - CRM data with complex joins - Projects: finservdna, hansen ## MongoDB Patterns ### Connection ```php $client = new MongoDB\Client('mongodb://127.0.0.1:27017'); $db = $client->selectDatabase('database_name'); $collection = $db->selectCollection('collection_name'); ``` ### Naming - Database names: lowercase, match project slug (e.g., `dmcall`, `email_intelligence`, `bMonV3`) - Collection names: `prefix_entity` (e.g., `dmcall_projects`, `dmcall_rules`) - Use `snake_case` for field names ### Standard Fields Every document should include: ```json { "created_at": "2026-02-20 14:30:00", "updated_at": "2026-02-20 14:30:00" } ``` ### Upsert Pattern ```php $db->insertOrUpdate('collection', ['slug' => $slug], $data); ``` This uses `updateOne` with `upsert: true` under the hood. ## MySQL Patterns ### Connection ```php define('DB_HOST', 'localhost'); define('DB_NAME', 'database'); define('DB_USER', 'root'); define('DB_PASS', 'password'); ``` ### Naming - Database names: `snake_case` matching project - Table names: `snake_case`, plural (e.g., `email_threads`, `contacts`) - Column names: `snake_case` ## Common Pitfalls 1. **Never use raw SQL in extension2** — always use `QueryAdapter` 2. **MongoDB insertOrUpdate()** — not `upsert()` (custom wrapper method) 3. **AI proxy models** must be keyed by provider: `[$provider => $model]` 4. **No auth needed** for local MongoDB or MySQL connections on the server
Update Rule
Cancel