Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bump SQLAlchemy to v2 #214

Closed
wants to merge 2 commits into from
Closed
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
111 changes: 59 additions & 52 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packages = [
python = "<3.12,>=3.8.1"
singer-sdk = "~=0.31.0"
psycopg2-binary = "2.9.7"
sqlalchemy = "<2"
sqlalchemy = "~=2.0.20"
sshtunnel = "0.4.0"

[tool.poetry.group.dev.dependencies]
Expand Down
15 changes: 9 additions & 6 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from faker import Faker
from singer_sdk.testing import get_tap_test_class, suites
from singer_sdk.testing.runners import TapTestRunner
from sqlalchemy import Column, DateTime, Integer, MetaData, Numeric, String, Table
from sqlalchemy import Column, DateTime, Integer, MetaData, Numeric, String, Table, text
from sqlalchemy.dialects.postgresql import DATE, JSONB, TIME, TIMESTAMP, JSON
from test_replication_key import TABLE_NAME, TapTestReplicationKey
from test_selected_columns_only import (
Expand Down Expand Up @@ -50,7 +50,7 @@ def setup_test_table(table_name, sqlalchemy_url):
)
with engine.connect() as conn:
metadata_obj.create_all(conn)
conn.execute(f"TRUNCATE TABLE {table_name}")
conn.execute(text(f"TRUNCATE TABLE {table_name}"))
for _ in range(1000):
insert = test_replication_key_table.insert().values(
updated_at=fake.date_between(date1, date2), name=fake.name()
Expand All @@ -61,7 +61,7 @@ def setup_test_table(table_name, sqlalchemy_url):
def teardown_test_table(table_name, sqlalchemy_url):
engine = sqlalchemy.create_engine(sqlalchemy_url)
with engine.connect() as conn:
conn.execute(f"DROP TABLE {table_name}")
conn.execute(text(f"DROP TABLE {table_name}"))


custom_test_replication_key = suites.TestSuite(
Expand Down Expand Up @@ -137,6 +137,7 @@ def test_temporal_datatypes():
"""
table_name = "test_date"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
inspector = sqlalchemy.inspect(engine)

metadata_obj = MetaData()
table = Table(
Expand All @@ -147,7 +148,7 @@ def test_temporal_datatypes():
Column("column_timestamp", TIMESTAMP),
)
with engine.connect() as conn:
if table.exists(conn):
if inspector.has_table(table_name=table_name):
table.drop(conn)
metadata_obj.create_all(conn)
insert = table.insert().values(
Expand Down Expand Up @@ -197,6 +198,7 @@ def test_jsonb_json():
"""JSONB and JSON Objects weren't being selected, make sure they are now"""
table_name = "test_jsonb_json"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
inspector = sqlalchemy.inspect(engine)

metadata_obj = MetaData()
table = Table(
Expand All @@ -206,7 +208,7 @@ def test_jsonb_json():
Column("column_json", JSON),
)
with engine.connect() as conn:
if table.exists(conn):
if inspector.has_table(table_name=table_name):
table.drop(conn)
metadata_obj.create_all(conn)
insert = table.insert().values(
Expand Down Expand Up @@ -248,6 +250,7 @@ def test_decimal():
"""Schema was wrong for Decimal objects. Check they are correctly selected."""
table_name = "test_decimal"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
inspector = sqlalchemy.inspect(engine)

metadata_obj = MetaData()
table = Table(
Expand All @@ -256,7 +259,7 @@ def test_decimal():
Column("column", Numeric()),
)
with engine.connect() as conn:
if table.exists(conn):
if inspector.has_table(table_name=table_name):
table.drop(conn)
metadata_obj.create_all(conn)
insert = table.insert().values(column=decimal.Decimal("3.14"))
Expand Down