comdab 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. comdab-0.2.0/.readthedocs.yaml +9 -0
  2. comdab-0.2.0/CHANGELOG.md +25 -0
  3. comdab-0.1.0/README.md → comdab-0.2.0/PKG-INFO +31 -2
  4. comdab-0.1.0/PKG-INFO → comdab-0.2.0/README.md +8 -12
  5. {comdab-0.1.0 → comdab-0.2.0}/docs/conf.py +12 -4
  6. {comdab-0.1.0 → comdab-0.2.0}/docs/index.rst +1 -1
  7. comdab-0.2.0/pyproject.toml +46 -0
  8. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/compare.py +37 -42
  9. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/postgresql/exclude_constraints.py +3 -6
  10. {comdab-0.1.0 → comdab-0.2.0}/tests/test_compare.py +5 -1
  11. {comdab-0.1.0 → comdab-0.2.0}/uv.lock +220 -219
  12. comdab-0.1.0/pyproject.toml +0 -29
  13. {comdab-0.1.0 → comdab-0.2.0}/.github/workflows/release.yml +0 -0
  14. {comdab-0.1.0 → comdab-0.2.0}/.github/workflows/test.yml +0 -0
  15. {comdab-0.1.0 → comdab-0.2.0}/.gitignore +0 -0
  16. {comdab-0.1.0 → comdab-0.2.0}/.pre-commit-config.yaml +0 -0
  17. {comdab-0.1.0 → comdab-0.2.0}/.python-version +0 -0
  18. {comdab-0.1.0 → comdab-0.2.0}/LICENSE +0 -0
  19. {comdab-0.1.0 → comdab-0.2.0}/docs/Makefile +0 -0
  20. {comdab-0.1.0 → comdab-0.2.0}/docs/reference.rst +0 -0
  21. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/__init__.py +0 -0
  22. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/build.py +0 -0
  23. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/exceptions.py +0 -0
  24. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/main.py +0 -0
  25. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/__init__.py +0 -0
  26. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/base.py +0 -0
  27. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/column.py +0 -0
  28. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/constraint.py +0 -0
  29. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/function.py +0 -0
  30. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/index.py +0 -0
  31. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/schema.py +0 -0
  32. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/sequence.py +0 -0
  33. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/table.py +0 -0
  34. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/trigger.py +0 -0
  35. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/type.py +0 -0
  36. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/models/view.py +0 -0
  37. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/path.py +0 -0
  38. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/py.typed +0 -0
  39. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/report.py +0 -0
  40. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/source.py +0 -0
  41. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/__init__.py +0 -0
  42. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/postgresql/__init__.py +0 -0
  43. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/postgresql/build.py +0 -0
  44. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/postgresql/functions.py +0 -0
  45. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/postgresql/sequences.py +0 -0
  46. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/postgresql/triggers.py +0 -0
  47. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/specific/postgresql/views.py +0 -0
  48. {comdab-0.1.0 → comdab-0.2.0}/src/comdab/utils.py +0 -0
  49. {comdab-0.1.0 → comdab-0.2.0}/tests/__init__.py +0 -0
  50. {comdab-0.1.0 → comdab-0.2.0}/tests/_mock_module.py +0 -0
  51. {comdab-0.1.0 → comdab-0.2.0}/tests/conftest.py +0 -0
  52. {comdab-0.1.0 → comdab-0.2.0}/tests/test_build.py +0 -0
  53. {comdab-0.1.0 → comdab-0.2.0}/tests/test_main.py +0 -0
  54. {comdab-0.1.0 → comdab-0.2.0}/tests/test_models.py +0 -0
  55. {comdab-0.1.0 → comdab-0.2.0}/tests/test_specific/__init__.py +0 -0
  56. {comdab-0.1.0 → comdab-0.2.0}/tests/test_specific/test_postgresql.py +0 -0
  57. {comdab-0.1.0 → comdab-0.2.0}/tests/test_utils.py +0 -0
