comdab 0.3.1__tar.gz → 0.4.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.
- {comdab-0.3.1 → comdab-0.4.1}/.github/workflows/test.yml +7 -6
- comdab-0.4.1/.python-version +1 -0
- comdab-0.4.1/.readthedocs.yaml +16 -0
- comdab-0.4.1/CHANGELOG.md +75 -0
- {comdab-0.3.1 → comdab-0.4.1}/PKG-INFO +58 -11
- {comdab-0.3.1 → comdab-0.4.1}/README.md +55 -8
- {comdab-0.3.1 → comdab-0.4.1}/docs/conf.py +20 -1
- {comdab-0.3.1 → comdab-0.4.1}/docs/index.rst +56 -13
- comdab-0.4.1/docs/reference.rst +39 -0
- {comdab-0.3.1 → comdab-0.4.1}/pyproject.toml +14 -3
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/__init__.py +12 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/exceptions.py +4 -2
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/main.py +66 -5
- comdab-0.4.1/src/comdab/migrate.py +569 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/__init__.py +21 -12
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/column.py +1 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/constraint.py +21 -13
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/function.py +1 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/index.py +1 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/schema.py +1 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/table.py +1 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/view.py +1 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/path.py +27 -1
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/report.py +4 -6
- {comdab-0.3.1 → comdab-0.4.1}/tests/test_compare.py +32 -1
- comdab-0.4.1/tests/test_main.py +169 -0
- comdab-0.4.1/tests/test_migrate.py +692 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/test_models.py +11 -10
- comdab-0.4.1/uv.lock +642 -0
- comdab-0.3.1/.python-version +0 -1
- comdab-0.3.1/.readthedocs.yaml +0 -9
- comdab-0.3.1/CHANGELOG.md +0 -44
- comdab-0.3.1/docs/reference.rst +0 -20
- comdab-0.3.1/tests/test_main.py +0 -67
- comdab-0.3.1/uv.lock +0 -658
- {comdab-0.3.1 → comdab-0.4.1}/.github/workflows/release.yml +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/.gitignore +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/.pre-commit-config.yaml +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/LICENSE +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/docs/Makefile +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/build.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/compare.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/base.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/custom_type.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/sequence.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/trigger.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/models/type.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/py.typed +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/source.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/__init__.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/__init__.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/build.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/custom_types.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/exclude_constraints.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/functions.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/sequences.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/triggers.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/specific/postgresql/views.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/src/comdab/utils.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/__init__.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/_mock_module.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/conftest.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/test_build.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/test_specific/__init__.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/test_specific/test_postgresql.py +0 -0
- {comdab-0.3.1 → comdab-0.4.1}/tests/test_utils.py +0 -0
|
@@ -9,22 +9,23 @@ jobs:
|
|
|
9
9
|
strategy:
|
|
10
10
|
matrix:
|
|
11
11
|
python-version:
|
|
12
|
-
- "3.12"
|
|
13
12
|
- "3.13"
|
|
14
|
-
- "3.14
|
|
13
|
+
- "3.14"
|
|
14
|
+
- "3.15.0-beta.2"
|
|
15
15
|
|
|
16
16
|
steps:
|
|
17
|
-
- uses: actions/checkout@
|
|
17
|
+
- uses: actions/checkout@v6
|
|
18
18
|
|
|
19
19
|
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
-
uses: actions/setup-python@
|
|
20
|
+
uses: actions/setup-python@v6
|
|
21
21
|
with:
|
|
22
22
|
python-version: ${{ matrix.python-version }}
|
|
23
23
|
|
|
24
24
|
- name: Install uv
|
|
25
|
-
uses: astral-sh/setup-uv@
|
|
25
|
+
uses: astral-sh/setup-uv@v8.1.0
|
|
26
26
|
with:
|
|
27
|
-
version: "0.
|
|
27
|
+
version: "0.11.8"
|
|
28
|
+
python-version: ${{ matrix.python-version }}
|
|
28
29
|
enable-cache: true
|
|
29
30
|
|
|
30
31
|
- name: Install the project
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
|
@@ -0,0 +1,75 @@
|
|
|
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.4.1] - 2026-06-21
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fix `ComdabInternalError` raised when generating migrations updating some
|
|
13
|
+
model `extra`; `MigrationGeneratorPort.alter_*_extra` methods are now
|
|
14
|
+
correctly called in these cases (fixes [#1](https://github.com/loic-simon/comdab/issues/1))
|
|
15
|
+
- Fix `ComdabForeignKeyConstraint.columns_mapping` not treated as an opaque
|
|
16
|
+
value in comparisons (generated `.left_only` / `.right_only` paths)
|
|
17
|
+
- Fix `ComdabType` not exported in `comdab.models`
|
|
18
|
+
|
|
19
|
+
## [0.4.0] - 2026-05-31
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- New migration generation mechanism, based on new `generate_migrations`
|
|
24
|
+
and `generate_migrations_from_reports` top-level functions, and new
|
|
25
|
+
`MigrationGeneratorPort` / `PartialMigrationGeneratorPort` classes
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Bump minimal Python version to 3.13, test with Python 3.15
|
|
30
|
+
- Improve documentation style and API Reference page
|
|
31
|
+
- Bump package versions in uv.lock, other maintenance upgrades
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- Fix `ComdabConstraint` annotations, using a new `ComdabConstraintType` alias
|
|
36
|
+
for more precise tagged union typing
|
|
37
|
+
- Various documentation fixes
|
|
38
|
+
|
|
39
|
+
## [0.3.1] - 2026-04-07
|
|
40
|
+
|
|
41
|
+
### Added
|
|
42
|
+
|
|
43
|
+
- PostgreSQL: detect & compare procedures, in addition of regular functions
|
|
44
|
+
|
|
45
|
+
## [0.3.0] - 2025-08-12
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
|
|
49
|
+
- PostgreSQL: detect & compare enum types, even if they are unused
|
|
50
|
+
(new model `ComdabCustomType`, in `ROOT.custom_types`)
|
|
51
|
+
|
|
52
|
+
## [0.2.1] - 2025-08-06
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
- Fix crash when reflecting tables without a primary key
|
|
57
|
+
|
|
58
|
+
## [0.2.0] - 2025-07-23
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
|
|
62
|
+
- Ignore rules aimed at specific dictionary key(s) now also apply to matching keys that are only in the left
|
|
63
|
+
or only in the right dictionaries, in addition to `.left_only` / `.right_only` rules
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- PostgreSQL exclude constraints attributes and operators were sometime mixed
|
|
68
|
+
|
|
69
|
+
## [0.1.1] - 2025-06-22
|
|
70
|
+
|
|
71
|
+
- Fixed PyPI metadata and other non-code changes
|
|
72
|
+
|
|
73
|
+
## [0.1.0] - 2025-06-22
|
|
74
|
+
|
|
75
|
+
Initial version
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: comdab
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.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
|
|
@@ -11,12 +11,12 @@ License-File: LICENSE
|
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
17
17
|
Classifier: Topic :: Database
|
|
18
18
|
Classifier: Typing :: Typed
|
|
19
|
-
Requires-Python: >=3.
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
20
|
Requires-Dist: pydantic>=2.0
|
|
21
21
|
Requires-Dist: sqlalchemy>=2.0
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
@@ -35,7 +35,7 @@ slight changes in function or triggers definitions...
|
|
|
35
35
|
|
|
36
36
|
> [!WARNING]
|
|
37
37
|
>
|
|
38
|
-
> _comdab_ is still in development, only tested with PostgreSQL 14 to date.
|
|
38
|
+
> _comdab_ is still in development, only tested with PostgreSQL 14 — 18 to date.
|
|
39
39
|
>
|
|
40
40
|
> All feedback and contributions are welcome!
|
|
41
41
|
|
|
@@ -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
|
|
@@ -12,7 +12,7 @@ slight changes in function or triggers definitions...
|
|
|
12
12
|
|
|
13
13
|
> [!WARNING]
|
|
14
14
|
>
|
|
15
|
-
> _comdab_ is still in development, only tested with PostgreSQL 14 to date.
|
|
15
|
+
> _comdab_ is still in development, only tested with PostgreSQL 14 — 18 to date.
|
|
16
16
|
>
|
|
17
17
|
> All feedback and contributions are welcome!
|
|
18
18
|
|
|
@@ -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
|
|
@@ -36,7 +36,18 @@ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
|
|
36
36
|
# -- Options for HTML output -------------------------------------------------
|
|
37
37
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
38
38
|
|
|
39
|
-
html_theme = "
|
|
39
|
+
html_theme = "shibuya"
|
|
40
|
+
html_theme_options = {
|
|
41
|
+
"accent_color": "indigo",
|
|
42
|
+
"nav_links_align": "right",
|
|
43
|
+
"show_ai_links": False,
|
|
44
|
+
"github_url": "https://github.com/loic-simon/comdab",
|
|
45
|
+
}
|
|
46
|
+
html_context = {
|
|
47
|
+
"source_type": "github",
|
|
48
|
+
"source_user": "loic-simon",
|
|
49
|
+
"source_repo": "comdab",
|
|
50
|
+
}
|
|
40
51
|
|
|
41
52
|
|
|
42
53
|
# -- Extensions options ------------------------------------------------------
|
|
@@ -45,3 +56,11 @@ intersphinx_mapping = {
|
|
|
45
56
|
"python": ("https://docs.python.org/3/", None),
|
|
46
57
|
"sqlalchemy": ("https://docs.sqlalchemy.org/en/stable/", None),
|
|
47
58
|
}
|
|
59
|
+
autodoc_default_options = {
|
|
60
|
+
"members": True,
|
|
61
|
+
"undoc-members": True,
|
|
62
|
+
"member-order": "bysource",
|
|
63
|
+
"exclude-members": "__init__,Path,model_config",
|
|
64
|
+
"no-index-entry": True,
|
|
65
|
+
}
|
|
66
|
+
autodoc_class_signature = "separated"
|
|
@@ -4,16 +4,18 @@ comdab -- Compare Database Schemas
|
|
|
4
4
|
.. toctree::
|
|
5
5
|
:hidden:
|
|
6
6
|
|
|
7
|
+
Get started <self>
|
|
7
8
|
reference
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
*comdab* allows you to compare in depth two database schemas to find
|
|
11
|
-
all differences
|
|
12
|
-
slight changes in function or triggers definitions...
|
|
12
|
+
all differences (missing columns, different nullabilities or defaults,
|
|
13
|
+
slight changes in function or triggers definitions...) and turn these
|
|
14
|
+
reports into model migrations.
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
`Alembic`_
|
|
16
|
-
|
|
16
|
+
*comdab* migration generation supercharges migration tools like
|
|
17
|
+
`Alembic`_ to create migrations that, when applied to an existing database,
|
|
18
|
+
produce **the exact same schema** than a new database created from scratch.
|
|
17
19
|
|
|
18
20
|
Indeed, while migration tools can auto-detect model changes and write
|
|
19
21
|
automatically the migrations to apply to pre-existing databases, it does not
|
|
@@ -32,7 +34,7 @@ the database, and for most of schema introspection.
|
|
|
32
34
|
|
|
33
35
|
.. warning::
|
|
34
36
|
|
|
35
|
-
*comdab* is still in development, only tested with PostgreSQL 14 to date.
|
|
37
|
+
*comdab* is still in development, only tested with PostgreSQL 14 — 18 to date.
|
|
36
38
|
|
|
37
39
|
All feedback and contributions are welcome!
|
|
38
40
|
|
|
@@ -40,7 +42,7 @@ the database, and for most of schema introspection.
|
|
|
40
42
|
Requirements
|
|
41
43
|
------------
|
|
42
44
|
|
|
43
|
-
* Python >= 3.
|
|
45
|
+
* Python >= 3.13
|
|
44
46
|
* `sqlalchemy <https://pypi.org/project/sqlalchemy>`_ >= 2.0
|
|
45
47
|
* `pydantic <https://pypi.org/project/pydantic>`_ >= 2.0
|
|
46
48
|
|
|
@@ -56,7 +58,10 @@ Installation
|
|
|
56
58
|
Usage
|
|
57
59
|
-----
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
Comparing database schemas
|
|
62
|
+
**************************
|
|
63
|
+
|
|
64
|
+
*comdab* main reporting function is :func:`.compare_databases`, which needs
|
|
60
65
|
already established `SQLAlchemy connections`_ to the two databases to compare:
|
|
61
66
|
|
|
62
67
|
.. code-block:: python
|
|
@@ -68,12 +73,12 @@ already established `SQLAlchemy connections`_ to the two databases to compare:
|
|
|
68
73
|
engine_2 = create_engine("postgresql://user:pass@host/bar")
|
|
69
74
|
|
|
70
75
|
with engine_1.connect() as left_conn, engine_2.connect() as right_conn:
|
|
71
|
-
|
|
76
|
+
reports = compare_databases(left_conn, right_conn)
|
|
72
77
|
|
|
73
78
|
if reports:
|
|
74
|
-
|
|
79
|
+
print("❌ Database schemas are different:", reports)
|
|
75
80
|
else:
|
|
76
|
-
|
|
81
|
+
print("✅ Database schemas are the same!")
|
|
77
82
|
|
|
78
83
|
These connections will, of course, only be used for read-only database
|
|
79
84
|
introspection.
|
|
@@ -96,6 +101,43 @@ has to be created first in a fresh database:
|
|
|
96
101
|
reports = compare_databases(left_connection, right_connection)
|
|
97
102
|
|
|
98
103
|
|
|
104
|
+
Generating migrations
|
|
105
|
+
*********************
|
|
106
|
+
|
|
107
|
+
To generate migrations, a user-defined :class:`.MigrationGeneratorPort` /
|
|
108
|
+
:class:`.PartialMigrationGeneratorPort` subclass is additionally needed:
|
|
109
|
+
|
|
110
|
+
.. code-block:: python
|
|
111
|
+
|
|
112
|
+
from comdab import generate_migrations, PartialMigrationGeneratorPort
|
|
113
|
+
from comdab.models import ComdabTable
|
|
114
|
+
from sqlalchemy import create_engine
|
|
115
|
+
|
|
116
|
+
class MyMigrationGenerator(PartialMigrationGeneratorPort):
|
|
117
|
+
def __init__(self) -> None:
|
|
118
|
+
self.sql_text = ""
|
|
119
|
+
|
|
120
|
+
def create_table(self, *, table: ComdabTable) -> None:
|
|
121
|
+
self.sql_text += f"CREATE TABLE {table.name} [...];\n"
|
|
122
|
+
|
|
123
|
+
def drop_table(self, *, table: ComdabTable) -> None:
|
|
124
|
+
self.sql_text += f"DROP TABLE {table.name};\n"
|
|
125
|
+
|
|
126
|
+
...
|
|
127
|
+
|
|
128
|
+
generator = MyMigrationGenerator()
|
|
129
|
+
engine_1 = create_engine("postgresql://user:pass@host/source")
|
|
130
|
+
engine_2 = create_engine("postgresql://user:pass@host/target")
|
|
131
|
+
|
|
132
|
+
with engine_1.connect() as source_conn, engine_2.connect() as target_conn:
|
|
133
|
+
generate_migrations(source_conn, target_conn, generator)
|
|
134
|
+
|
|
135
|
+
print(generator.sql_text)
|
|
136
|
+
|
|
137
|
+
An `Alembic`_-based migration generator implementation might be included
|
|
138
|
+
in a future *comdab* release.
|
|
139
|
+
|
|
140
|
+
|
|
99
141
|
Supported database features
|
|
100
142
|
***************************
|
|
101
143
|
|
|
@@ -137,8 +179,9 @@ Ignore rules
|
|
|
137
179
|
.. _ignorerules:
|
|
138
180
|
|
|
139
181
|
*comdab* comes with a powerful system to allow some specific differences
|
|
140
|
-
between the two schemas. :func:`.
|
|
141
|
-
:func:`.
|
|
182
|
+
between the two schemas. :func:`.generate_migrations`,
|
|
183
|
+
:func:`.build_comdab_schema` and :func:`.compare_databases`
|
|
184
|
+
functions take a ``rules`` argument, where you
|
|
142
185
|
can specifies *paths* to be ignored or reported as warnings.
|
|
143
186
|
|
|
144
187
|
These are a mapping of model path (build from :attr:`comdab.ROOT`) to
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
:tocdepth: 3
|
|
2
|
+
|
|
3
|
+
API Reference
|
|
4
|
+
=============
|
|
5
|
+
|
|
6
|
+
Entry points
|
|
7
|
+
------------
|
|
8
|
+
|
|
9
|
+
.. automodule:: comdab
|
|
10
|
+
:members:
|
|
11
|
+
:exclude-members: PartialMigrationGeneratorPort
|
|
12
|
+
|
|
13
|
+
.. class:: comdab.PartialMigrationGeneratorPort
|
|
14
|
+
|
|
15
|
+
Like :class:`.MigrationGeneratorPort`, but does not require all migration methods to be implemented.
|
|
16
|
+
|
|
17
|
+
By default, :exc:`NotImplementedError` will be raised if a missing method is called;
|
|
18
|
+
to silently do nothing instead, use ``class MyGenerator(PartialMigrationGeneratorPort, strict=False)``.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Reports
|
|
22
|
+
-------
|
|
23
|
+
|
|
24
|
+
.. automodule:: comdab.report
|
|
25
|
+
:members:
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Models
|
|
29
|
+
------
|
|
30
|
+
|
|
31
|
+
.. automodule:: comdab.models
|
|
32
|
+
:members:
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Exceptions
|
|
36
|
+
----------
|
|
37
|
+
|
|
38
|
+
.. automodule:: comdab.exceptions
|
|
39
|
+
:members:
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "comdab"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.1"
|
|
4
4
|
description = "Compare Database Schemas"
|
|
5
5
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
7
|
dependencies = ["pydantic>=2.0", "sqlalchemy>=2.0"]
|
|
8
8
|
authors = [{ name = "Loïc Simon", email = "loic.simon@espci.org" }]
|
|
9
9
|
classifiers = [
|
|
10
10
|
"Development Status :: 4 - Beta",
|
|
11
11
|
"Intended Audience :: Developers",
|
|
12
12
|
"Programming Language :: Python :: 3",
|
|
13
|
-
"Programming Language :: Python :: 3.12",
|
|
14
13
|
"Programming Language :: Python :: 3.13",
|
|
15
14
|
"Programming Language :: Python :: 3.14",
|
|
15
|
+
"Programming Language :: Python :: 3.15",
|
|
16
16
|
"Typing :: Typed",
|
|
17
17
|
"Topic :: Database"
|
|
18
18
|
]
|
|
@@ -32,10 +32,14 @@ dev = [
|
|
|
32
32
|
"psycopg2>=2.9.10",
|
|
33
33
|
"pytest>=8.4.0",
|
|
34
34
|
"ruff>=0.11.11",
|
|
35
|
+
]
|
|
36
|
+
docs = [
|
|
37
|
+
"shibuya>=2026.5.19",
|
|
35
38
|
"sphinx>=8.2.3",
|
|
36
39
|
]
|
|
37
40
|
|
|
38
41
|
[tool.ruff]
|
|
42
|
+
target-version = "py313"
|
|
39
43
|
line-length = 120
|
|
40
44
|
|
|
41
45
|
[tool.ruff.lint]
|
|
@@ -43,7 +47,14 @@ select = ["E", "F", "UP", "B", "SIM", "I"]
|
|
|
43
47
|
|
|
44
48
|
[tool.pyright]
|
|
45
49
|
typeCheckingMode = "strict"
|
|
50
|
+
pythonVersion = "3.13"
|
|
46
51
|
venvPath = "."
|
|
47
52
|
venv = ".venv"
|
|
48
53
|
reportUnknownArgumentType = false
|
|
49
54
|
reportUnknownMemberType = false
|
|
55
|
+
|
|
56
|
+
[tool.pytest]
|
|
57
|
+
filterwarnings = [
|
|
58
|
+
"error",
|
|
59
|
+
"ignore:.+can't locate any SQLAlchemy dialect:sqlalchemy.exc.SAWarning"
|
|
60
|
+
]
|
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
Loïc Simon 2025, MIT License
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
from comdab.main import
|
|
6
|
+
from comdab.main import (
|
|
7
|
+
build_comdab_schema,
|
|
8
|
+
compare_comdab_schemas,
|
|
9
|
+
compare_databases,
|
|
10
|
+
generate_migrations,
|
|
11
|
+
generate_migrations_from_reports,
|
|
12
|
+
)
|
|
13
|
+
from comdab.migrate import MigrationGeneratorPort, PartialMigrationGeneratorPort
|
|
7
14
|
from comdab.models import ROOT
|
|
8
15
|
|
|
9
16
|
#: The top-level *comdab* path, pointing to a whole :class:`ComdabSchema`.
|
|
@@ -18,8 +25,12 @@ ROOT = ROOT # pyright: ignore[reportConstantRedefinition] # Only here for Sphi
|
|
|
18
25
|
|
|
19
26
|
|
|
20
27
|
__all__ = [
|
|
28
|
+
"generate_migrations",
|
|
21
29
|
"compare_databases",
|
|
22
30
|
"build_comdab_schema",
|
|
23
31
|
"compare_comdab_schemas",
|
|
32
|
+
"generate_migrations_from_reports",
|
|
24
33
|
"ROOT",
|
|
34
|
+
"MigrationGeneratorPort",
|
|
35
|
+
"PartialMigrationGeneratorPort",
|
|
25
36
|
]
|
|
@@ -5,7 +5,8 @@ class ComdabException(Exception):
|
|
|
5
5
|
class UnhandledTypeError(ComdabException):
|
|
6
6
|
"""A SQL type not handled by comdab was encountered.
|
|
7
7
|
|
|
8
|
-
Consider passing
|
|
8
|
+
Consider passing ``allow_unknown_types=True``, or opening a feature request!
|
|
9
|
+
"""
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class OverlappingPathsError(ComdabException):
|
|
@@ -15,4 +16,5 @@ class OverlappingPathsError(ComdabException):
|
|
|
15
16
|
class ComdabInternalError(ComdabException):
|
|
16
17
|
"""Something unexpected happened!
|
|
17
18
|
|
|
18
|
-
If it escapes comdab internals, please report a bug.
|
|
19
|
+
If it escapes comdab internals, please report a bug.
|
|
20
|
+
"""
|