comdab 0.2.0__tar.gz → 0.3.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 (58) hide show
  1. {comdab-0.2.0 → comdab-0.3.0}/CHANGELOG.md +13 -0
  2. {comdab-0.2.0 → comdab-0.3.0}/PKG-INFO +1 -1
  3. {comdab-0.2.0 → comdab-0.3.0}/docs/index.rst +22 -19
  4. {comdab-0.2.0 → comdab-0.3.0}/pyproject.toml +1 -1
  5. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/build.py +8 -0
  6. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/__init__.py +2 -0
  7. comdab-0.3.0/src/comdab/models/custom_type.py +22 -0
  8. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/schema.py +3 -0
  9. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/postgresql/build.py +6 -0
  10. comdab-0.3.0/src/comdab/specific/postgresql/custom_types.py +40 -0
  11. {comdab-0.2.0 → comdab-0.3.0}/tests/test_build.py +7 -0
  12. {comdab-0.2.0 → comdab-0.3.0}/tests/test_compare.py +16 -0
  13. {comdab-0.2.0 → comdab-0.3.0}/tests/test_specific/test_postgresql.py +129 -0
  14. {comdab-0.2.0 → comdab-0.3.0}/uv.lock +1 -1
  15. {comdab-0.2.0 → comdab-0.3.0}/.github/workflows/release.yml +0 -0
  16. {comdab-0.2.0 → comdab-0.3.0}/.github/workflows/test.yml +0 -0
  17. {comdab-0.2.0 → comdab-0.3.0}/.gitignore +0 -0
  18. {comdab-0.2.0 → comdab-0.3.0}/.pre-commit-config.yaml +0 -0
  19. {comdab-0.2.0 → comdab-0.3.0}/.python-version +0 -0
  20. {comdab-0.2.0 → comdab-0.3.0}/.readthedocs.yaml +0 -0
  21. {comdab-0.2.0 → comdab-0.3.0}/LICENSE +0 -0
  22. {comdab-0.2.0 → comdab-0.3.0}/README.md +0 -0
  23. {comdab-0.2.0 → comdab-0.3.0}/docs/Makefile +0 -0
  24. {comdab-0.2.0 → comdab-0.3.0}/docs/conf.py +0 -0
  25. {comdab-0.2.0 → comdab-0.3.0}/docs/reference.rst +0 -0
  26. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/__init__.py +0 -0
  27. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/compare.py +0 -0
  28. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/exceptions.py +0 -0
  29. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/main.py +0 -0
  30. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/base.py +0 -0
  31. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/column.py +0 -0
  32. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/constraint.py +0 -0
  33. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/function.py +0 -0
  34. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/index.py +0 -0
  35. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/sequence.py +0 -0
  36. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/table.py +0 -0
  37. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/trigger.py +0 -0
  38. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/type.py +0 -0
  39. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/models/view.py +0 -0
  40. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/path.py +0 -0
  41. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/py.typed +0 -0
  42. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/report.py +0 -0
  43. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/source.py +0 -0
  44. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/__init__.py +0 -0
  45. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/postgresql/__init__.py +0 -0
  46. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/postgresql/exclude_constraints.py +0 -0
  47. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/postgresql/functions.py +0 -0
  48. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/postgresql/sequences.py +0 -0
  49. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/postgresql/triggers.py +0 -0
  50. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/specific/postgresql/views.py +0 -0
  51. {comdab-0.2.0 → comdab-0.3.0}/src/comdab/utils.py +0 -0
  52. {comdab-0.2.0 → comdab-0.3.0}/tests/__init__.py +0 -0
  53. {comdab-0.2.0 → comdab-0.3.0}/tests/_mock_module.py +0 -0
  54. {comdab-0.2.0 → comdab-0.3.0}/tests/conftest.py +0 -0
  55. {comdab-0.2.0 → comdab-0.3.0}/tests/test_main.py +0 -0
  56. {comdab-0.2.0 → comdab-0.3.0}/tests/test_models.py +0 -0
  57. {comdab-0.2.0 → comdab-0.3.0}/tests/test_specific/__init__.py +0 -0
  58. {comdab-0.2.0 → comdab-0.3.0}/tests/test_utils.py +0 -0
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.3.0] - 2025-08-12
9
+
10
+ ### Added
11
+
12
+ - PostgreSQL: detect & compare enum types, even if they are unused
13
+ (new model `ComdabCustomType`, in `ROOT.custom_types`)
14
+
15
+ ## [0.2.1] - 2025-08-06
16
+
17
+ ### Fixed
18
+
19
+ - Fix crash when reflecting tables without a primary key
20
+
8
21
  ## [0.2.0] - 2025-07-23
