comdab 0.4.0__tar.gz → 0.4.2__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.
- {comdab-0.4.0 → comdab-0.4.2}/.github/workflows/test.yml +1 -1
- {comdab-0.4.0 → comdab-0.4.2}/CHANGELOG.md +19 -0
- {comdab-0.4.0 → comdab-0.4.2}/PKG-INFO +56 -9
- {comdab-0.4.0 → comdab-0.4.2}/README.md +54 -7
- {comdab-0.4.0 → comdab-0.4.2}/pyproject.toml +5 -3
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/main.py +3 -3
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/migrate.py +23 -14
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/__init__.py +2 -1
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/constraint.py +1 -1
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_compare.py +32 -1
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_main.py +16 -11
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_migrate.py +118 -33
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_models.py +8 -9
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_specific/test_postgresql.py +11 -5
- comdab-0.4.2/uv.lock +772 -0
- comdab-0.4.0/uv.lock +0 -642
- {comdab-0.4.0 → comdab-0.4.2}/.github/workflows/release.yml +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/.gitignore +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/.pre-commit-config.yaml +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/.python-version +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/.readthedocs.yaml +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/LICENSE +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/docs/Makefile +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/docs/conf.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/docs/index.rst +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/docs/reference.rst +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/__init__.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/build.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/compare.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/exceptions.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/base.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/column.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/custom_type.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/function.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/index.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/schema.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/sequence.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/table.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/trigger.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/type.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/models/view.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/path.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/py.typed +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/report.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/source.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/__init__.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/__init__.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/build.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/custom_types.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/exclude_constraints.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/functions.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/sequences.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/triggers.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/specific/postgresql/views.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/src/comdab/utils.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/tests/__init__.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/tests/_mock_module.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/tests/conftest.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_build.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_specific/__init__.py +0 -0
- {comdab-0.4.0 → comdab-0.4.2}/tests/test_utils.py +0 -0
|
@@ -5,6 +5,25 @@ 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.4.2] - 2026-11-27
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Use `ComdabPostgreSQLBuilder` for all PostgreSQL drivers included in SQLAlchemy,
|
|
13
|
+
not only the default one (and use `psycopg` instead of `psycopg2` for tests)
|
|
14
|
+
- Fix SQLAlchemy 2.1 deprecation warnings
|
|
15
|
+
|
|
16
|
+
## [0.4.1] - 2026-06-21
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Fix `ComdabInternalError` raised when generating migrations updating some
|
|
21
|
+
model `extra`; `MigrationGeneratorPort.alter_*_extra` methods are now
|
|
22
|
+
correctly called in these cases (fixes [#1](https://github.com/loic-simon/comdab/issues/1))
|
|
23
|
+
- Fix `ComdabForeignKeyConstraint.columns_mapping` not treated as an opaque
|
|
24
|
+
value in comparisons (generated `.left_only` / `.right_only` paths)
|
|
25
|
+
- Fix `ComdabType` not exported in `comdab.models`
|
|
26
|
+
|
|
8
27
|
## [0.4.0] - 2026-05-31
|
|
9
28
|
|
|
10
29
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: comdab
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
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
|
|
@@ -49,16 +49,21 @@ pip install comdab
|
|
|
49
49
|
|
|
50
50
|
### Requirements
|
|
51
51
|
|
|
52
|
-
- Python `>= 3.
|
|
52
|
+
- Python `>= 3.13`
|
|
53
53
|
- [sqlalchemy](https://pypi.org/project/sqlalchemy) `>= 2.0`
|
|
54
54
|
- [pydantic](https://pypi.org/project/pydantic) `>= 2.0`
|
|
55
55
|
|
|
56
56
|
## Goals
|
|
57
57
|
|
|
58
|
-
_comdab_
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
_comdab_ allows you to compare in depth two database schemas to find
|
|
59
|
+
all differences (missing columns, different nullabilities or defaults,
|
|
60
|
+
slight changes in function or triggers definitions...) and turn these
|
|
61
|
+
reports into model migrations.
|
|
62
|
+
|
|
63
|
+
_comdab_ migration generation supercharges migration tools like
|
|
64
|
+
[Alembic](https://alembic.sqlalchemy.org) to create migrations that,
|
|
65
|
+
when applied to an existing database, produce **the exact same schema**
|
|
66
|
+
than a new database created from scratch.
|
|
62
67
|
|
|
63
68
|
Indeed, while migration tools can auto-detect model changes and write
|
|
64
69
|
automatically the migrations to apply to pre-existing databases, it does not
|
|
@@ -72,11 +77,17 @@ on pre-existing databases with the new migration applied.
|
|
|
72
77
|
|
|
73
78
|
By running _comdab_, you can ensure the two are the nearly-exact same.
|
|
74
79
|
|
|
75
|
-
_comdab_
|
|
76
|
-
|
|
80
|
+
_comdab_ is based on the wonderful [SQLAlchemy](https://sqlalchemy.org) library
|
|
81
|
+
to connect to the database, and for most of schema introspection.
|
|
77
82
|
|
|
78
83
|
## Usage
|
|
79
84
|
|
|
85
|
+
### Comparing database schemas
|
|
86
|
+
|
|
87
|
+
_comdab_ main reporting function is
|
|
88
|
+
[`.compare_databases`](https://comdab.readthedocs.io/en/latest/reference.html#comdab.compare_databases),
|
|
89
|
+
which needs already established SQLAlchemy connections to the two databases to compare:
|
|
90
|
+
|
|
80
91
|
```py
|
|
81
92
|
from comdab import compare_databases
|
|
82
93
|
from sqlalchemy import create_engine
|
|
@@ -93,6 +104,42 @@ else:
|
|
|
93
104
|
print("✅ Database schemas are the same!")
|
|
94
105
|
```
|
|
95
106
|
|
|
107
|
+
### Generating migrations
|
|
108
|
+
|
|
109
|
+
To generate migrations, a user-defined
|
|
110
|
+
[`MigrationGeneratorPort`](https://comdab.readthedocs.io/en/latest/reference.html#comdab.MigrationGeneratorPort) /
|
|
111
|
+
[`PartialMigrationGeneratorPort`](https://comdab.readthedocs.io/en/latest/reference.html#comdab.MigrationGeneratorPort)
|
|
112
|
+
subclass is additionally needed:
|
|
113
|
+
|
|
114
|
+
```py
|
|
115
|
+
from comdab import generate_migrations, PartialMigrationGeneratorPort
|
|
116
|
+
from comdab.models import ComdabTable
|
|
117
|
+
from sqlalchemy import create_engine
|
|
118
|
+
|
|
119
|
+
class MyMigrationGenerator(PartialMigrationGeneratorPort):
|
|
120
|
+
def __init__(self) -> None:
|
|
121
|
+
self.sql_text = ""
|
|
122
|
+
|
|
123
|
+
def create_table(self, *, table: ComdabTable) -> None:
|
|
124
|
+
self.sql_text += f"CREATE TABLE {table.name} [...];\n"
|
|
125
|
+
|
|
126
|
+
def drop_table(self, *, table: ComdabTable) -> None:
|
|
127
|
+
self.sql_text += f"DROP TABLE {table.name};\n"
|
|
128
|
+
|
|
129
|
+
...
|
|
130
|
+
|
|
131
|
+
generator = MyMigrationGenerator()
|
|
132
|
+
engine_1 = create_engine("postgresql://user:pass@host/source")
|
|
133
|
+
engine_2 = create_engine("postgresql://user:pass@host/target")
|
|
134
|
+
|
|
135
|
+
with engine_1.connect() as source_conn, engine_2.connect() as target_conn:
|
|
136
|
+
generate_migrations(source_conn, target_conn, generator)
|
|
137
|
+
|
|
138
|
+
print(generator.sql_text)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Advanced usage
|
|
142
|
+
|
|
96
143
|
See [documentation](https://comdab.readthedocs.io) for configuration and other details.
|
|
97
144
|
|
|
98
145
|
## Contributing
|
|
@@ -26,16 +26,21 @@ pip install comdab
|
|
|
26
26
|
|
|
27
27
|
### Requirements
|
|
28
28
|
|
|
29
|
-
- Python `>= 3.
|
|
29
|
+
- Python `>= 3.13`
|
|
30
30
|
- [sqlalchemy](https://pypi.org/project/sqlalchemy) `>= 2.0`
|
|
31
31
|
- [pydantic](https://pypi.org/project/pydantic) `>= 2.0`
|
|
32
32
|
|
|
33
33
|
## Goals
|
|
34
34
|
|
|
35
|
-
_comdab_
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
_comdab_ allows you to compare in depth two database schemas to find
|
|
36
|
+
all differences (missing columns, different nullabilities or defaults,
|
|
37
|
+
slight changes in function or triggers definitions...) and turn these
|
|
38
|
+
reports into model migrations.
|
|
39
|
+
|
|
40
|
+
_comdab_ migration generation supercharges migration tools like
|
|
41
|
+
[Alembic](https://alembic.sqlalchemy.org) to create migrations that,
|
|
42
|
+
when applied to an existing database, produce **the exact same schema**
|
|
43
|
+
than a new database created from scratch.
|
|
39
44
|
|
|
40
45
|
Indeed, while migration tools can auto-detect model changes and write
|
|
41
46
|
automatically the migrations to apply to pre-existing databases, it does not
|
|
@@ -49,11 +54,17 @@ on pre-existing databases with the new migration applied.
|
|
|
49
54
|
|
|
50
55
|
By running _comdab_, you can ensure the two are the nearly-exact same.
|
|
51
56
|
|
|
52
|
-
_comdab_
|
|
53
|
-
|
|
57
|
+
_comdab_ is based on the wonderful [SQLAlchemy](https://sqlalchemy.org) library
|
|
58
|
+
to connect to the database, and for most of schema introspection.
|
|
54
59
|
|
|
55
60
|
## Usage
|
|
56
61
|
|
|
62
|
+
### Comparing database schemas
|
|
63
|
+
|
|
64
|
+
_comdab_ main reporting function is
|
|
65
|
+
[`.compare_databases`](https://comdab.readthedocs.io/en/latest/reference.html#comdab.compare_databases),
|
|
66
|
+
which needs already established SQLAlchemy connections to the two databases to compare:
|
|
67
|
+
|
|
57
68
|
```py
|
|
58
69
|
from comdab import compare_databases
|
|
59
70
|
from sqlalchemy import create_engine
|
|
@@ -70,6 +81,42 @@ else:
|
|
|
70
81
|
print("✅ Database schemas are the same!")
|
|
71
82
|
```
|
|
72
83
|
|
|
84
|
+
### Generating migrations
|
|
85
|
+
|
|
86
|
+
To generate migrations, a user-defined
|
|
87
|
+
[`MigrationGeneratorPort`](https://comdab.readthedocs.io/en/latest/reference.html#comdab.MigrationGeneratorPort) /
|
|
88
|
+
[`PartialMigrationGeneratorPort`](https://comdab.readthedocs.io/en/latest/reference.html#comdab.MigrationGeneratorPort)
|
|
89
|
+
subclass is additionally needed:
|
|
90
|
+
|
|
91
|
+
```py
|
|
92
|
+
from comdab import generate_migrations, PartialMigrationGeneratorPort
|
|
93
|
+
from comdab.models import ComdabTable
|
|
94
|
+
from sqlalchemy import create_engine
|
|
95
|
+
|
|
96
|
+
class MyMigrationGenerator(PartialMigrationGeneratorPort):
|
|
97
|
+
def __init__(self) -> None:
|
|
98
|
+
self.sql_text = ""
|
|
99
|
+
|
|
100
|
+
def create_table(self, *, table: ComdabTable) -> None:
|
|
101
|
+
self.sql_text += f"CREATE TABLE {table.name} [...];\n"
|
|
102
|
+
|
|
103
|
+
def drop_table(self, *, table: ComdabTable) -> None:
|
|
104
|
+
self.sql_text += f"DROP TABLE {table.name};\n"
|
|
105
|
+
|
|
106
|
+
...
|
|
107
|
+
|
|
108
|
+
generator = MyMigrationGenerator()
|
|
109
|
+
engine_1 = create_engine("postgresql://user:pass@host/source")
|
|
110
|
+
engine_2 = create_engine("postgresql://user:pass@host/target")
|
|
111
|
+
|
|
112
|
+
with engine_1.connect() as source_conn, engine_2.connect() as target_conn:
|
|
113
|
+
generate_migrations(source_conn, target_conn, generator)
|
|
114
|
+
|
|
115
|
+
print(generator.sql_text)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Advanced usage
|
|
119
|
+
|
|
73
120
|
See [documentation](https://comdab.readthedocs.io) for configuration and other details.
|
|
74
121
|
|
|
75
122
|
## Contributing
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "comdab"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.2"
|
|
4
4
|
description = "Compare Database Schemas"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
@@ -29,7 +29,7 @@ build-backend = "hatchling.build"
|
|
|
29
29
|
|
|
30
30
|
[dependency-groups]
|
|
31
31
|
dev = [
|
|
32
|
-
"
|
|
32
|
+
"psycopg>=3.3.9",
|
|
33
33
|
"pytest>=8.4.0",
|
|
34
34
|
"ruff>=0.11.11",
|
|
35
35
|
]
|
|
@@ -39,6 +39,7 @@ docs = [
|
|
|
39
39
|
]
|
|
40
40
|
|
|
41
41
|
[tool.ruff]
|
|
42
|
+
target-version = "py313"
|
|
42
43
|
line-length = 120
|
|
43
44
|
|
|
44
45
|
[tool.ruff.lint]
|
|
@@ -55,5 +56,6 @@ reportUnknownMemberType = false
|
|
|
55
56
|
[tool.pytest]
|
|
56
57
|
filterwarnings = [
|
|
57
58
|
"error",
|
|
58
|
-
"ignore:.+can't locate any SQLAlchemy dialect:sqlalchemy.exc.SAWarning"
|
|
59
|
+
"ignore:.+can't locate any SQLAlchemy dialect:sqlalchemy.exc.SAWarning",
|
|
60
|
+
"ignore:The Result.t method is deprecated:sqlalchemy.exc.SADeprecationWarning", # SQLA 2.0 compatibility
|
|
59
61
|
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from collections.abc import Iterable
|
|
2
2
|
|
|
3
3
|
from sqlalchemy import Connection
|
|
4
|
-
from sqlalchemy.dialects import
|
|
4
|
+
from sqlalchemy.dialects.postgresql import asyncpg, pg8000, psycopg, psycopg2
|
|
5
5
|
|
|
6
6
|
from comdab.build import ComdabBuilder
|
|
7
7
|
from comdab.compare import ComdabComparer, ComdabStrategy
|
|
@@ -111,10 +111,10 @@ def build_comdab_schema(
|
|
|
111
111
|
"""
|
|
112
112
|
source = ComdabSource(connection=connection, schema_name=schema)
|
|
113
113
|
match connection.dialect:
|
|
114
|
-
case
|
|
114
|
+
case psycopg.dialect() | psycopg2.dialect() | asyncpg.dialect() | pg8000.dialect():
|
|
115
115
|
from comdab.specific.postgresql.build import ComdabPostgreSQLBuilder
|
|
116
116
|
|
|
117
|
-
builder = ComdabPostgreSQLBuilder(source, allow_unknown_types=allow_unknown_types)
|
|
117
|
+
builder: ComdabBuilder = ComdabPostgreSQLBuilder(source, allow_unknown_types=allow_unknown_types)
|
|
118
118
|
|
|
119
119
|
case _:
|
|
120
120
|
builder = ComdabBuilder(source, allow_unknown_types=allow_unknown_types)
|
|
@@ -36,8 +36,7 @@ def _register[MF: Callable[..., None]](path: ComdabPath, **kwargs: _ReportGetter
|
|
|
36
36
|
raise ValueError(f"Migration already registered for {path}: {_path_to_migration_func_spec[path]}")
|
|
37
37
|
|
|
38
38
|
_path_to_migration_func_spec[path] = (func.__name__, kwargs)
|
|
39
|
-
func.
|
|
40
|
-
func._registered_kwargs = kwargs # pyright: ignore[reportFunctionMemberAccess] # used for tests only
|
|
39
|
+
func._comdab_registered = (*getattr(func, "_comdab_registered", ()), (path, kwargs)) # pyright: ignore[reportFunctionMemberAccess] # used for tests only
|
|
41
40
|
return func
|
|
42
41
|
|
|
43
42
|
return _decorator
|
|
@@ -143,7 +142,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
143
142
|
self.__default_impl()
|
|
144
143
|
|
|
145
144
|
@abstractmethod
|
|
146
|
-
@_register(ROOT.extra, old_extra=_left, new_extra=_right)
|
|
145
|
+
@_register(ROOT.extra.left_only, old_extra=_left, new_extra=_right)
|
|
146
|
+
@_register(ROOT.extra.right_only, old_extra=_left, new_extra=_right)
|
|
147
147
|
def alter_schema_extra(self, *, old_extra: dict[str, Any], new_extra: dict[str, Any]) -> None:
|
|
148
148
|
"""Change some dialect-specific schema options."""
|
|
149
149
|
self.__default_impl()
|
|
@@ -199,7 +199,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
199
199
|
self.__default_impl()
|
|
200
200
|
|
|
201
201
|
@abstractmethod
|
|
202
|
-
@_register(ROOT.tables[...].extra, old_extra=_left, new_extra=_right)
|
|
202
|
+
@_register(ROOT.tables[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
203
|
+
@_register(ROOT.tables[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
203
204
|
def alter_table_extra(self, *, table: ComdabTable, old_extra: dict[str, Any], new_extra: dict[str, Any]) -> None:
|
|
204
205
|
"""Change some dialect-specific table options."""
|
|
205
206
|
self.__default_impl()
|
|
@@ -217,7 +218,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
217
218
|
self.__default_impl()
|
|
218
219
|
|
|
219
220
|
@abstractmethod
|
|
220
|
-
@_register(ROOT.views[...].extra, old_extra=_left, new_extra=_right)
|
|
221
|
+
@_register(ROOT.views[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
222
|
+
@_register(ROOT.views[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
221
223
|
def alter_view_extra(self, *, view: ComdabView, old_extra: dict[str, Any], new_extra: dict[str, Any]) -> None:
|
|
222
224
|
"""Change some dialect-specific view options."""
|
|
223
225
|
self.__default_impl()
|
|
@@ -259,7 +261,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
259
261
|
self.__default_impl()
|
|
260
262
|
|
|
261
263
|
@abstractmethod
|
|
262
|
-
@_register(ROOT.sequences[...].extra, old_extra=_left, new_extra=_right)
|
|
264
|
+
@_register(ROOT.sequences[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
265
|
+
@_register(ROOT.sequences[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
263
266
|
def alter_sequence_extra(
|
|
264
267
|
self, *, sequence: ComdabSequence, old_extra: dict[str, Any], new_extra: dict[str, Any]
|
|
265
268
|
) -> None:
|
|
@@ -273,7 +276,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
273
276
|
self.__default_impl()
|
|
274
277
|
|
|
275
278
|
@abstractmethod
|
|
276
|
-
@_register(ROOT.functions[...].extra, old_extra=_left, new_extra=_right)
|
|
279
|
+
@_register(ROOT.functions[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
280
|
+
@_register(ROOT.functions[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
277
281
|
def alter_function_extra(
|
|
278
282
|
self, *, function: ComdabFunction, old_extra: dict[str, Any], new_extra: dict[str, Any]
|
|
279
283
|
) -> None:
|
|
@@ -289,7 +293,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
289
293
|
self.__default_impl()
|
|
290
294
|
|
|
291
295
|
@abstractmethod
|
|
292
|
-
@_register(ROOT.custom_types[...].extra, old_extra=_left, new_extra=_right)
|
|
296
|
+
@_register(ROOT.custom_types[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
297
|
+
@_register(ROOT.custom_types[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
293
298
|
def alter_custom_type_extra(
|
|
294
299
|
self, *, custom_type: ComdabCustomType, old_extra: dict[str, Any], new_extra: dict[str, Any]
|
|
295
300
|
) -> None:
|
|
@@ -315,9 +320,9 @@ class MigrationGeneratorPort(ABC):
|
|
|
315
320
|
self.__default_impl()
|
|
316
321
|
|
|
317
322
|
@abstractmethod
|
|
318
|
-
@_register(ROOT.tables[...].columns[...].default,
|
|
323
|
+
@_register(ROOT.tables[...].columns[...].default, old_default=_left, new_default=_right)
|
|
319
324
|
def alter_column_default(
|
|
320
|
-
self, *, table: ComdabTable, column: ComdabColumn,
|
|
325
|
+
self, *, table: ComdabTable, column: ComdabColumn, old_default: str | None, new_default: str | None
|
|
321
326
|
) -> None:
|
|
322
327
|
"""Change the default value of a column."""
|
|
323
328
|
self.__default_impl()
|
|
@@ -331,7 +336,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
331
336
|
self.__default_impl()
|
|
332
337
|
|
|
333
338
|
@abstractmethod
|
|
334
|
-
@_register(ROOT.tables[...].columns[...].extra, old_extra=_left, new_extra=_right)
|
|
339
|
+
@_register(ROOT.tables[...].columns[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
340
|
+
@_register(ROOT.tables[...].columns[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
335
341
|
def alter_column_extra(
|
|
336
342
|
self, *, table: ComdabTable, column: ComdabColumn, old_extra: dict[str, Any], new_extra: dict[str, Any]
|
|
337
343
|
) -> None:
|
|
@@ -378,7 +384,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
378
384
|
self.__default_impl()
|
|
379
385
|
|
|
380
386
|
@abstractmethod
|
|
381
|
-
@_register(ROOT.tables[...].constraints[...].extra, old_extra=_left, new_extra=_right)
|
|
387
|
+
@_register(ROOT.tables[...].constraints[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
388
|
+
@_register(ROOT.tables[...].constraints[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
382
389
|
def alter_constraint_extra(
|
|
383
390
|
self, *, table: ComdabTable, constraint: ComdabConstraint, old_extra: dict[str, Any], new_extra: dict[str, Any]
|
|
384
391
|
) -> None:
|
|
@@ -477,7 +484,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
477
484
|
self.__default_impl()
|
|
478
485
|
|
|
479
486
|
@abstractmethod
|
|
480
|
-
@_register(ROOT.tables[...].indexes[...].extra, old_extra=_left, new_extra=_right)
|
|
487
|
+
@_register(ROOT.tables[...].indexes[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
488
|
+
@_register(ROOT.tables[...].indexes[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
481
489
|
def alter_index_extra(
|
|
482
490
|
self, *, table: ComdabTable, index: ComdabIndex, old_extra: dict[str, Any], new_extra: dict[str, Any]
|
|
483
491
|
) -> None:
|
|
@@ -493,7 +501,8 @@ class MigrationGeneratorPort(ABC):
|
|
|
493
501
|
self.__default_impl()
|
|
494
502
|
|
|
495
503
|
@abstractmethod
|
|
496
|
-
@_register(ROOT.tables[...].triggers[...].extra, old_extra=_left, new_extra=_right)
|
|
504
|
+
@_register(ROOT.tables[...].triggers[...].extra.left_only, old_extra=_left, new_extra=_right)
|
|
505
|
+
@_register(ROOT.tables[...].triggers[...].extra.right_only, old_extra=_left, new_extra=_right)
|
|
497
506
|
def alter_trigger_extra(
|
|
498
507
|
self, *, table: ComdabTable, trigger: ComdabTrigger, old_extra: dict[str, Any], new_extra: dict[str, Any]
|
|
499
508
|
) -> None:
|
|
@@ -15,7 +15,7 @@ from comdab.models.schema import ROOT, ComdabSchema
|
|
|
15
15
|
from comdab.models.sequence import ComdabSequence
|
|
16
16
|
from comdab.models.table import ComdabTable
|
|
17
17
|
from comdab.models.trigger import ComdabTrigger
|
|
18
|
-
from comdab.models.type import ComdabTypes
|
|
18
|
+
from comdab.models.type import ComdabType, ComdabTypes
|
|
19
19
|
from comdab.models.view import ComdabView
|
|
20
20
|
|
|
21
21
|
__all__ = (
|
|
@@ -40,5 +40,6 @@ __all__ = (
|
|
|
40
40
|
"ComdabIndex",
|
|
41
41
|
"ComdabTrigger",
|
|
42
42
|
# Level 3
|
|
43
|
+
"ComdabType",
|
|
43
44
|
"ComdabTypes",
|
|
44
45
|
)
|
|
@@ -35,7 +35,7 @@ class _BaseComdabConstraint(ComdabModel, frozen=True):
|
|
|
35
35
|
|
|
36
36
|
# Union of fields of all constraint types
|
|
37
37
|
columns = terminal_path()
|
|
38
|
-
columns_mapping =
|
|
38
|
+
columns_mapping = terminal_path()
|
|
39
39
|
on_update = terminal_path()
|
|
40
40
|
on_delete = terminal_path()
|
|
41
41
|
sql_text = terminal_path()
|
|
@@ -7,6 +7,8 @@ from comdab.compare import ComdabComparer, ComdabStrategy
|
|
|
7
7
|
from comdab.models import (
|
|
8
8
|
ROOT,
|
|
9
9
|
ComdabColumn,
|
|
10
|
+
ComdabCustomType,
|
|
11
|
+
ComdabForeignKeyConstraint,
|
|
10
12
|
ComdabFunction,
|
|
11
13
|
ComdabIndex,
|
|
12
14
|
ComdabPrimaryKeyConstraint,
|
|
@@ -18,7 +20,6 @@ from comdab.models import (
|
|
|
18
20
|
ComdabUniqueConstraint,
|
|
19
21
|
ComdabView,
|
|
20
22
|
)
|
|
21
|
-
from comdab.models.custom_type import ComdabCustomType
|
|
22
23
|
from comdab.path import ComdabPath
|
|
23
24
|
from comdab.report import ComdabReport
|
|
24
25
|
|
|
@@ -63,6 +64,14 @@ FULL_SCHEMA = ComdabSchema(
|
|
|
63
64
|
"col1_col2_uq": ComdabUniqueConstraint(
|
|
64
65
|
name="col1_col2_uq", deferrable=True, initially="DEFERRED", columns={"col1", "col2"}
|
|
65
66
|
),
|
|
67
|
+
"col2_fk": ComdabForeignKeyConstraint(
|
|
68
|
+
name="col2_fk",
|
|
69
|
+
deferrable=None,
|
|
70
|
+
initially=None,
|
|
71
|
+
columns_mapping={"col2": "table2.col3"},
|
|
72
|
+
on_update=None,
|
|
73
|
+
on_delete=None,
|
|
74
|
+
),
|
|
66
75
|
},
|
|
67
76
|
indexes={
|
|
68
77
|
"ix_col1": ComdabIndex(
|
|
@@ -239,6 +248,28 @@ def test_empty_vs_full() -> None:
|
|
|
239
248
|
{"key1": True},
|
|
240
249
|
{"key1": True, "key2": False},
|
|
241
250
|
),
|
|
251
|
+
(
|
|
252
|
+
replace(
|
|
253
|
+
(s := FULL_SCHEMA),
|
|
254
|
+
tables={
|
|
255
|
+
**s.tables,
|
|
256
|
+
"table1": replace(
|
|
257
|
+
(t := s.tables["table1"]),
|
|
258
|
+
constraints={
|
|
259
|
+
**t.constraints,
|
|
260
|
+
"col2_fk": replace(
|
|
261
|
+
(c := t.constraints["col2_fk"]),
|
|
262
|
+
columns_mapping={"col2": "table2.col3", "col1": "table2.col3"},
|
|
263
|
+
),
|
|
264
|
+
},
|
|
265
|
+
),
|
|
266
|
+
},
|
|
267
|
+
),
|
|
268
|
+
# No deep comparison of FK columns_mapping
|
|
269
|
+
ROOT.tables["table1"].constraints["col2_fk"].columns_mapping,
|
|
270
|
+
{"col2": "table2.col3", "col1": "table2.col3"},
|
|
271
|
+
{"col2": "table2.col3"},
|
|
272
|
+
),
|
|
242
273
|
],
|
|
243
274
|
)
|
|
244
275
|
def test_subtil_differences(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from unittest import mock
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from pytest import Subtests
|
|
4
|
+
from sqlalchemy.dialects import mysql
|
|
5
|
+
from sqlalchemy.dialects.postgresql import asyncpg, pg8000, psycopg, psycopg2
|
|
4
6
|
|
|
5
7
|
from comdab.main import (
|
|
6
8
|
build_comdab_schema,
|
|
@@ -99,7 +101,7 @@ def test_compare_databases() -> None:
|
|
|
99
101
|
assert reports is compare_mock.return_value
|
|
100
102
|
|
|
101
103
|
|
|
102
|
-
def test_build_comdab_schema() -> None:
|
|
104
|
+
def test_build_comdab_schema(subtests: Subtests) -> None:
|
|
103
105
|
with (
|
|
104
106
|
mock.patch("comdab.main.ComdabBuilder") as generic_builder_mock,
|
|
105
107
|
mock.patch.dict(
|
|
@@ -127,17 +129,20 @@ def test_build_comdab_schema() -> None:
|
|
|
127
129
|
generic_builder_mock.return_value.build_schema.assert_called_once_with()
|
|
128
130
|
assert result is generic_builder_mock.return_value.build_schema.return_value
|
|
129
131
|
|
|
130
|
-
generic_builder_mock.reset_mock()
|
|
131
132
|
psql_builder_mock.assert_not_called()
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
for driver in (psycopg, psycopg2, asyncpg, pg8000):
|
|
135
|
+
generic_builder_mock.reset_mock()
|
|
136
|
+
psql_builder_mock.reset_mock()
|
|
137
|
+
with subtests.test(driver=driver):
|
|
138
|
+
connection = mock.Mock(dialect=driver.dialect())
|
|
139
|
+
result = build_comdab_schema(connection, schema="other", allow_unknown_types=True)
|
|
140
|
+
generic_builder_mock.assert_not_called()
|
|
141
|
+
psql_builder_mock.assert_called_once_with(
|
|
142
|
+
ComdabSource(connection=connection, schema_name="other"), allow_unknown_types=True
|
|
143
|
+
)
|
|
144
|
+
psql_builder_mock.return_value.build_schema.assert_called_once_with()
|
|
145
|
+
assert result is psql_builder_mock.return_value.build_schema.return_value
|
|
141
146
|
|
|
142
147
|
|
|
143
148
|
def test_compare_comdab_schemas() -> None:
|