db-to-sqlalchemy-generator

Generates SQLAlchemy 2.0 ORM models and Pydantic DTO schemas from database specifications or DDL.

Updated Aug 15, 2026
One-click install
npx skills add https://github.com/jacksonlee-tw/mystock-vue --skill db-to-sqlalchemy-generator-jacksonlee-tw
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: db-to-sqlalchemy-generator
Source: https://github.com/jacksonlee-tw/mystock-vue/tree/main/mystock-analysis/.github/skills/db-to-sqlalchemy-generator
Command: npx skills add https://github.com/jacksonlee-tw/mystock-vue --skill db-to-sqlalchemy-generator-jacksonlee-tw

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Manually translating database design documents or DDL into SQLAlchemy ORM models and Pydantic schemas is repetitive and error-prone. This Skill automates that conversion, producing consistent, convention-compliant Python code for FastAPI projects. ## Core Features & Use Cases - DB Spec to ORM Conversion: Parses DB specification documents, SQL DDL, existing models, or verbal descriptions into SQLAlchemy 2.0 models with proper type mappings, constraints, and relationships. - Pydantic DTO Generation: Creates four standard DTOs per model (Base, Create, Update, Read) following FastAPI layered architecture conventions. - Special Case Handling: Automatically applies TimestampMixin, SoftDeleteMixin, CheckConstraint, StrEnum generation, and SQL Server dialect types where applicable. - Use Case: Given a DB spec document for a weighing-record module, generate models/weighing_record.py and schemas/weighing_record.py with all fields, indexes, foreign keys, and Alembic migration hints. ## Quick Start Generate SQLAlchemy models and Pydantic schemas from the DB specification document at docs/02_Design/db/ecard-weighing-db規格書.md.

Frequently Asked Questions about db-to-sqlalchemy-generator

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

FAQPage Schema
How do I generate SQLAlchemy models from a database design document?▼

Provide the DB specification document path or paste the DDL, and the Skill parses each table's fields, constraints, indexes, and foreign keys to produce SQLAlchemy 2.0 models using Mapped type annotations. Output files follow the models/<table_name>.py convention.

How to convert DDL to Pydantic schemas for FastAPI?▼

The Skill generates four standard Pydantic 2.x DTOs per table: Base, Create, Update, and Read. Base holds required business fields, Update makes all fields optional for partial updates, and Read adds id and timestamps with from_attributes enabled.

Does SQLAlchemy 2.0 model generation support SQL Server types?▼

Yes, SQL Server-specific column types are mapped using sqlalchemy.dialects.mssql types. Standard types like NVARCHAR, DECIMAL, and DATETIME map to String, Numeric, and DateTime(timezone=True) respectively.

How are foreign keys and relationships handled in generated models?▼

Foreign keys become ForeignKey columns paired with relationship declarations using back_populates on both sides. Many-to-many associations generate an intermediate table model with bidirectional relationship(secondary=...) mappings.

What happens when a table has soft delete or timestamp columns?▼

Tables with is_deleted or deleted_at columns automatically use SoftDeleteMixin, and tables with created_at and updated_at use TimestampMixin. This avoids duplicating these system columns in every generated model.