portal-db-models

Define SQLModel ORM models and Pydantic API schemas mirroring a dbmate-managed database schema.

Updated Jul 27, 2026
One-click install
npx skills add https://github.com/ArthurZizumbo/karisma-data --skill portal-db-models-arthurzizumbo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: portal-db-models
Source: https://github.com/ArthurZizumbo/karisma-data/tree/main/.claude/skills/portal-db-models
Command: npx skills add https://github.com/ArthurZizumbo/karisma-data --skill portal-db-models-arthurzizumbo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires sqlmodel, sqlalchemy, pgvector.

What problem does it solve? Keeping SQLModel ORM classes consistent with a dbmate-managed database schema is error-prone: developers may accidentally generate tables from models, leak password hashes into API responses, or drift from the migration-defined schema. This Skill enforces a strict modeling pattern so the Portal backend stays aligned with its migrations. ## Core Features & Use Cases - Three-class pattern: Defines XBase (shared Pydantic fields), X (table=True ORM), and XOut/XCreate/XUpdate API contracts so routers never expose internal fields. - Schema mirroring, not generation: Models reflect the dbmate schema for app_user, catalog_source, catalog_field, catalog_tribal_note, and export_job; SQLModel.metadata.create_all() is forbidden outside isolated test fixtures. - Security and audit rules: Soft delete via disabled = true, hashed_password never serialized in *Out models, role enums matching JWT scopes, and created_at audit timestamps on every table. - Use Case: When adding a new catalog table or modifying the export job model, apply this Skill to produce SQLModel classes with pgvector embeddings, JSONB columns, and async SQLAlchemy session compatibility that exactly match the existing migrations. ## Quick Start Use the portal-db-models skill to create the SQLModel models for the catalog tables mirroring the existing dbmate schema.

Frequently Asked Questions about portal-db-models

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define SQLModel models that match an existing database schema?

Create SQLModel classes with table=True whose fields mirror the migration-defined columns exactly, and never call SQLModel.metadata.create_all() outside isolated test fixtures. The migrations tool owns the schema; the models only reflect it.

How to separate SQLModel ORM models from API response schemas?

Use a three-class pattern: an XBase class with shared Pydantic fields, an X class with table=True for the ORM, and XOut/XCreate/XUpdate classes as API contracts. Routers only expose XOut, so internal fields like hashed_password never leak.

Does SQLModel support pgvector and JSONB columns?

Yes, via the sa_column parameter on Field. Use sa_column=Column(Vector(768)) for pgvector embeddings and sa_column=Column(JSONB, nullable=False) for JSONB payloads such as serialized query objects.

How do I implement soft delete for users in SQLModel?

Add a disabled boolean field defaulting to False and set it to true instead of deleting the row, preserving audit history. Combine it with a created_at timestamptz audit field on every table.

Why should hashed_password be excluded from API response models?

Serializing password hashes in responses exposes credential material to clients and logs. Define separate Out models that omit hashed_password entirely so it can never be returned by routers or written to logs.