9
22
 
10
23
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: comdab
3
- Version: 0.2.0
3
+ Version: 0.3.0
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
@@ -105,25 +105,27 @@ to retrieve objects not natively handled by SQLALchemy.
105
105
 
106
106
  Top-level schema fields
107
107
 
108
- =========== ========== ====================================================
109
- Object Support Notes
110
- =========== ========== ====================================================
111
- Tables Yes
112
- Views Partial PostgreSQL only (temporary + materialized)
113
- Sequences Partial PostgreSQL only
114
- Functions Partial PostgreSQL only (compares reconstructed definitions)
115
- ----------- ---------- ----------------------------------------------------
116
- Columns Yes
117
- Constraints Partial All databases: PK, FK, unique & check constraints;
118
- PostgreSQL only: exclude constraints
119
- Indexes Yes
120
- Triggers Partial PostgreSQL only (compares reconstructed definitions)
121
- ----------- ---------- ----------------------------------------------------
122
- Column type Partial All SQLALchemy common types;
123
- PostgreSQL only: HSTORE, ranges, multiranges
124
- Owners No No notion of users/roles/permissions...
125
- Comments No
126
- =========== ========== ====================================================
108
+ ============ ========== =====================================================
109
+ Object Support Notes
110
+ ============ ========== =====================================================
111
+ Tables Yes
112
+ Views Partial PostgreSQL only (temporary + materialized)
113
+ Sequences Partial PostgreSQL only
114
+ Functions Partial PostgreSQL only (compares reconstructed definitions)
115
+ Custom types Partial | All databases: enums that are used (in column.type)
116
+ | PostgreSQL only: unused enums
117
+ ------------ ---------- -----------------------------------------------------
118
+ Columns Yes
119
+ Constraints Partial | All databases: PK, FK, unique & check constraints
120
+ | PostgreSQL only: exclude constraints
121
+ Indexes Yes
122
+ Triggers Partial PostgreSQL only (compares reconstructed definitions)
123
+ ------------ ---------- -----------------------------------------------------
124
+ Column type Partial | All databases: `SQLALchemy generic types`_
125
+ | PostgreSQL only: HSTORE, ranges, multiranges
126
+ Owners No No notion of users/roles/permissions...
127
+ Comments No
128
+ ============ ========== =====================================================
127
129
 
128
130
  Each object can hold non-standard / dialect-specific data in a ``extra``
129
131
  dictionary, that will be compared too (unless specifically ignored, see below).
@@ -168,3 +170,4 @@ if you want to say "every tables but ``foo``", use ``(?!foo$).*``.
168
170
  .. _sqla: https://sqlalchemy.org
169
171
  .. _SQLAlchemy connections: https://docs.sqlalchemy.org/en/stable/code/connections.html
170
172
  .. _schema reflection: https://docs.sqlalchemy.org/en/stable/code/reflecion.html
173
+ .. _SQLALchemy generic types: https://docs.sqlalchemy.org/en/stable/core/type_basics.html#generic-camelcase-types
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "comdab"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "Compare Database Schemas"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -13,6 +13,7 @@ from comdab.models.constraint import (
13
13
  ComdabPrimaryKeyConstraint,
14
14
  ComdabUniqueConstraint,
15
15
  )
