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
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ jobs:
- name: Install package and test dependencies
run: pip install -e ".[all]" pytest pytest-cov
- name: Run unit + cli tests
run: pytest tests/unit tests/cli --cov=db2sql --cov-fail-under=80
run: pytest tests/unit tests/cli --cov=db2sql --cov-report=xml --cov-report=term --cov-fail-under=80
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: false

docs:
name: Build documentation
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 26.3.1
hooks:
- id: black
- repo: https://github.com/commitizen-tools/commitizen
Expand Down
20 changes: 20 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
coverage:
status:
project:
default:
target: auto
threshold: 1%
patch:
default:
target: 80%
threshold: 0%

comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false

ignore:
- "tests/**"
- "docs/**"
- "installer/**"
64 changes: 16 additions & 48 deletions db2sql/infrastructure/persistence/mssql/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def iter_query_rows(self, query: str, limit: int = -1) -> Iterator[Tuple[Any, ..

def _read_schemas(self, database: Database) -> None:
try:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT SCHEMA_NAME
FROM
INFORMATION_SCHEMA.SCHEMATA s
Expand All @@ -95,19 +93,15 @@ def _read_schemas(self, database: Database) -> None:
)
ORDER BY
SCHEMA_NAME
"""
)
)
"""))
except Exception as exc:
raise SourceReaderError(f"Error connecting to database {exc}") from exc

for row in r:
database.add_schema(Schema(row.SCHEMA_NAME))

def _read_tables(self, database: Database) -> None:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT TABLE_SCHEMA, TABLE_NAME
FROM
information_schema.tables
Expand All @@ -116,16 +110,12 @@ def _read_tables(self, database: Database) -> None:
AND TABLE_NAME NOT IN ('dtproperties', 'sysdiagrams')
ORDER BY
TABLE_SCHEMA, TABLE_NAME
"""
)
)
"""))
for row in r:
database.add_table(row.TABLE_SCHEMA, Table(row.TABLE_NAME))

def _read_columns(self, database: Database) -> None:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT
TABLE_SCHEMA,
TABLE_NAME,
Expand All @@ -140,9 +130,7 @@ def _read_columns(self, database: Database) -> None:
INFORMATION_SCHEMA.COLUMNS
ORDER BY
TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION
"""
)
)
"""))

for row in r:
table = database.get_table(row.TABLE_SCHEMA, row.TABLE_NAME)
Expand All @@ -160,18 +148,14 @@ def _read_columns(self, database: Database) -> None:
)

def _read_computed_columns(self, database: Database) -> None:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT S.NAME TABLE_SCHEMA, T.NAME TABLE_NAME, C.NAME COLUMN_NAME, C.DEFINITION
FROM SYS.COMPUTED_COLUMNS C
INNER JOIN SYS.TABLES T
ON T.OBJECT_ID = C.OBJECT_ID
INNER JOIN SYS.SCHEMAS S
ON S.SCHEMA_ID = T.SCHEMA_ID
"""
)
)
"""))

for row in r:
table = database.get_table(row.TABLE_SCHEMA, row.TABLE_NAME)
Expand All @@ -181,9 +165,7 @@ def _read_computed_columns(self, database: Database) -> None:
column.computed_definition = row.DEFINITION

def _read_identity_columns(self, database: Database) -> None:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT s.name TABLE_SCHEMA,
o.name TABLE_NAME,
c.name COLUMN_NAME
Expand All @@ -194,9 +176,7 @@ def _read_identity_columns(self, database: Database) -> None:
ON o.schema_id = s.schema_id
WHERE s.name NOT IN ('sys')
ORDER BY 1, 2, 3
"""
)
)
"""))

for row in r:
table = database.get_table(row.TABLE_SCHEMA, row.TABLE_NAME)
Expand All @@ -206,18 +186,14 @@ def _read_identity_columns(self, database: Database) -> None:
column.identity = True

def _read_column_constraints(self, database: Database) -> None:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT u.TABLE_SCHEMA, u.TABLE_NAME, u.COLUMN_NAME, c.CONSTRAINT_TYPE
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE u
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
ON c.CONSTRAINT_NAME = u.CONSTRAINT_NAME
AND c.CONSTRAINT_SCHEMA = u.CONSTRAINT_SCHEMA
WHERE c.CONSTRAINT_TYPE IN ('UNIQUE', 'PRIMARY KEY')
"""
)
)
"""))

for row in r:
table = database.get_table(row.TABLE_SCHEMA, row.TABLE_NAME)
Expand All @@ -227,9 +203,7 @@ def _read_column_constraints(self, database: Database) -> None:
column.constraint = row.CONSTRAINT_TYPE

def _read_foreign_keys(self, database: Database) -> None:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT KCU1.CONSTRAINT_SCHEMA AS CONSTRAINT_SCHEMA,
KCU1.CONSTRAINT_NAME AS CONSTRAINT_NAME,
KCU1.TABLE_SCHEMA AS TABLE_SCHEMA,
Expand All @@ -253,9 +227,7 @@ def _read_foreign_keys(self, database: Database) -> None:
WHERE KCU1.ORDINAL_POSITION = KCU2.ORDINAL_POSITION
AND KCU1.TABLE_SCHEMA not in ('sys', 'guest', 'information_schema')
ORDER BY CONSTRAINT_SCHEMA, CONSTRAINT_NAME
"""
)
)
"""))

for row in r:
table = database.get_table(row.TABLE_SCHEMA, row.TABLE_NAME)
Expand All @@ -269,9 +241,7 @@ def _read_foreign_keys(self, database: Database) -> None:
)

def _read_indexes(self, database: Database) -> None:
r: engine.Result[Any] = self._ensure_session().execute(
text(
"""
r: engine.Result[Any] = self._ensure_session().execute(text("""
SELECT sch.name as TABLE_SCHEMA,
t.name as TABLE_NAME,
ind.name as INDEX_NAME,
Expand All @@ -295,9 +265,7 @@ def _read_indexes(self, database: Database) -> None:
AND t.is_ms_shipped = 0
AND sch.name not in ('sys', 'guest', 'information_schema')
ORDER BY t.name, ind.name, ind.index_id, ic.index_column_id
"""
)
)
"""))

for row in r:
table = database.get_table(row.TABLE_SCHEMA, row.TABLE_NAME)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ repository = "http://github.com/sismicfr/python-db2sql.git"

[tool.black]
line-length = 100
target-version = ["py39"]

[flake8]
exclude = [".git",".venv",".tox","dist","docs","*egg,build"]
Expand Down
2 changes: 1 addition & 1 deletion requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
build==1.2.1
black==24.10.0
black==26.3.1
commitizen==3.31.0
flake8==7.1.1
import-linter==2.1
Expand Down
Loading