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
92 changes: 12 additions & 80 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ on:
pull_request:

jobs:
dialect-sqlite:
uses: ./.github/workflows/dialect-sqlite.yml
secrets: inherit

dialect-postgresql:
uses: ./.github/workflows/dialect-postgresql.yml
secrets: inherit

static-analysis:
name: Static analysis
runs-on: ubuntu-latest
Expand All @@ -18,6 +26,7 @@ jobs:
uses: astral-sh/setup-uv@v8.2.0
with:
enable-cache: true
cache-suffix: static-analysis

- name: Ruff check
run: uv run ruff check .
Expand All @@ -38,9 +47,8 @@ jobs:
run: uv run mypy .

- name: Mypy (Example project)
run: |
cd example_project
uv run mypy .
working-directory: example_project
run: uv run mypy .

plugin-tests:
name: Plugin tests
Expand Down Expand Up @@ -95,82 +103,6 @@ jobs:
uses: astral-sh/setup-uv@v8.2.0
with:
enable-cache: true

cache-suffix: plugin-${{ matrix.python_version }}
- name: Run tests
run: uv run ${{ matrix.dependencies }} pytest

dialect-sqlite-tests:
name: Dialect tests (SQLite)
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

env:
UV_PYTHON: ${{ matrix.python_version }}
DATABASE_URL: sqlite:///./database.db

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}

- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
enable-cache: true

- name: Run example project tests
run: |
cd example_project
uv run pytest

dialect-postgresql-tests:
name: Dialect tests (PostgreSQL)
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
postgres_version: ["14", "15", "16", "17", "18"]

services:
postgres:
image: postgres:${{ matrix.postgres_version }}
env:
POSTGRES_USER: ci
POSTGRES_PASSWORD: password
POSTGRES_DB: example
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
UV_PYTHON: ${{ matrix.python_version }}
DATABASE_URL: postgresql://ci:password@localhost:5432/example

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}

- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
enable-cache: true

- name: Run example project tests
run: |
cd example_project
uv run --extra postgres pytest
52 changes: 52 additions & 0 deletions .github/workflows/dialect-postgresql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "PostgreSQL dialect tests"

on:
workflow_call:

jobs:
dialect-postgresql-tests:
name: Dialect tests (PostgreSQL)
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
postgres_version: ["14", "15", "16", "17", "18"]
drivername: ["postgresql+psycopg", "postgresql+psycopg2", "postgresql+pg8000", "postgresql+psycopg2cffi"]

services:
postgres:
image: postgres:${{ matrix.postgres_version }}
env:
POSTGRES_USER: ci
POSTGRES_PASSWORD: password
POSTGRES_DB: example
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
UV_PYTHON: ${{ matrix.python_version }}
DATABASE_URL: ${{ matrix.drivername }}://ci:password@localhost:5432/example

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}

- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
enable-cache: true
cache-suffix: postgres-${{ matrix.python_version }}

- name: Run example project tests
working-directory: example_project
run: uv run --extra postgres pytest
42 changes: 42 additions & 0 deletions .github/workflows/dialect-sqlite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Sqlite dialect tests"

on:
workflow_call:

jobs:
dialect-sqlite-tests:
name: Dialect tests (SQLite)
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
drivername: ["sqlite+pysqlite", "sqlite+pysqlcipher"]

include:
- drivername: "sqlite+pysqlite"
database_url: sqlite:///./database.db
- drivername: "sqlite+pysqlcipher"
database_url: sqlite+pysqlcipher://:example@/database.db

env:
UV_PYTHON: ${{ matrix.python_version }}
DATABASE_URL: ${{ matrix.database_url }}

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}

- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
enable-cache: true
cache-suffix: sqlite-${{ matrix.python_version }}

- name: Run example project tests
working-directory: example_project
run: uv run --extra sqlite pytest
7 changes: 7 additions & 0 deletions example_project/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SHELL := /bin/bash

.PHONY: dev_infra


infra_postgres:
docker compose -p example_project -f docker-compose.yml up -d --build postgres
2 changes: 1 addition & 1 deletion example_project/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
target_metadata = Base.metadata

if not config.get_main_option('sqlalchemy.url'):
config.set_main_option('sqlalchemy.url', str(settings.DATABASE_URL))
config.set_main_option('sqlalchemy.url', settings.DATABASE_URL)


def run_migrations_offline() -> None:
Expand Down
20 changes: 20 additions & 0 deletions example_project/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:

postgres:
image: postgres:18
volumes:
- postgres_data:/var/lib/postgresql
ports:
- 127.0.0.1:5432:5432
environment:
- POSTGRES_PASSWORD=example
- POSTGRES_USER=example
restart: on-failure
healthcheck:
test: pg_isready -U example
interval: 10s
timeout: 5s
retries: 5

volumes:
postgres_data:
3 changes: 1 addition & 2 deletions example_project/example_project/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from pydantic import AnyUrl
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8', env_ignore_empty=True)

DATABASE_URL: AnyUrl
DATABASE_URL: str


settings = Settings()
2 changes: 1 addition & 1 deletion example_project/example_project/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .config import settings

engine = create_engine(str(settings.DATABASE_URL))
engine = create_engine(settings.DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)


Expand Down
10 changes: 10 additions & 0 deletions example_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@ version = "0.1.0"

[project.optional-dependencies]
postgres = [
"pg8000>=1.31.5",
"psycopg>=3.3.4",
"psycopg2>=2.9.12",
"psycopg2cffi>=2.9.0",
]
sqlite = [
"sqlcipher3>=0.6.2",
]

[dependency-groups]
dev = [
"ipython>=8.39.0",
"mypy>=2.1.0",
"pytest>=9.0.3",
"pytest-sqlalchemy-alembic>=0.1.0",
]

[tool.uv]
reinstall-package = ["pytest-sqlalchemy-alembic"]

[tool.uv.sources]
pytest-sqlalchemy-alembic = {path = "../"}

Expand Down
Loading
Loading