16
+ from comdab.models.custom_type import ComdabCustomType
16
17
  from comdab.models.function import ComdabFunction
17
18
  from comdab.models.index import ComdabIndex
18
19
  from comdab.models.schema import ComdabSchema
@@ -57,6 +58,7 @@ class ComdabBuilder:
57
58
  views=dict_by_name(self.generate_views(sa_metadata)),
58
59
  sequences=dict_by_name(self.generate_sequences(sa_metadata)),
59
60
  functions=dict_by_name(self.generate_functions(sa_metadata)),
61
+ custom_types=dict_by_name(self.generate_custom_types(sa_metadata)),
60
62
  extra={str(key): val for key, val in sa_metadata.info.items()},
61
63
  )
62
64
 
@@ -85,6 +87,9 @@ class ComdabBuilder:
85
87
  def generate_functions(self, sa_metadata: schema.MetaData) -> Iterator[ComdabFunction]:
86
88
  yield from () # No database-agnostic implementation
87
89
 
90
+ def generate_custom_types(self, sa_metadata: schema.MetaData) -> Iterator[ComdabCustomType]:
91
+ yield from () # No database-agnostic implementation
92
+
88
93
  # Level 2
89
94
 
90
95
  def generate_columns(self, sa_table: schema.Table) -> Iterator[ComdabColumn]:
@@ -93,6 +98,9 @@ class ComdabBuilder:
93
98
 
94
99
  def generate_constraints(self, sa_table: schema.Table) -> Iterator[ComdabConstraint]:
95
100
  for sa_constraint in sa_table.constraints:
101
+ if isinstance(sa_constraint, schema.PrimaryKeyConstraint) and not sa_constraint.columns:
102
+ # Non-existing constraint created because SQLAlchemy needs a primary key per table: ignore
103
+ continue
96
104
  yield self.build_constraint(sa_constraint)
97
105
 
98
106
  def generate_indexes(self, sa_table: schema.Table) -> Iterator[ComdabIndex]:
@@ -6,6 +6,7 @@ from comdab.models.constraint import (
6
6
  ComdabPrimaryKeyConstraint,
7
7
  ComdabUniqueConstraint,
8
8
  )
9
+ from comdab.models.custom_type import ComdabCustomType
9
10
  from comdab.models.function import ComdabFunction
10
11
  from comdab.models.index import ComdabIndex
11
12
  from comdab.models.schema import ROOT, ComdabSchema
