comdab 0.1.1__tar.gz → 0.2.1__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 (56) hide show
  1. comdab-0.2.1/CHANGELOG.md +31 -0
  2. {comdab-0.1.1 → comdab-0.2.1}/PKG-INFO +7 -7
  3. {comdab-0.1.1 → comdab-0.2.1}/README.md +6 -6
  4. {comdab-0.1.1 → comdab-0.2.1}/docs/index.rst +1 -1
  5. {comdab-0.1.1 → comdab-0.2.1}/pyproject.toml +1 -1
  6. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/build.py +3 -0
  7. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/compare.py +37 -42
  8. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/postgresql/exclude_constraints.py +3 -6
  9. {comdab-0.1.1 → comdab-0.2.1}/tests/test_compare.py +5 -1
  10. {comdab-0.1.1 → comdab-0.2.1}/tests/test_specific/test_postgresql.py +31 -0
  11. {comdab-0.1.1 → comdab-0.2.1}/uv.lock +1 -1
  12. {comdab-0.1.1 → comdab-0.2.1}/.github/workflows/release.yml +0 -0
  13. {comdab-0.1.1 → comdab-0.2.1}/.github/workflows/test.yml +0 -0
  14. {comdab-0.1.1 → comdab-0.2.1}/.gitignore +0 -0
  15. {comdab-0.1.1 → comdab-0.2.1}/.pre-commit-config.yaml +0 -0
  16. {comdab-0.1.1 → comdab-0.2.1}/.python-version +0 -0
  17. {comdab-0.1.1 → comdab-0.2.1}/.readthedocs.yaml +0 -0
  18. {comdab-0.1.1 → comdab-0.2.1}/LICENSE +0 -0
  19. {comdab-0.1.1 → comdab-0.2.1}/docs/Makefile +0 -0
  20. {comdab-0.1.1 → comdab-0.2.1}/docs/conf.py +0 -0
  21. {comdab-0.1.1 → comdab-0.2.1}/docs/reference.rst +0 -0
  22. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/__init__.py +0 -0
  23. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/exceptions.py +0 -0
  24. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/main.py +0 -0
  25. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/__init__.py +0 -0
  26. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/base.py +0 -0
  27. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/column.py +0 -0
  28. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/constraint.py +0 -0
  29. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/function.py +0 -0
  30. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/index.py +0 -0
  31. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/schema.py +0 -0
  32. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/sequence.py +0 -0
  33. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/table.py +0 -0
  34. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/trigger.py +0 -0
  35. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/type.py +0 -0
  36. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/models/view.py +0 -0
  37. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/path.py +0 -0
  38. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/py.typed +0 -0
  39. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/report.py +0 -0
  40. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/source.py +0 -0
  41. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/__init__.py +0 -0
  42. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/postgresql/__init__.py +0 -0
  43. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/postgresql/build.py +0 -0
  44. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/postgresql/functions.py +0 -0
  45. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/postgresql/sequences.py +0 -0
  46. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/postgresql/triggers.py +0 -0
  47. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/specific/postgresql/views.py +0 -0
  48. {comdab-0.1.1 → comdab-0.2.1}/src/comdab/utils.py +0 -0
  49. {comdab-0.1.1 → comdab-0.2.1}/tests/__init__.py +0 -0
  50. {comdab-0.1.1 → comdab-0.2.1}/tests/_mock_module.py +0 -0
  51. {comdab-0.1.1 → comdab-0.2.1}/tests/conftest.py +0 -0
  52. {comdab-0.1.1 → comdab-0.2.1}/tests/test_build.py +0 -0
  53. {comdab-0.1.1 → comdab-0.2.1}/tests/test_main.py +0 -0
  54. {comdab-0.1.1 → comdab-0.2.1}/tests/test_models.py +0 -0
  55. {comdab-0.1.1 → comdab-0.2.1}/tests/test_specific/__init__.py +0 -0
  56. {comdab-0.1.1 → comdab-0.2.1}/tests/test_utils.py +0 -0
@@ -0,0 +1,31 @@
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.1] - 2025-08-06
9
+
10
+ ### Fixed
11
+
12
+ - Fix crash when reflecting tables without a primary key
13
+
14
+ ## [0.2.0] - 2025-07-23
15
+
16
+ ### Changed
17
+
18
+ - Ignore rules aimed at specific dictionary key(s) now also apply to matching keys that are only in the left
19
+ or only in the right dictionaries, in addition to `.left_only` / `.right_only` rules
20
+
21
+ ### Fixed
22
+
23
+ - PostgreSQL exclude constraints attributes and operators were sometime mixed
24
+
25
+ ## [0.1.1] - 2025-06-22
26
+
27
+ - Fixed PyPI metadata and other non-code changes
28
+
29
+ ## [0.1.0] - 2025-06-22
30
+
31
+ Initial version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: comdab
3
- Version: 0.1.1
3
+ Version: 0.2.1
4
4
  Summary: Compare Database Schemas
5
5
  Project-URL: Homepage, https://github.com/loic-simon/comdab