@@ -0,0 +1,9 @@
1
+ version: 2
2
+
3
+ build:
4
+ os: ubuntu-24.04
5
+ tools:
6
+ python: "3.13"
7
+
8
+ sphinx:
9
+ configuration: docs/conf.py
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2025-07-23
9
+
10
+ ### Changed
11
+
12
+ - Ignore rules aimed at specific dictionary key(s) now also apply to matching keys that are only in the left
13
+ or only in the right dictionaries, in addition to `.left_only` / `.right_only` rules
14
+
15
+ ### Fixed
16
+
17
+ - PostgreSQL exclude constraints attributes and operators were sometime mixed
18
+
19
+ ## [0.1.1] - 2025-06-22
20
+
21
+ - Fixed PyPI metadata and other non-code changes
22
+
23
+ ## [0.1.0] - 2025-06-22
24
+
25
+ Initial version
@@ -1,5 +1,34 @@
1
+ Metadata-Version: 2.4
2
+ Name: comdab
3
+ Version: 0.2.0
4
+ Summary: Compare Database Schemas
5
+ Project-URL: Homepage, https://github.com/loic-simon/comdab
6
+ Project-URL: Documentation, https://comdab.readthedocs.io/en/latest
7
+ Project-URL: Repository, https://github.com/loic-simon/comdab
8
+ Project-URL: Issues, https://github.com/loic-simon/comdab/issues
9
+ Author-email: Loïc Simon <loic.simon@espci.org>
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Database
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: pydantic>=2.0
21
+ Requires-Dist: sqlalchemy>=2.0
22
+ Description-Content-Type: text/markdown
23
+
1
24
  # comdab — Compare Database Schemas
2
25
 
