PluginMind Docs

Database Schema

PluginMind uses SQLModel for typed models that map directly to FastAPI responses. The same schema works with SQLite (dev/test) and PostgreSQL (production).


๐Ÿ”‘ Connection

app/database.py creates a shared engine using settings.database_url. Example values:

  • sqlite:///./pluginmind.db
  • postgresql://pluginmind:password@postgres:5432/pluginmind

Sessions are provided through the get_session dependency.


๐Ÿ“‹ Tables

users

Tracks authenticated users and usage counters.

ColumnTypeNotes
idINTEGER PKAuto-increment.
emailTEXT UNIQUEPrimary identifier for session management.
google_idTEXT UNIQUE NULLABLEStored when provided by Google token.
subscription_tierTEXTfree by default.
queries_usedINTEGERIncremented per successful /process call.
queries_limitINTEGERDefault 10.
is_activeBOOLEANSoft enable/disable.
created_atDATETIMESet on creation.

analysis_jobs

Persists async requests (/analyze-async).

ColumnTypeNotes
idINTEGER PKInternal ID.
job_idTEXT UNIQUEUUID exposed to clients.
user_inputTEXTOriginal request body.
statusTEXTEnum: queued, processing_openai, processing_grok, completed, failed.
created_atDATETIMEJob creation time.
completed_atDATETIME NULLABLESet on completion/failure.
optimized_promptTEXT NULLABLESaved result from OpenAI.
analysisTEXT NULLABLESaved result from Grok.
errorTEXT NULLABLEUser-friendly error message.
user_idTEXT NULLABLEReference to users.google_id/email.
costFLOAT NULLABLEReserved for future billing.

query_logs

Captures synchronous /process calls (success or failure).

ColumnTypeNotes
idINTEGER PKAuto increment.
user_idTEXT NULLABLEEmail or Google ID.
user_inputTEXTTruncated in responses for readability.
optimized_promptTEXT NULLABLESaved prompt optimiser output.
ai_resultTEXT NULLABLESerialized analysis result.
created_atDATETIMETimestamp.
response_time_msINTEGER NULLABLEMeasured latency.
successBOOLEANTrue/False.
error_messageTEXT NULLABLECaptured error string.
openai_costFLOAT NULLABLEPlaceholder for usage tracking.
grok_costFLOAT NULLABLEPlaceholder.
total_costFLOAT NULLABLEPlaceholder.

analysis_results

Flexible storage for generic analyses (used when a DB session is provided to analyze_generic).

ColumnTypeNotes
idINTEGER PK
analysis_idTEXT UNIQUEExternal reference (UUID).
analysis_typeTEXTMirrors AnalysisType enum values.
user_idTEXT NULLABLEOwning user.
user_inputTEXTOriginal content.
result_dataJSON NULLABLEStructured result body.
processing_metadataJSON NULLABLEArbitrary metadata (timings, provider info).
created_atDATETIMEStored automatically.
updated_atDATETIME NULLABLE
processing_time_msINTEGER NULLABLE
ai_service_usedTEXT NULLABLE
costFLOAT NULLABLE
statusTEXTEnum: PENDING, PROCESSING, COMPLETED, FAILED.
error_detailsTEXT NULLABLE

๐Ÿงฌ Enums

Located in app/models/enums.py:

  • JobStatus โ†’ QUEUED, PROCESSING_OPENAI, PROCESSING_GROK, COMPLETED, FAILED.
  • AnalysisResultStatus (inside database.py) โ†’ PENDING, PROCESSING, COMPLETED, FAILED.

๐Ÿ› ๏ธ Migrations

  • Alembic is configured (alembic.ini, alembic/).
  • Generate migrations with alembic revision --autogenerate -m "message".
  • Apply migrations using alembic upgrade head.

๐Ÿ’ก Notes & Tips

  • SQLite stores the database in the repository root (pluginmind_backend/test.db) during testsโ€”tests/conftest.py cleans it up automatically.
  • When using Postgres, set DATABASE_URL and ensure the role has rights to create tables (FastAPI calls SQLModel.metadata.create_all() on startup).
  • Want audit history? Add triggers or extend SQLModel models to include updated_at alongside created_at.

Happy modelling! ๐Ÿงฎ