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)
)

+ Add column

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

+ Add index

Indexes

Name Columns Unique SQL Drop?
idx_billing_cache_period
  • year
  • month
SQL
CREATE INDEX idx_billing_cache_period
ON billing_cache(year, month)
Drop
idx_billing_cache_store store_key SQL
CREATE INDEX idx_billing_cache_store
ON billing_cache(store_key)
Drop
sqlite_autoindex_billing_cache_1
  • store_key
  • year
  • month
SQL
-- no sql found --
Drop