26
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comdab)](https://pypi.org/p/comdab)
27
+ [![PyPI - Version](https://img.shields.io/pypi/v/comdab)](https://pypi.org/p/comdab)
28
+ [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/loic-simon/comdab/test.yml?label=tests)](https://github.com/loic-simon/comdab/actions/workflows/test.yml)
29
+ [![Read the Docs](https://img.shields.io/readthedocs/comdab)](https://comdab.readthedocs.io)
30
+ ![PyPI - Types](https://img.shields.io/pypi/types/comdab)
31
+
3
32
  _comdab_ allows you to compare in depth two database schemas to find
4
33
  all differences: missing columns, different nullabilities or defaults,
5
34
  slight changes in function or triggers definitions...
@@ -64,7 +93,7 @@ else:
64
93
  print("✅ Database schemas are the same!")
65
94
  ```
66
95
 
67
- See documentation for configuration and other details.
96
+ See [documentation](https://comdab.readthedocs.io) for configuration and other details.
68
97
 
69
98
  ## Contributing
70
99
 
@@ -72,6 +101,6 @@ Issues and pull requests are welcome!
72
101
 
73
102
  ## License
74
103
 
75
- This work is shared under [the MIT license](LICENSE);
104
+ This work is shared under [the MIT license](LICENSE).
76
105
 
77
106
  @ 2025 Loïc Simon ([loic.simon@espci.org](mailto:loic.simon@espci.org))
@@ -1,15 +1,11 @@
1
- Metadata-Version: 2.4
2
- Name: comdab
3
- Version: 0.1.0
4
- Summary: Compare Database Schemas
5
- License-File: LICENSE
6
- Requires-Python: >=3.12
7
- Requires-Dist: pydantic>=2.0
8
- Requires-Dist: sqlalchemy>=2.0
9
- Description-Content-Type: text/markdown
10
-
11
1
  # comdab — Compare Database Schemas
12
2
 
3
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comdab)](https://pypi.org/p/comdab)
4
+ [![PyPI - Version](https://img.shields.io/pypi/v/comdab)](https://pypi.org/p/comdab)
5
+ [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/loic-simon/comdab/test.yml?label=tests)](https://github.com/loic-simon/comdab/actions/workflows/test.yml)
6
+ [![Read the Docs](https://img.shields.io/readthedocs/comdab)](https://comdab.readthedocs.io)
7
+ ![PyPI - Types](https://img.shields.io/pypi/types/comdab)
8
+
13
9
  _comdab_ allows you to compare in depth two database schemas to find
14
10
  all differences: missing columns, different nullabilities or defaults,
15
11
  slight changes in function or triggers definitions...
@@ -74,7 +70,7 @@ else:
74
70
  print("✅ Database schemas are the same!")
75
71
  ```
76
72
 
77
- See documentation for configuration and other details.
73
+ See [documentation](https://comdab.readthedocs.io) for configuration and other details.
78
74
 
79
75
  ## Contributing
80
76
 
@@ -82,6 +78,6 @@ Issues and pull requests are welcome!
82
78
 
83
79
  ## License
84
80
 
85
- This work is shared under [the MIT license](LICENSE);
81
+ This work is shared under [the MIT license](LICENSE).
86
82
 
87
83
  @ 2025 Loïc Simon ([loic.simon@espci.org](mailto:loic.simon@espci.org))
@@ -6,10 +6,18 @@
6
6
  # -- Project information -----------------------------------------------------
7
7
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
8
 
9
- project = "comdab"
10
- copyright = "2025, Loïc Simon"
11
- author = "Loïc Simon"
12
- release = "0.1.0"
9
+ import tomllib
10
+ from datetime import date
11
+ from pathlib import Path
12
+
13
+ REPO_ROOT = Path(__file__).parent.parent
14
+ with open(REPO_ROOT / "pyproject.toml", "rb") as fh:
15
+ pyproject = tomllib.load(fh)
16
+
17
+ project = pyproject["project"]["name"]
18
+ author = pyproject["project"]["authors"][0]["name"]
19
+ copyright = f"{date.today().year}, {author}"
20
+ release = pyproject["project"]["version"]
13
21
 
14
22
  # -- General configuration ---------------------------------------------------
15
23
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -158,7 +158,7 @@ may override a more general exclusion:
158
158
  ROOT.tables[...].columns.right_only: "warning",
159
159
  }
160
160
 
161
- Rules can use regular expressions, but two rules *cannot* match the same tables:
161
+ Rules can use regular expressions, but two rules *cannot* match a same object:
162
162
  if you want to say "every tables but ``foo``", use ``(?!foo$).*``.
163
163
 
164
164
 
@@ -0,0 +1,46 @@
1
+ [project]
2
+ name = "comdab"
3
+ version = "0.2.0"
4
+ description = "Compare Database Schemas"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = ["pydantic>=2.0", "sqlalchemy>=2.0"]
8
+ authors = [{ name = "Loïc Simon", email = "loic.simon@espci.org" }]
9
+ classifiers = [
10
+ "Development Status :: 4 - Beta",
11
+ "Intended Audience :: Developers",
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Programming Language :: Python :: 3.13",
15
+ "Programming Language :: Python :: 3.14",
16
+ "Typing :: Typed",
17
+ "Topic :: Database"
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/loic-simon/comdab"
22
+ Documentation = "https://comdab.readthedocs.io/en/latest"
23
+ Repository = "https://github.com/loic-simon/comdab"
24
+ Issues = "https://github.com/loic-simon/comdab/issues"
25
+
26
+ [build-system]
27
+ requires = ["hatchling >= 1.26"]
28
+ build-backend = "hatchling.build"
29
+
30
+ [tool.uv]
31
+ dev-dependencies = [
32
+ "psycopg2>=2.9.10",
33
+ "pytest>=8.4.0",
34
+ "ruff>=0.11.11",
35
+ "sphinx>=8.2.3",
36
+ ]
37
+
38
+ [tool.ruff]
39
+ line-length = 120
40
+
41
+ [tool.pyright]
42
+ typeCheckingMode = "strict"
43
+ venvPath = "."
44
+ venv = ".venv"
45
+ reportUnknownArgumentType = false
46
+ reportUnknownMemberType = false
@@ -117,63 +117,58 @@ class ComdabComparer:
117
117
  left_dict = cast(dict[str, Any], left_attr)
118
118
  right_dict = cast(dict[str, Any], right_attr)
119
119
 
120
- # Use lists instead of sets for consistent reporting order
121
- left_only = [key for key in left_dict if key not in right_dict]
122
- right_only = [key for key in right_dict if key not in left_dict]
123
- both = [key for key in left_dict if key in right_dict]
120
+ all_keys = sorted(left_dict | right_dict)
124
121
  key_depth = field_depth + 1
125
122
 
126
- if left_only:
127
- # Keys only in left dict: apply special rule, else field rule
128
- left_only_crule = next(
129
- (rule for rule in field_prules if rule.get_attr_component(key_depth) == "left_only"),
130
- field_crule,
131
- )
132
- if left_only_crule.strategy != "ignore":
133
- for key in left_only:
123
+ left_only_crule = next(
124
+ (rule for rule in field_prules if rule.get_attr_component(key_depth) == "left_only"), None
125
+ )
126
+ right_only_crule = next(
127
+ (rule for rule in field_prules if rule.get_attr_component(key_depth) == "right_only"), None
128
+ )
129
+
130
+ for key in all_keys:
131
+ # Key in both dicts: compare, using the matching rule, else field rule
132
+ key_prules = [rule for rule in field_prules if _regex_applies(rule.get_item_component(key_depth), key)]
133
+ key_crules = [rule for rule in key_prules if rule.applies_to(key_depth)]
134
+ if len(key_crules) > 1:
135
+ raise OverlappingPathsError(
136
+ f"The key {key!r} matches more than one regex: "
137
+ f"{', '.join(r.get_item_component(key_depth) or '?' for r in key_crules)}"
138
+ )
139
+ key_crule = key_crules[0] if key_crules else None
140
+
141
+ if key not in right_dict:
142
+ # Keys only in left dict: apply special rule, else the rule matching the key, else field rule
143
+ key_crule = left_only_crule or key_crule or field_crule
144
+ if key_crule.strategy != "ignore":
134
145
  yield ComdabReport(
135
- level=left_only_crule.strategy,
146
+ level=key_crule.strategy,
136
147
  path=field_path.left_only,
137
148
  left={key: left_dict[key]},
138
149
  right={},
139
150
  )
140
151
 
141
- if right_only:
142
- # Keys only in right dict: apply special rule, else field rule
143
- right_only_crule = next(
144
- (rule for rule in field_prules if rule.get_attr_component(key_depth) == "right_only"),
145
- field_crule,
146
- )
147
- if right_only_crule.strategy != "ignore":
148
- for key in right_only:
152
+ elif key not in left_dict:
153
+ # Keys only in right dict: apply special rule, else the rule matching the key, else field rule
154
+ key_crule = right_only_crule or key_crule or field_crule
155
+ if key_crule.strategy != "ignore":
149
156
  yield ComdabReport(
150
- level=right_only_crule.strategy,
157
+ level=key_crule.strategy,
151
158
  path=field_path.right_only,
152
159
  left={},
153
160
  right={key: right_dict[key]},
154
161
  )
155
162
 
156
- for key in both:
157
- # Key in both dicts: compare, using the matching rule, else field rule
158
- key_prules = [rule for rule in field_prules if _regex_applies(rule.get_item_component(key_depth), key)]
159
- key_crules = [rule for rule in key_prules if rule.applies_to(key_depth)]
160
- if len(key_crules) > 1:
161
- raise OverlappingPathsError(
162
- f"The key {key!r} matches more than one regex: "
163
- f"{', '.join(r.get_item_component(key_depth) or '?' for r in key_crules)}"
164
- )
165
- elif key_crules:
166
- key_crule = key_crules[0]
167
163
  else:
168
- key_crule = field_crule
169
-
170
- yield from self._compare(
171
- left_dict[key],
172
- right_dict[key],
173
- path=field_path[key],
174
- crule=key_crule,
175
- prules=key_prules,
176
- )
164
+ # Key in both dicts: compare, using the matching rule, else field rule
165
+ yield from self._compare(
166
+ left_dict[key],
167
+ right_dict[key],
168
+ path=field_path[key],
169
+ crule=key_crule or field_crule,
170
+ prules=key_prules,
171
+ )
177
172
 
178
173
 
179
174
  def _regex_applies(pattern: str | None, key: str) -> bool:
@@ -41,13 +41,10 @@ _EXCLUDE_CONSTRAINTS_QUERY = typed_sql[_ExcludeConstraintsQuery](
41
41
  GROUP BY con2.oid, ind.indexrelid, am.oid
42
42
  ) ix_info ON ix_info.oid = con.oid
43
43
  JOIN (
44
- SELECT con3.oid, ARRAY_AGG(opr.oprname) AS operators
44
+ SELECT con3.oid, ARRAY_AGG(opr.oprname ORDER BY opnum ASC) AS operators
45
45
  FROM pg_catalog.pg_constraint con3
46
- JOIN (
47
- SELECT con4.oid, unnest(con4.conexclop) as opid -- Unnest constraint operators
48
- FROM pg_catalog.pg_constraint con4
49
- ) con_ops ON con_ops.oid = con3.oid
50
- JOIN pg_operator opr ON opr.oid = con_ops.opid -- Operator info
46
+ JOIN unnest(con3.conexclop) WITH ORDINALITY AS t(opid, opnum) ON true -- Constraint operators for each column
47
+ JOIN pg_operator opr ON opr.oid = opid -- Operator info
51
48
  GROUP BY con3.oid
52
49
  ) op_info ON op_info.oid = con.oid
53
50
  WHERE nsp.nspname = :schema_name
@@ -289,9 +289,13 @@ def test_rules_empty_vs_full() -> None:
289
289
  ComdabReport("error", ROOT.views.right_only, {}, {"_table1_mat": FULL_SCHEMA.views["_table1_mat"]}),
290
290
  ]
291
291
  assert _test({ROOT.tables["table1"]: "warning"})[:2] == [
292
- ComdabReport("error", ROOT.tables.right_only, {}, {"table1": FULL_SCHEMA.tables["table1"]}),
292
+ ComdabReport("warning", ROOT.tables.right_only, {}, {"table1": FULL_SCHEMA.tables["table1"]}),
293
293
  ComdabReport("error", ROOT.tables.right_only, {}, {"table2": FULL_SCHEMA.tables["table2"]}),
294
294
  ]
295
+ assert _test({ROOT.tables[".+2"]: "warning"})[:2] == [
296
+ ComdabReport("error", ROOT.tables.right_only, {}, {"table1": FULL_SCHEMA.tables["table1"]}),
297
+ ComdabReport("warning", ROOT.tables.right_only, {}, {"table2": FULL_SCHEMA.tables["table2"]}),
298
+ ]
295
299
 
296
300
  # just to test left_only too
297
301
  assert ComdabComparer(rules={ROOT.tables.left_only: "warning"}).compare(FULL_SCHEMA, EMPTY_SCHEMA)[:2] == [