@@ -18,6 +19,7 @@ from comdab.models.view import ComdabView
18
19
  __all__ = (
19
20
  "ComdabCheckConstraint",
20
21
  "ComdabColumn",
22
+ "ComdabCustomType",
21
23
  "ComdabExcludeConstraint",
22
24
  "ComdabForeignKeyConstraint",
23
25
  "ComdabFunction",
@@ -0,0 +1,22 @@
1
+ from typing import Any
2
+
3
+ from pydantic import Field
4
+
5
+ from comdab.models.base import ComdabModel
6
+ from comdab.path import ComdabPath, dict_of_paths, terminal_path
7
+
8
+
9
+ class ComdabCustomType(ComdabModel, frozen=True):
10
+ """A database custom type (only Enums supported).
11
+
12
+ Even types not used in any column are listed here.
13
+ """
14
+
15
+ name: str
16
+ values: list[str]
17
+ extra: dict[str, Any] = Field(default_factory=dict)
18
+
19
+ class Path(ComdabPath):
20
+ name = terminal_path()
21
+ values = terminal_path()
22
+ extra = dict_of_paths(ComdabPath)
@@ -3,6 +3,7 @@ from typing import Any
3
3
  from pydantic import Field
4
4
 
5
5
  from comdab.models.base import ComdabModel
6
+ from comdab.models.custom_type import ComdabCustomType
6
7
  from comdab.models.function import ComdabFunction
7
8
  from comdab.models.sequence import ComdabSequence
8
9
  from comdab.models.table import ComdabTable
@@ -20,6 +21,7 @@ class ComdabSchema(ComdabModel, frozen=True):
20
21
  views: dict[str, ComdabView]
21
22
  sequences: dict[str, ComdabSequence]
22
23
  functions: dict[str, ComdabFunction]
24
+ custom_types: dict[str, ComdabCustomType]
23
25
  extra: dict[str, Any] = Field(default_factory=dict)
24
26
 
25
27
  class Path(ComdabPath):
@@ -27,6 +29,7 @@ class ComdabSchema(ComdabModel, frozen=True):
27
29
  views = dict_of_paths(ComdabView.Path)
28
30
  sequences = dict_of_paths(ComdabSequence.Path)
29
31
  functions = dict_of_paths(ComdabFunction.Path)
32
+ custom_types = dict_of_paths(ComdabCustomType.Path)
30
33
  extra = dict_of_paths(ComdabPath)
31
34
 
32
35
 
@@ -8,11 +8,13 @@ from sqlalchemy.dialects.postgresql import HSTORE, ranges
8
8
  from comdab.build import ComdabBuilder
9
9
  from comdab.exceptions import UnhandledTypeError
10
10
  from comdab.models.constraint import ComdabConstraint, ComdabExcludeConstraint
11
+ from comdab.models.custom_type import ComdabCustomType
11
12
  from comdab.models.function import ComdabFunction
12
13
  from comdab.models.sequence import ComdabSequence
13
14
  from comdab.models.trigger import ComdabTrigger
14
15
  from comdab.models.type import ComdabType, ComdabTypes
15
16
  from comdab.models.view import ComdabView
17
+ from comdab.specific.postgresql.custom_types import get_postgresql_custom_types
16
18
  from comdab.specific.postgresql.exclude_constraints import get_postgresql_exclude_constraints_by_table
17
19
  from comdab.specific.postgresql.functions import get_postgresql_functions
18
20
  from comdab.specific.postgresql.sequences import get_postgresql_sequences
@@ -35,6 +37,10 @@ class ComdabPostgreSQLBuilder(ComdabBuilder):
35
37
  yield from super().generate_functions(sa_metadata)
36
38
  yield from get_postgresql_functions(self.source)
37
39
 
40
+ def generate_custom_types(self, sa_metadata: MetaData) -> Iterator[ComdabCustomType]:
41
+ yield from super().generate_custom_types(sa_metadata)
42
+ yield from get_postgresql_custom_types(self.source)
43
+
38
44
  # Level 2
39
45
 
40
46
  @cached_property
@@ -0,0 +1,40 @@
1
+ from typing import NamedTuple
2
+
3
+ from comdab.models.custom_type import ComdabCustomType
4
+ from comdab.source import ComdabSource
5
+ from comdab.utils import typed_sql
6
+
7
+
8
+ class _CustomTypesQuery(NamedTuple):
9
+ typname: str
10
+ values: list[str]
11
+
12
+
13
+ _CUSTOM_TYPES_QUERY = typed_sql[_CustomTypesQuery](
14
+ """--sql
15
+
16
+ SELECT
17
+ typ.typname,
18
+ ARRAY_AGG(enum.enumlabel ORDER BY enum.enumsortorder) AS values
19
+ FROM pg_catalog.pg_type typ -- Type
20
+ JOIN pg_catalog.pg_namespace nsp ON typ.typnamespace = nsp.oid -- Type schema
21
+ LEFT OUTER JOIN pg_catalog.pg_enum enum ON enum.enumtypid = typ.oid -- Enum values
22
+ WHERE nsp.nspname = :schema_name
23
+ AND typ.typtype = 'e' -- TODO: handle other kind of custom types?
24
+ GROUP BY typ.oid;
25
+ """,
26
+ )
27
+
28
+
29
+ def get_postgresql_custom_types(source: ComdabSource) -> list[ComdabCustomType]:
30
+ result = source.connection.execute(
31
+ _CUSTOM_TYPES_QUERY,
32
+ {"schema_name": source.schema_name},
33
+ )
34
+ return [
35
+ ComdabCustomType(
36
+ name=row.typname,
37
+ values=row.values,
38
+ )
39
+ for row in result.t
40
+ ]
@@ -80,6 +80,7 @@ def test_empty_metadata(meta: MetaData) -> None:
80
80
  views={},
81
81
  sequences={},
82
82
  functions={},
83
+ custom_types={},
83
84
  )