6
6
  Project-URL: Documentation, https://comdab.readthedocs.io/en/latest
@@ -23,10 +23,10 @@ Description-Content-Type: text/markdown
23
23
 
24
24
  # comdab — Compare Database Schemas
25
25
 
26
- ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comdab)
27
- ![PyPI - Version](https://img.shields.io/pypi/v/comdab)
28
- ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/loic-simon/comdab/test.yml?label=tests)
29
- ![Read the Docs](https://img.shields.io/readthedocs/comdab)
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
30
  ![PyPI - Types](https://img.shields.io/pypi/types/comdab)
31
31
 
32
32
  _comdab_ allows you to compare in depth two database schemas to find
@@ -93,7 +93,7 @@ else:
93
93
  print("✅ Database schemas are the same!")
94
94
  ```
95
95
 
96
- See documentation for configuration and other details.
96
+ See [documentation](https://comdab.readthedocs.io) for configuration and other details.
97
97
 
98
98
  ## Contributing
99
99
 
@@ -101,6 +101,6 @@ Issues and pull requests are welcome!
101
101
 
102
102
  ## License
103
103
 
104
- This work is shared under [the MIT license](LICENSE);
104
+ This work is shared under [the MIT license](LICENSE).
105
105
 
106
106
  @ 2025 Loïc Simon ([loic.simon@espci.org](mailto:loic.simon@espci.org))
@@ -1,9 +1,9 @@
1
1
  # comdab — Compare Database Schemas
2
2
 
3
- ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/comdab)
4
- ![PyPI - Version](https://img.shields.io/pypi/v/comdab)
5
- ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/loic-simon/comdab/test.yml?label=tests)
6
- ![Read the Docs](https://img.shields.io/readthedocs/comdab)
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
7
  ![PyPI - Types](https://img.shields.io/pypi/types/comdab)
8
8
 
9
9
  _comdab_ allows you to compare in depth two database schemas to find
@@ -70,7 +70,7 @@ else:
70
70
  print("✅ Database schemas are the same!")
71
71
  ```
72
72
 
73
- See documentation for configuration and other details.
73
+ See [documentation](https://comdab.readthedocs.io) for configuration and other details.
74
74
 
75
75
  ## Contributing
76
76
 
@@ -78,6 +78,6 @@ Issues and pull requests are welcome!
78
78
 
79
79
  ## License
80
80
 
81
- This work is shared under [the MIT license](LICENSE);
81
+ This work is shared under [the MIT license](LICENSE).
82
82
 
83
83
  @ 2025 Loïc Simon ([loic.simon@espci.org](mailto:loic.simon@espci.org))
@@ -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
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "comdab"
3
- version = "0.1.1"
3
+ version = "0.2.1"
4
4
  description = "Compare Database Schemas"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -93,6 +93,9 @@ class ComdabBuilder:
93
93
 
94
94
  def generate_constraints(self, sa_table: schema.Table) -> Iterator[ComdabConstraint]:
95
95
  for sa_constraint in sa_table.constraints:
96
+ if isinstance(sa_constraint, schema.PrimaryKeyConstraint) and not sa_constraint.columns:
97
+ # Non-existing constraint created because SQLAlchemy needs a primary key per table: ignore
98
+ continue
96
99
  yield self.build_constraint(sa_constraint)
97
100
 
98
101
  def generate_indexes(self, sa_table: schema.Table) -> Iterator[ComdabIndex]:
@@ -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] == [
@@ -844,3 +844,34 @@ def test_psql_types(connection: Connection, meta: MetaData) -> None:
844
844
  },
845
845
  functions={},
846
846
  )
847
+
848
+
849
+ def test_no_primary_key_ignore_fake_constraint(connection: Connection) -> None:
850
+ # Not really psql-specific, but needs a DB
851
+
852
+ connection.exec_driver_sql("CREATE TABLE table_1 (id INTEGER);") # no primary key
853
+
854
+ builder = ComdabPostgreSQLBuilder(ComdabSource(connection=connection, schema_name="public"))
855
+ assert builder.build_schema() == ComdabSchema(
856
+ tables={
857
+ "table_1": ComdabTable(
858
+ name="table_1",
859
+ columns={
860
+ "id": ComdabColumn(
861
+ name="id",
862
+ type=ComdabTypes.Integer(implem_name="INTEGER"),
863
+ nullable=True,
864
+ default=None,
865
+ generation_expression=None,
866
+ ),
867
+ },
868
+ constraints={},
869
+ indexes={},
870
+ triggers={},
871
+ extra={},
872
+ ),
873
+ },
874
+ views={},
875
+ sequences={},
876
+ functions={},
877
+ )
@@ -84,7 +84,7 @@ wheels = [
84
84
 
85
85
  [[package]]
86
86
  name = "comdab"
87
- version = "0.1.1"
87
+ version = "0.2.1"
88
88
  source = { editable = "." }
89
89
  dependencies = [
90
90
  { name = "pydantic" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes