Skip to content

Commit

Permalink
fix: Add testing for sqlalchemy 2.0 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCardin committed Jul 6, 2023
1 parent 18ab2eb commit 6ef0f3c
Show file tree
Hide file tree
Showing 172 changed files with 577 additions and 318 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
pytest-version: ["6.2", "7.0"]
pytest-asyncio-version: ["0.16", "0.19"]
sqlalchemy-version: ["1.3", "1.4"]
pytest-version: ["6.2.0", "7.0.0"]
pytest-asyncio-version: ["0.16.0", "0.19.0"]
sqlalchemy-version: ["1.3.0", "1.4.0", "2.0.0"]

steps:
- uses: actions/checkout@v3
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ build:
poetry build

test:
COVERAGE_PROCESS_START="$(PWD)/pyproject.toml" \
SQLALCHEMY_WARN_20=1 COVERAGE_PROCESS_START="$(PWD)/pyproject.toml" \
coverage run -m pytest src tests -vv
coverage combine
coverage report -i
coverage xml

lint:
ruff src tests || exit 1
black --check src tests || exit 1
ruff src tests examples || exit 1
black --check src tests examples || exit 1
mypy src tests || exit 1

format:
ruff --fix src tests
black src tests
ruff --fix src tests examples
black src tests examples

publish: build
poetry publish -u __token__ -p '${PYPI_TOKEN}' --no-interaction
Expand Down
3 changes: 2 additions & 1 deletion docs/source/asyncio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ thus fixes :ref:`test_downgrade_leaves_no_trace`.
if isinstance(connectable, AsyncEngine):
asyncio.run(run_async_migrations(connectable))
else:
do_run_migrations(connectable)
with connectable.connect() as connection:
do_run_migrations(connection)
# Then use their setup for async connection/running of the migration
Expand Down
6 changes: 5 additions & 1 deletion docs/source/experimental_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ after its definition.
import sqlalchemy
from sqlalchemy import Column, types
from sqlalchemy.ext.declarative import declarative_base
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
Expand Down
3 changes: 1 addition & 2 deletions examples/test_alternative_script_location/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config, pool

from models import Base
from sqlalchemy import engine_from_config, pool

fileConfig(context.config.config_file_name)
target_metadata = Base.metadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from alembic import op
import sqlalchemy as sa
from alembic import op

revision = "aaaaaaaaaaaa"
down_revision = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from alembic import op
from sqlalchemy import text

revision = "bbbbbbbbbbbb"
down_revision = "aaaaaaaaaaaa"
Expand All @@ -8,7 +9,7 @@

def upgrade():
conn = op.get_bind()
result = conn.execute("SELECT * FROM foo").fetchall()
result = conn.execute(text("SELECT * FROM foo")).fetchall()
assert len(result) == 0


Expand Down
7 changes: 6 additions & 1 deletion examples/test_alternative_script_location/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sqlalchemy
from sqlalchemy import Column, types
from sqlalchemy.ext.declarative import declarative_base

try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()

Expand Down
3 changes: 1 addition & 2 deletions examples/test_ambiguous_downgrade_history/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config, pool

from models import Base
from sqlalchemy import engine_from_config, pool