84
85
 
85
86
 
@@ -121,6 +122,7 @@ def test_basic(meta: MetaData) -> None:
121
122
  views={},
122
123
  sequences={},
123
124
  functions={},
125
+ custom_types={},
124
126
  extra={"hello": 3, "bye": 2},
125
127
  )
126
128
 
@@ -184,6 +186,7 @@ def test_column_attributes(meta: MetaData) -> None:
184
186
  views={},
185
187
  sequences={},
186
188
  functions={},
189
+ custom_types={},
187
190
  )
188
191
 
189
192
 
@@ -342,6 +345,7 @@ def test_constraints(meta: MetaData) -> None:
342
345
  views={},
343
346
  sequences={},
344
347
  functions={},
348
+ custom_types={},
345
349
  )
346
350
 
347
351
 
@@ -397,6 +401,7 @@ def test_indexes(meta: MetaData) -> None:
397
401
  views={},
398
402
  sequences={},
399
403
  functions={},
404
+ custom_types={},
400
405
  )
401
406
 
402
407
 
@@ -499,6 +504,7 @@ def test_types(meta: MetaData) -> None:
499
504
  views={},
500
505
  sequences={},
501
506
  functions={},
507
+ custom_types={},
502
508
  )
503
509
 
504
510
 
@@ -550,4 +556,5 @@ def test_unknown_types(meta: MetaData) -> None:
550
556
  views={},
551
557
  sequences={},
552
558
  functions={},
559
+ custom_types={},
553
560
  )
@@ -18,6 +18,7 @@ from comdab.models import (
18
18
  ComdabUniqueConstraint,
19
19
  ComdabView,
20
20
  )
21
+ from comdab.models.custom_type import ComdabCustomType
21
22
  from comdab.path import ComdabPath
22
23
  from comdab.report import ComdabReport
23
24
 
@@ -26,6 +27,7 @@ EMPTY_SCHEMA = ComdabSchema(
26
27
  views={},
27
28
  sequences={},
28
29
  functions={},
30
+ custom_types={},
29
31
  )
30
32
 
31
33
  FULL_SCHEMA = ComdabSchema(
@@ -125,6 +127,10 @@ FULL_SCHEMA = ComdabSchema(
125
127
  ),
126
128
  "other_func": ComdabFunction(name="other_func", definition="CREATE OR REPLACE OTHER FUNCTION..."),
127
129
  },
130
+ custom_types={
131
+ "my_enum": ComdabCustomType(name="my_enum", values=["one", "two"]),
132
+ "my_enum_2": ComdabCustomType(name="my_enum_2", values=["Three (3)", "FOUR"]),
133
+ },
128
134
  extra={
129
135
  "extra1": "foo",
130
136
  "extra2": {"key1": True, "key2": False},
@@ -149,6 +155,8 @@ def test_empty_vs_full() -> None:
149
155
  ComdabReport("error", ROOT.sequences.right_only, {}, {"seq2": FULL_SCHEMA.sequences["seq2"]}),
150
156
  ComdabReport("error", ROOT.functions.right_only, {}, {"my_func": FULL_SCHEMA.functions["my_func"]}),
151
157
  ComdabReport("error", ROOT.functions.right_only, {}, {"other_func": FULL_SCHEMA.functions["other_func"]}),
158
+ ComdabReport("error", ROOT.custom_types.right_only, {}, {"my_enum": FULL_SCHEMA.custom_types["my_enum"]}),
159
+ ComdabReport("error", ROOT.custom_types.right_only, {}, {"my_enum_2": FULL_SCHEMA.custom_types["my_enum_2"]}),
152
160
  ComdabReport("error", ROOT.extra.right_only, {}, {"extra1": FULL_SCHEMA.extra["extra1"]}),
153
161
  ComdabReport("error", ROOT.extra.right_only, {}, {"extra2": FULL_SCHEMA.extra["extra2"]}),
154
162
  ]
