Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env

This file was deleted.

9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
ADMIN_USER=admin ADMIN_PASS=pass ADMIN_SECRET=sec
# Database connection string used by the generated application
DATABASE_URL=sqlite+aiosqlite:///./database.db

# SQLAdmin authentication (only required when generating with --admin-auth)
ADMIN_USER=admin
ADMIN_PASS=change-me
# ADMIN_SECRET must be at least 32 characters long
ADMIN_SECRET=replace-with-a-secret-of-at-least-32-characters
59 changes: 59 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish to PyPI

# Publishes the package to PyPI when a GitHub Release is published.
# Uses PyPI Trusted Publishing (OIDC) — no API tokens are stored in the repo.
#
# One-time setup on PyPI (https://pypi.org/manage/account/publishing/):
# - Project name: dbml-to-sqlmodel
# - Owner: azhig
# - Repository: dbml-to-sqlmodel
# - Workflow name: publish.yml
# - Environment: pypi

on:
release:
types: [published]
workflow_dispatch:

jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "latest"

- name: Build sdist and wheel
run: uv build

- name: Check distribution metadata
run: uvx twine check dist/*

- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/dbml-to-sqlmodel/
permissions:
id-token: write # required for trusted publishing
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ habr_article.md
*.db-shm
*.db-wal

# Generated files in root (legacy - если остались)
# Generated files in root
/models.py
/admin.py
/crud/
Expand All @@ -35,6 +35,7 @@ habr_article.md
.pytest_cache/
.ruff_cache/
.coverage
.mypy_cache
htmlcov/

# OS
Expand Down
66 changes: 32 additions & 34 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,39 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.1.0] - 2026-06-02

### Added
- Ruff configuration for linting and formatting
- Pre-commit hooks for code quality
- MyPy type checking support
- Dependabot for automated dependency updates
- CHANGELOG.md for tracking version changes
- CONTRIBUTING.md guidelines

### Changed
- Project structure refactored from `dbml_to_code` to `dbml_to_sqlmodel`
- Updated Makefile with correct CLI commands
- Improved .gitignore patterns

## [0.1.0] - 2026-01-14
Initial public release.

### Added
- Initial release
- DBML to SQLModel conversion
- FastAPI CRUD generation
- Interactive CLI with questionary
- Preview mode with diff display
- Info command for file inspection
- GitHub Actions CI/CD pipeline
- Test coverage reporting
- Example schema files

### Features
- Generate SQLModel models from DBML schemas
- Auto-generate FastAPI CRUD endpoints
- SQLAdmin integration
- Database migrations support
- Type-safe code generation
- CLI with multiple commands (generate, preview, info)

[Unreleased]: https://github.com/yourusername/dbml-to-sqlmodel/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/yourusername/dbml-to-sqlmodel/releases/tag/v0.1.0
- DBML to SQLModel model generation
- FastAPI CRUD endpoint generation powered by
[FastCRUD](https://github.com/igorbenav/fastcrud)
- Optional [SQLAdmin](https://github.com/aminalaee/sqladmin) admin panel, with
optional constant-time credential authentication (`--admin-auth`)
- Modular generated project: one package per table, plus a wired-up `main.py`
that uses the FastAPI `lifespan` API and reads `DATABASE_URL` from the
environment (`.env`)
- Correct temporal type mapping: DBML `timestamp`/`datetime`/`date`/`time` map to
Python `datetime`/`date`/`time` with the matching imports
- PascalCase class names and singularized relationship attribute names
- Interactive CLI (`questionary`) plus direct subcommands: `generate`,
`preview`, `info` and `code-to-dbml`
- Preview mode with diff display and protection for manual edits via the
`USER_MODIFIED` marker
- Reverse conversion: generated code back to DBML
- `--version` / `-V` flag
- Generated `requirements.txt` with runtime versions aligned to the tested
stack (including `greenlet`, which the async SQLAlchemy engine needs but
which is not auto-installed on every platform)
- `py.typed` marker (PEP 561) and full PyPI packaging metadata (authors,
keywords, Trove classifiers, project URLs)
- Documentation: README, CLI guide and contributing guidelines
- Tooling: Ruff, MyPy, pre-commit, Dependabot, GitHub Actions CI with Codecov
coverage and a PyPI trusted-publishing workflow
- Test suite with 100% coverage, including smoke tests that compile the
generated application and guard temporal-type, lifespan and requirements
regressions

[0.1.0]: https://github.com/azhig/dbml-to-sqlmodel/releases/tag/v0.1.0
18 changes: 11 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Thank you for your interest in contributing! This document provides guidelines f

1. **Clone the repository**
```bash
git clone <your-repo-url>
cd dbml_to_crud
git clone https://github.com/azhig/dbml-to-sqlmodel.git
cd dbml-to-sqlmodel
```

2. **Install uv** (if not already installed)
Expand Down Expand Up @@ -232,18 +232,22 @@ docs(readme): update installation instructions
## Project Structure

```
dbml_to_crud/
dbml-to-sqlmodel/
├── src/
│ └── dbml_to_sqlmodel/ # Main package
│ ├── cli.py # CLI entry point
│ ├── parser.py # DBML parser
│ ├── generator.py # Code generator
│ ├── config.py # Configuration
│ └── templates/ # Jinja2 templates
│ ├── core/ # Parser, config, code generation
│ ├── commands/ # CLI subcommands (generate, preview, info, code-to-dbml)
│ ├── integrations/ # pydbml adapter
│ ├── models/ # Internal data models
│ ├── utils/ # Helpers (diff, formatters, file manager)
│ └── templates/ # Code templates
├── tests/ # Test files
├── examples/ # Example schemas
├── docs/ # Documentation
├── Makefile # Development commands
└── pyproject.toml # Project metadata
└── pyproject.toml # Project metadata
```

## Configuration Files
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help install cli generate preview info run dev clean db-reset format format-imports lint lint-fix typecheck check pre-commit pre-commit-install fresh restart full-reset
.PHONY: help install cli generate preview info run-deps run dev clean db-reset format format-imports lint lint-fix typecheck check pre-commit pre-commit-install fresh restart full-reset

# Output colors
GREEN := \033[0;32m
Expand Down Expand Up @@ -27,10 +27,14 @@ preview: ## Show diff without writing files
info: ## Show generated files and mismatches
uv run dbml-to-sqlmodel info examples/schema.dbml

run: ## Run server (production)
run-deps: ## Install runtime dependencies for the generated app (fastapi, sqlmodel, greenlet, ...)
uv sync --extra runtime
@echo "$(GREEN)OK: runtime dependencies installed$(NC)"

run: run-deps ## Run server (production)
cd output && uv run python main.py

dev: ## Run server in development mode (hot reload)
dev: run-deps ## Run server in development mode (hot reload)
cd output && uv run uvicorn main:app --reload --host 0.0.0.0 --port 8001

clean: ## Remove generated files and caches
Expand Down
Loading
Loading