fileConfig(context.config.config_file_name)
target_metadata = Base.metadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: 10483a8dd3c8
"""Revision ID: 10483a8dd3c8
Revises: first
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = '10483a8dd3c8'
down_revision = 'first'
revision = "10483a8dd3c8"
down_revision = "first"
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: 25521e40a00f
"""Revision ID: 25521e40a00f
Revises: b55e304ba00c, bd7be2a11e1c
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = '25521e40a00f'
down_revision = ['b55e304ba00c', 'bd7be2a11e1c']
revision = "25521e40a00f"
down_revision = ["b55e304ba00c", "bd7be2a11e1c"]
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: 68bf6c25ca140073cfa0
"""Revision ID: 68bf6c25ca140073cfa0
Revises: first
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = '68bf6c25ca140073cfa0'
down_revision = 'first'
revision = "68bf6c25ca140073cfa0"
down_revision = "first"
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: 79ee02b5e895
"""Revision ID: 79ee02b5e895
Revises: 10483a8dd3c8, effc355fddff
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = '79ee02b5e895'
down_revision = ('10483a8dd3c8', 'effc355fddff')
revision = "79ee02b5e895"
down_revision = ("10483a8dd3c8", "effc355fddff")
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: 7f5b06f81aef
"""Revision ID: 7f5b06f81aef
Revises: effc355fddff
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = '7f5b06f81aef'
down_revision = 'effc355fddff'
revision = "7f5b06f81aef"
down_revision = "effc355fddff"
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: 845c0ab60c02
"""Revision ID: 845c0ab60c02
Revises: 7f5b06f81aef, 68bf6c25ca140073cfa0
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = '845c0ab60c02'
down_revision = ('7f5b06f81aef', '68bf6c25ca140073cfa0')
revision = "845c0ab60c02"
down_revision = ("7f5b06f81aef", "68bf6c25ca140073cfa0")
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: b55e304ba00c
"""Revision ID: b55e304ba00c
Revises: 7f5b06f81aef, 79ee02b5e895
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = 'b55e304ba00c'
down_revision = ('7f5b06f81aef', '79ee02b5e895')
revision = "b55e304ba00c"
down_revision = ("7f5b06f81aef", "79ee02b5e895")
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: first
"""Revision ID: first
Revises:
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = 'first'
revision = "first"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: bd7be2a11e1c
"""Revision ID: bd7be2a11e1c
Revises: 845c0ab60c02
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = 'bd7be2a11e1c'
down_revision = '845c0ab60c02'
revision = "bd7be2a11e1c"
down_revision = "845c0ab60c02"
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Revision ID: effc355fddff
"""Revision ID: effc355fddff
Revises: first
Create Date: 2020-07-01 16:44:05.244310
Create Date: 2020-07-01 16:44:05.244310.
"""
# revision identifiers, used by Alembic.
revision = 'effc355fddff'
down_revision = 'first'
revision = "effc355fddff"
down_revision = "first"
branch_labels = None
depends_on = None


def upgrade():
pass

Expand Down
8 changes: 5 additions & 3 deletions examples/test_ambiguous_downgrade_history/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sqlalchemy
from sqlalchemy import Column, types
from sqlalchemy.ext.declarative import declarative_base
try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from alembic import op
import sqlalchemy as sa
from alembic import op

revision = "aaaaaaaaaaaa"
down_revision = None
Expand Down
7 changes: 6 additions & 1 deletion examples/test_async_sqlalchemy/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sqlalchemy
from sqlalchemy import Column, types
from sqlalchemy.ext.declarative import declarative_base

try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()

Expand Down
2 changes: 1 addition & 1 deletion examples/test_async_sqlalchemy_native/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
alembic_engine = create_postgres_fixture(async_=True)


@pytest.fixture
@pytest.fixture()
def alembic_config():
return {"before_revision_data": {"bbbbbbbbbbbb": {"__tablename__": "foo", "id": 9}}}
3 changes: 2 additions & 1 deletion examples/test_async_sqlalchemy_native/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def run_migrations_online():
if isinstance(connectable, AsyncEngine):
asyncio.run(run_async_migrations(connectable))
else:
do_run_migrations(connectable)
with connectable.connect() as connection:
do_run_migrations(connection)


async def run_async_migrations(connectable):
Expand Down
7 changes: 6 additions & 1 deletion examples/test_async_sqlalchemy_native/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sqlalchemy
from sqlalchemy import Column, types
from sqlalchemy.ext.declarative import declarative_base

try:
from sqlalchemy.orm import declarative_base
except ImportError:
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()

Expand Down
2 changes: 1 addition & 1 deletion examples/test_basic_revision_upgrade_data/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest


@pytest.fixture
@pytest.fixture()
def alembic_config():
return {"before_revision_data": {"bbbbbbbbbbbb": {"__tablename__": "foo", "id": 9}}}
3 changes: 1 addition & 2 deletions examples/test_basic_revision_upgrade_data/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config, pool

from models import Base
from sqlalchemy import engine_from_config, pool

fileConfig(context.config.config_file_name)
target_metadata = Base.metadata
Expand Down
Loading

0 comments on commit 6ef0f3c

Please sign in to comment.