@@ -161,6 +169,8 @@ def test_empty_vs_full() -> None:
161
169
  ComdabReport("error", ROOT.sequences.left_only, {"seq2": FULL_SCHEMA.sequences["seq2"]}, {}),
162
170
  ComdabReport("error", ROOT.functions.left_only, {"my_func": FULL_SCHEMA.functions["my_func"]}, {}),
163
171
  ComdabReport("error", ROOT.functions.left_only, {"other_func": FULL_SCHEMA.functions["other_func"]}, {}),
172
+ ComdabReport("error", ROOT.custom_types.left_only, {"my_enum": FULL_SCHEMA.custom_types["my_enum"]}, {}),
173
+ ComdabReport("error", ROOT.custom_types.left_only, {"my_enum_2": FULL_SCHEMA.custom_types["my_enum_2"]}, {}),
164
174
  ComdabReport("error", ROOT.extra.left_only, {"extra1": FULL_SCHEMA.extra["extra1"]}, {}),
165
175
  ComdabReport("error", ROOT.extra.left_only, {"extra2": FULL_SCHEMA.extra["extra2"]}, {}),
166
176
  ]
@@ -254,6 +264,8 @@ def test_rules_empty_vs_full() -> None:
254
264
  ComdabReport("error", ROOT.sequences.right_only, {}, {"seq2": FULL_SCHEMA.sequences["seq2"]}),
255
265
  ComdabReport("error", ROOT.functions.right_only, {}, {"my_func": FULL_SCHEMA.functions["my_func"]}),
256
266
  ComdabReport("error", ROOT.functions.right_only, {}, {"other_func": FULL_SCHEMA.functions["other_func"]}),
267
+ ComdabReport("error", ROOT.custom_types.right_only, {}, {"my_enum": FULL_SCHEMA.custom_types["my_enum"]}),
268
+ ComdabReport("error", ROOT.custom_types.right_only, {}, {"my_enum_2": FULL_SCHEMA.custom_types["my_enum_2"]}),
257
269
  ComdabReport("error", ROOT.extra.right_only, {}, {"extra1": FULL_SCHEMA.extra["extra1"]}),
258
270
  ComdabReport("error", ROOT.extra.right_only, {}, {"extra2": FULL_SCHEMA.extra["extra2"]}),
259
271
  ]
@@ -266,6 +278,8 @@ def test_rules_empty_vs_full() -> None:
266
278
  ComdabReport("warning", ROOT.sequences.right_only, {}, {"seq2": FULL_SCHEMA.sequences["seq2"]}),
267
279
  ComdabReport("warning", ROOT.functions.right_only, {}, {"my_func": FULL_SCHEMA.functions["my_func"]}),
268
280
  ComdabReport("warning", ROOT.functions.right_only, {}, {"other_func": FULL_SCHEMA.functions["other_func"]}),
281
+ ComdabReport("warning", ROOT.custom_types.right_only, {}, {"my_enum": FULL_SCHEMA.custom_types["my_enum"]}),
282
+ ComdabReport("warning", ROOT.custom_types.right_only, {}, {"my_enum_2": FULL_SCHEMA.custom_types["my_enum_2"]}),
269
283
  ComdabReport("warning", ROOT.extra.right_only, {}, {"extra1": FULL_SCHEMA.extra["extra1"]}),
270
284
  ComdabReport("warning", ROOT.extra.right_only, {}, {"extra2": FULL_SCHEMA.extra["extra2"]}),
271
285
  ]
@@ -278,6 +292,8 @@ def test_rules_empty_vs_full() -> None:
278
292
  ComdabReport("warning", ROOT.views.right_only, {}, {"_table1_mat": FULL_SCHEMA.views["_table1_mat"]}),
