database-management

A collection of database rules for Python projects using SQLAlchemy, PostgreSQL, and Alembic. SQLAlchemy maps Python classes to database tables, PostgreSQL stores the data, and Alembic manages database structure changes called migrations.

In plain words
What is it for?
Use it when creating or changing asynchronous SQLAlchemy models, PostgreSQL indexes, UTC timestamps, or Alembic migrations.
Why use it?
It keeps models, identifiers, timestamps, soft deletion, audit fields, indexes, and migrations consistent across the application.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/aps08/fullstack-clean-architecture/database_management
Any agent
npx skills add aps08/fullstack-clean-architecture --skill database_management
Clone the repo
git clone --depth 1 https://github.com/aps08/fullstack-clean-architecture

Made for: Claude Code, Codex.

Per session 25 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 642 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00025 $0.00642
Opus 5 $0.00013 $0.00321
Sonnet 5 $0.00005 $0.00128
Haiku 4.5 $0.00003 $0.00064

Measured yesterday against content hash dba8dcad4796, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

database-management scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/database_management/SKILL.md · 49 lines

How it starts

The opening of the file, as written. The whole thing — 49 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Management Skill

1. SQLAlchemy Base Class & Models

All database models (except system/internal models where not applicable) must inherit from BaseModel defined in server/app/models/base.py.

Automatically Handled by BaseModel

  • Table Names: Automatically converted from PascalCase class names to snake_case (e.g., Todos -> todos, Attachments -> attachments).
  • Primary Keys: Defined as a native PostgreSQL UUID using PG_UUID(as_uuid=True) with database-side generator server_default=text("gen_random_uuid()").
  • Audit Fields: All models inherit these auditing and metadata fields:
    • id: Mapped[UUID] primary key.
    • is_active: Boolean status defaulting to true on the server.
    • is_deleted: Soft-delete status defaulting to false on the server.
    • created_at / updated_at: Timezone-aware UTC timestamps with server_default=func.now() (and onupdate=func.now() for updates).
    • created_by / updated_by: VARCHAR(100) auditing fields.

Best Practices for Custom Models

  • Inheritance: Always subclass BaseModel.
  • Use Database Defaults: Lean on PostgreSQL for default values as much as possible using server_default (e.g. server_default=text("true") rather than Python-level default=True).
  • Type Annotations: Use SQLAlchemy 2.0 Mapped[...] and mapped_column() syntax.
  • Foreign Keys:
    • Explicitly define ondelete behavior (e.g. ondelete="CASCADE").
    • Add index=True for foreign key columns to ensure performant joins.
  • Timezones: Use timezone-aware datetime objects (TIMESTAMP(timezone=True)) or Pydantic UTC validation.
  • Relationships: Define back-populates and lazy loading modes explicitly (e.g., lazy="selectin" for eager loading without Cartesian products).

2. Database Queries & Transactions

  • Async execution: All database interactions must be executed asynchronously using AsyncSession.
  • Eager Loading: Always declare eager relationships where expected to avoid N+1 queries. Specify eagers list on models if supported by the service repository.
  • Optimistic Concurrency: Use auditing columns or version fields if concurrent updates are expected on highly mutated resources.

Read the full file on GitHub · 49 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 49 lines · 25 tokens per session scan A dba8dcad4796

Subscribe to this mod's changes

database-management is a skill published in the GitHub repository aps08/fullstack-clean-architecture (2 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 25 tokens to every session and 642 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.