# Build Reliable Python Database Layers

Database layers often suffer from inconsistent sessions, schemas, and query patterns. This skill provides reusable SQLModel and SQLAlchemy examples for connections, repositories, migrations, optimization, and tests.

## Install

```bash
npx skillstore add azeem-2/database
```

## Metadata

- Status: approved
- Slug: azeem-2-database
- Skillstore revision: r3
- Version status: missing
- Tree hash: 47fab9601a6f7d137e3a7028dcc9c0ddbb0b1a6cf8beefdf076b0fe91209fff5
- Author: Azeem-2
- GitHub username: Azeem-2
- License: MIT
- Repository: https://github.com/Azeem-2/HackthonII/tree/master/.claude/skills/database
- Ref: 89edfdc710d0846129dcee6a929477b04f08052c
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: confirmation\_required
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: scripts, external\_commands, env\_access
- Quality score: 38
- Quality tier: warning
- Public page: https://skillstore.pages.dev/skills/azeem-2-database
- Manifest: https://skillstore.pages.dev/api/skills/azeem-2-database/manifest

## Capabilities

- Design SQLModel models with indexes, relationships, timestamps, and soft deletion.
- Configure asynchronous database engines, sessions, pooling, and cleanup.
- Draft reusable repository methods for create, read, update, delete, filtering, and pagination.
- Create Alembic migration patterns for tables, constraints, indexes, and rollback steps.
- Review query performance, PostgreSQL statistics, and isolated database tests.

## Use Cases

- Create an application data layer: Define models, sessions, repositories, and indexes for a new Python service.
- Review production database design: Assess pooling, migrations, query plans, and PostgreSQL monitoring before deployment.
- Build isolated database tests: Create fixtures and test cases for transactions, repositories, pagination, and tenant boundaries.

## Prompt Templates

### Create a starter schema

```
Design SQLModel models for [domain]. Include field types, relationships, constraints, and essential indexes. Explain each design choice.
```

### Build an async repository

```
Create an AsyncSession repository for [model]. Include typed create and update inputs, pagination, transactions, rollback, and an explicit field allowlist.
```

### Review a migration

```
Review this migration plan for [change]. Identify locking, data loss, rollback, index, and deployment risks. Propose safer steps.
```

### Audit performance and isolation

```
Audit this database design for [workload]. Analyze query plans, pool sizing, tenant isolation, authorization boundaries, monitoring, and failure recovery.
```

## Limitations

- It provides documentation and examples; it does not connect to databases or execute migrations.
- Some repository examples declare asynchronous functions while using synchronous Session methods.
- PostgreSQL monitoring examples require pg\_stat\_statements and adaptation for current SQLAlchemy APIs.
- Generated patterns still require schema-specific validation, authorization, load testing, and operational review.

## Best Practices

- Use typed create and update schemas with explicit field allowlists.
- Require production connection URLs through secret management and fail when configuration is missing.
- Test transactions, tenant isolation, migrations, and query plans before deployment.

## Anti Patterns

- Do not copy placeholder credentials into production configurations.
- Do not pass untrusted dictionaries directly into generic repository methods.
- Do not mix synchronous session calls with asynchronous engines and request handlers.

## Security Audit

- Audited at: 2026-07-23T09:51:29.08\+00:00
- Summary: Most alerts are false positives caused by SQLModel Session.exec and Markdown fences; they do not invoke Python, processes, or shells. The production example retains a default database credential, and generic repository writes accept unrestricted model fields.

## Stats

- Views: 265
- Downloads: 9
- Favorites: 0
- Popularity score: 0