279
293
  ComdabReport("error", ROOT.functions.right_only, {}, {"my_func": FULL_SCHEMA.functions["my_func"]}),
280
294
  ComdabReport("error", ROOT.functions.right_only, {}, {"other_func": FULL_SCHEMA.functions["other_func"]}),
295
+ ComdabReport("error", ROOT.custom_types.right_only, {}, {"my_enum": FULL_SCHEMA.custom_types["my_enum"]}),
296
+ ComdabReport("error", ROOT.custom_types.right_only, {}, {"my_enum_2": FULL_SCHEMA.custom_types["my_enum_2"]}),
281
297
  ComdabReport("error", ROOT.extra.right_only, {}, {"extra1": FULL_SCHEMA.extra["extra1"]}),
282
298
  ComdabReport("error", ROOT.extra.right_only, {}, {"extra2": FULL_SCHEMA.extra["extra2"]}),
283
299
  ]
@@ -11,6 +11,7 @@ from sqlalchemy import (
11
11
  URL,
12
12
  Connection,
13
13
  Engine,
14
+ Enum,
14
15
  MetaData,
15
16
  Sequence,
16
17
  create_engine,
@@ -21,6 +22,7 @@ from sqlalchemy.sql.ddl import CreateSequence
21
22
 
22
23
  from comdab.models.column import ComdabColumn
23
24
  from comdab.models.constraint import ComdabExcludeConstraint, ComdabPrimaryKeyConstraint
25
+ from comdab.models.custom_type import ComdabCustomType
24
26
  from comdab.models.function import ComdabFunction
25
27
  from comdab.models.schema import ComdabSchema
26
28
  from comdab.models.sequence import ComdabSequence
@@ -377,6 +379,7 @@ def test_psql_exclude_constraints(meta: MetaData, meta_other: MetaData, connecti
377
379
  )
378
380
  },
379
381
  functions={},
382
+ custom_types={},
380
383
  )
381
384
 
382
385
  other_builder = ComdabPostgreSQLBuilder(ComdabSource(connection=connection, schema_name="other"))
@@ -435,6 +438,7 @@ def test_psql_exclude_constraints(meta: MetaData, meta_other: MetaData, connecti
435
438
  )
436
439
  },
437
440
  functions={},
441
+ custom_types={},
438
442
  )
439
443
 
440
444
 
@@ -625,6 +629,7 @@ def test_psql_triggers(meta: MetaData, meta_other: MetaData, connection: Connect
625
629
  extra={},
626
630
  )
627
631
  },
632
+ custom_types={},
628
633
  extra={},
629
634
  )
630
635
 
@@ -688,6 +693,97 @@ def test_psql_triggers(meta: MetaData, meta_other: MetaData, connection: Connect
688
693
  )
689
694
  },
690
695
  functions={},
