SQL
CREATE TABLE billing_cache (
id INTEGER PRIMARY KEY AUTOINCREMENT,
store_key TEXT NOT NULL,
year INTEGER NOT NULL,
month INTEGER NOT NULL,
-- Métricas de uso
total_sessions INTEGER DEFAULT 0,
total_calls INTEGER DEFAULT 0,
total_skus INTEGER DEFAULT 0,
-- Contadores por operación
image_generate_count INTEGER DEFAULT 0,
image_edit_count INTEGER DEFAULT 0,
description_generate_count INTEGER DEFAULT 0,
image_search_count INTEGER DEFAULT 0,
image_upload_count INTEGER DEFAULT 0,
-- Sesiones por tipo
image_generation_sessions INTEGER DEFAULT 0,
description_generation_sessions INTEGER DEFAULT 0,
search_sessions INTEGER DEFAULT 0,
-- Costos
api_cost_total REAL DEFAULT 0,
invoiced_amount REAL DEFAULT 0,
margin REAL DEFAULT 0,
margin_percent REAL DEFAULT 0,
-- Metadata
billing_model TEXT,
calculated_at TEXT DEFAULT (datetime('now')),
UNIQUE(store_key, year, month)
)
Columns
| Column | Data type | Allow null | Primary key | Actions |
|---|---|---|---|---|
id |
INTEGER |
✓ | ✓ | Rename | Drop |
store_key |
TEXT |
Rename | Drop | ||
year |
INTEGER |
Rename | Drop | ||
month |
INTEGER |
Rename | Drop | ||
total_sessions |
INTEGER |
✓ | Rename | Drop | |
total_calls |
INTEGER |
✓ | Rename | Drop | |
total_skus |
INTEGER |
✓ | Rename | Drop | |
image_generate_count |
INTEGER |
✓ | Rename | Drop | |
image_edit_count |
INTEGER |
✓ | Rename | Drop | |
description_generate_count |
INTEGER |
✓ | Rename | Drop | |
image_search_count |
INTEGER |
✓ | Rename | Drop | |
image_upload_count |
INTEGER |
✓ | Rename | Drop | |
image_generation_sessions |
INTEGER |
✓ | Rename | Drop | |
description_generation_sessions |
INTEGER |
✓ | Rename | Drop | |
search_sessions |
INTEGER |
✓ | Rename | Drop | |
api_cost_total |
REAL |
✓ | Rename | Drop | |
invoiced_amount |
REAL |
✓ | Rename | Drop | |
margin |
REAL |
✓ | Rename | Drop | |
margin_percent |
REAL |
✓ | Rename | Drop | |
billing_model |
TEXT |
✓ | Rename | Drop | |
calculated_at |
TEXT |
✓ | Rename | Drop |
Indexes
| Name | Columns | Unique | SQL | Drop? |
|---|---|---|---|---|
| idx_billing_cache_period |
|
SQL | Drop | |
| idx_billing_cache_store |
store_key
|
SQL | Drop | |
| sqlite_autoindex_billing_cache_1 |
|
✓ | SQL | Drop |