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
64 changes: 61 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
run: |
flake8 omymodels/ --count --show-source --statistics

# Unit and functional tests
tests:
runs-on: ubuntu-latest
needs: [flake8_py3]
Expand All @@ -43,9 +44,9 @@ jobs:
poetry install
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Test with pytest and coverage
- name: Run unit and functional tests
run: |
pytest tests/ -vv --cov=omymodels --cov-report=term-missing --cov-report=xml
pytest tests/unit tests/functional -vv --cov=omymodels --cov-report=term-missing --cov-report=xml
- name: Upload coverage to Codecov
if: matrix.python == '3.11'
uses: codecov/codecov-action@v4
Expand All @@ -54,6 +55,63 @@ jobs:
fail_ci_if_error: false
verbose: true

# Integration tests with SQLAlchemy 2.0 (pydantic, pydantic_v2, dataclass, sqlalchemy, sqlalchemy_v2, openapi3)
integration-sqlalchemy:
runs-on: ubuntu-latest
needs: [flake8_py3]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest simple-ddl-parser Jinja2 py-models-parser 'pydantic>=1.8.2,<2.0.0' table-meta 'sqlalchemy>=2.0'
pip install -e .
- name: Run SQLAlchemy integration tests
run: |
pytest tests/integration/pydantic tests/integration/pydantic_v2 tests/integration/dataclass tests/integration/sqlalchemy tests/integration/sqlalchemy_v2 tests/integration/openapi3 -vv

# Integration tests with Gino (requires SQLAlchemy<1.4)
# Tests use pre-generated code fixtures, no omymodels dependency at runtime
integration-gino:
runs-on: ubuntu-latest
needs: [flake8_py3]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest 'gino>=1.0.0'
- name: Run Gino integration tests
run: |
pytest tests/integration/gino -vv

# Integration tests with SQLModel (requires Pydantic>=2.0)
# Tests use pre-generated code fixtures, no omymodels dependency at runtime
integration-sqlmodel:
runs-on: ubuntu-latest
needs: [flake8_py3]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest 'sqlmodel>=0.0.22'
- name: Run SQLModel integration tests
run: |
pytest tests/integration/sqlmodel -vv

deploy-pages:
runs-on: ubuntu-latest
needs: [tests]
Expand All @@ -78,4 +136,4 @@ jobs:

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v4
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Boolean defaults 0/1 converted to False/True
- Expanded `datetime_now_check` with more SQL datetime keywords

**SQLAlchemy 2.0 Support (issue #49)**
- New `sqlalchemy_v2` models type with modern SQLAlchemy 2.0 syntax
- Uses `DeclarativeBase` instead of deprecated `declarative_base()`
- Uses `Mapped[T]` type annotations for columns
- Uses `mapped_column()` instead of `Column()`
- Uses `X | None` union syntax for nullable columns
- Supports all column types, foreign keys, indexes, and constraints

**SQLModel Improvements**
- Fixed array type generation (issue #66)
- Arrays now properly generate `List[T]` with correct SQLAlchemy ARRAY type
Expand Down Expand Up @@ -75,6 +83,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed boolean values capitalization - now generates `True`/`False` instead of `true`/`false` (PR #67)
- Fixed SQLModel array type generation TypeError (issue #66)
- Fixed MySQL blob types not mapping to `bytes` (issue #62)
- Fixed `sqlalchemy_core` generator missing column names in output
- Fixed `sqlalchemy_core` generator not including type name with size (e.g., `String(255)`)
- Fixed `sqlalchemy_core` generator ForeignKey positional argument order

### Documentation

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ O! My Models (omymodels) is a library that allow you to **generate** different O

Supported Models:

- SQLAlchemy ORM (https://docs.sqlalchemy.org/en/20/orm/)
- SQLAlchemy 2.0 ORM (https://docs.sqlalchemy.org/en/20/orm/) - modern syntax with `Mapped` and `mapped_column`
- SQLAlchemy ORM (legacy style)
- SQLAlchemy Core (Tables) (https://docs.sqlalchemy.org/en/20/core/metadata.html)
- SQLModel (https://sqlmodel.tiangolo.com/) - combines SQLAlchemy and Pydantic
- GinoORM (https://python-gino.org/)
Expand Down
Loading