696
+ custom_types={},
697
+ extra={},
698
+ )
699
+
700
+
701
+ def test_psql_custom_types(meta: MetaData, connection: Connection) -> None:
702
+ class _BaseModel(DeclarativeBase):
703
+ metadata = meta
704
+
705
+ class _Table1(_BaseModel): # pyright: ignore[reportUnusedClass]
706
+ __tablename__ = "table_1"
707
+
708
+ id: Mapped[int] = mapped_column(primary_key=True)
709
+ status = mapped_column(Enum("one", "two", name="my_cool_enum"))
710
+
711
+ meta.create_all(connection)
712
+ Enum("Three (3)", "FOUR", name="my_cool_enum_NEXT").create(connection) # Unused type
713
+
714
+ connection.exec_driver_sql("CREATE SCHEMA other;")
715
+ Enum("five", "6", name="my_cool_enum_other", schema="other").create(connection)
716
+
717
+ builder = ComdabPostgreSQLBuilder(ComdabSource(connection=connection, schema_name="public"))
718
+ assert builder.build_schema() == ComdabSchema(
719
+ tables={
720
+ "table_1": ComdabTable(
721
+ name="table_1",
722
+ columns={
723
+ "id": ComdabColumn(
724
+ name="id",
725
+ type=ComdabTypes.Integer(type="Integer", implem_name="INTEGER", extra={}),
726
+ nullable=False,
727
+ default="nextval('\"public\".table_1_id_seq'::regclass)",
728
+ generation_expression=None,
729
+ extra={},
730
+ ),
731
+ "status": ComdabColumn(
732
+ name="status",
733
+ type=ComdabTypes.Enum(
734
+ implem_name="ENUM", values={"one", "two"}, type_name="my_cool_enum", collation=None
735
+ ),
736
+ nullable=True,
737
+ default=None,
738
+ generation_expression=None,
739
+ extra={},
740
+ ),
741
+ },
742
+ constraints={
743
+ "pk_table_1": ComdabPrimaryKeyConstraint(
744
+ type="primary_key",
745
+ name="pk_table_1",
746
+ deferrable=None,
747
+ initially=None,
748
+ extra={"postgresql_include": []},
749
+ columns={"id"},
750
+ )
751
+ },
752
+ indexes={},
753
+ triggers={},
754
+ extra={},
755
+ ),
756
+ },
757
+ views={},
758
+ sequences={
759
+ "table_1_id_seq": ComdabSequence(
760
+ name="table_1_id_seq",
761
+ type_name="int4",
762
+ start=1,
763
+ increment=1,
764
+ min=1,
765
+ max=2147483647,
766
+ cycle=False,
767
+ extra={},
768
+ ),
769
+ },
770
+ functions={},
771
+ custom_types={
772
+ "my_cool_enum": ComdabCustomType(name="my_cool_enum", values=["one", "two"]),
773
+ "my_cool_enum_NEXT": ComdabCustomType(name="my_cool_enum_NEXT", values=["Three (3)", "FOUR"]),
774
+ },
775
+ extra={},
776
+ )
777
+
778
+ other_builder = ComdabPostgreSQLBuilder(ComdabSource(connection=connection, schema_name="other"))
779
+ assert other_builder.build_schema() == ComdabSchema(
780
+ tables={},
781
+ views={},
782
+ sequences={},
783
+ functions={},
784
+ custom_types={
785
+ "my_cool_enum_other": ComdabCustomType(name="my_cool_enum_other", values=["five", "6"]),
786
+ },
691
787
  extra={},
692
788
  )
693
789
 
@@ -843,4 +939,37 @@ def test_psql_types(connection: Connection, meta: MetaData) -> None:
843
939
  )
844
940
  },
845
941
  functions={},
942
+ custom_types={},
943
+ )
944
+
945
+
946
+ def test_no_primary_key_ignore_fake_constraint(connection: Connection) -> None:
947
+ # Not really psql-specific, but needs a DB
948
+
949
+ connection.exec_driver_sql("CREATE TABLE table_1 (id INTEGER);") # no primary key
950
+
951
+ builder = ComdabPostgreSQLBuilder(ComdabSource(connection=connection, schema_name="public"))
952
+ assert builder.build_schema() == ComdabSchema(
953
+ tables={
954
+ "table_1": ComdabTable(
955
+ name="table_1",
956
+ columns={
957
+ "id": ComdabColumn(
958
+ name="id",
959
+ type=ComdabTypes.Integer(implem_name="INTEGER"),
960
+ nullable=True,
961
+ default=None,
962
+ generation_expression=None,
963
+ ),
964
+ },
965
+ constraints={},
966
+ indexes={},
967
+ triggers={},
968
+ extra={},
969
+ ),
970
+ },
971
+ views={},
972
+ sequences={},
973
+ functions={},
974
+ custom_types={},
846
975
  )
@@ -84,7 +84,7 @@ wheels = [
84
84
 
85
85
  [[package]]
86
86
  name = "comdab"
87
- version = "0.2.0"
87
+ version = "0.3.0"
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
File without changes