migradiff 1.1.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.
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
@@ -0,0 +1,291 @@
1
+ Metadata-Version: 2.4
2
+ Name: migradiff
3
+ Version: 1.1.0
4
+ Summary: Like `diff` but for PostgreSQL schemas — actively maintained fork
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: MigraDiff Team
8
+ Author-email: migradiff@anomalyco.com
9
+ Requires-Python: >=3.7,<4
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.7
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Provides-Extra: pg
21
+ Requires-Dist: psycopg2-binary ; extra == "pg"
22
+ Requires-Dist: schemainspect (>=3.1.1663480743)
23
+ Requires-Dist: six
24
+ Requires-Dist: sqlbag
25
+ Project-URL: Homepage, https://github.com/migradiff/migra
26
+ Project-URL: Repository, https://github.com/migradiff/migra
27
+ Description-Content-Type: text/markdown
28
+
29
+ # migra — PostgreSQL Schema Diff Tool
30
+
31
+ [![PyPI version](https://img.shields.io/pypi/v/migradiff)](https://pypi.org/project/migradiff/)
32
+ [![Python versions](https://img.shields.io/pypi/pyversions/migradiff)](https://pypi.org/project/migradiff/)
33
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
34
+
35
+ **The actively maintained fork of [djrobstep/migra](https://github.com/djrobstep/migra).**
36
+
37
+ migra compares two PostgreSQL database schemas and generates the SQL
38
+ migration script needed to transform one into the other. Drop it into
39
+ your CI pipeline and stop writing `ALTER TABLE` by hand.
40
+
41
+ ---
42
+
43
+ ## Why This Fork
44
+
45
+ The original `migra` was officially deprecated in 2024. This fork picks
46
+ up where it left off — fixing known issues, adding Python 3.12+ support,
47
+ and extending coverage for advanced PostgreSQL features.
48
+
49
+ If you were using `djrobstep/migra`, this is your drop-in continuation.
50
+ Nothing has changed about how the tool works. We're just keeping the
51
+ lights on and making it better.
52
+
53
+ ---
54
+
55
+ ## Quickstart
56
+
57
+ ### Install
58
+
59
+ ```bash
60
+ pip install migradiff
61
+ ```
62
+
63
+ Requires Python 3.10+ and a running PostgreSQL instance (12+).
64
+
65
+ To install from source:
66
+
67
+ ```bash
68
+ git clone https://github.com/migradiff/migra
69
+ cd migra
70
+ pip install -e .
71
+ ```
72
+
73
+ > **Note:** PyPI package coming with v1.1.0.
74
+
75
+ ### Basic Usage
76
+
77
+ Point migra at two database connections and it outputs the DDL needed
78
+ to migrate from one to the other:
79
+
80
+ ```bash
81
+ migra \
82
+ postgresql://user:pass@localhost/db_production \
83
+ postgresql://user:pass@localhost/db_branch \
84
+ --unsafe
85
+ ```
86
+
87
+ Output is plain SQL — pipe it, review it, apply it:
88
+
89
+ ```bash
90
+ migra postgres://db_a postgres://db_b > migration.sql
91
+ psql postgres://db_production < migration.sql
92
+ ```
93
+
94
+ ### Schema Dumps (No Live Connection Required)
95
+
96
+ If you can't or don't want to point migra at a live database, use
97
+ `pg_dump -s` to generate a schema dump and diff that instead:
98
+
99
+ ```bash
100
+ pg_dump -s postgres://db_production > schema_a.sql
101
+ pg_dump -s postgres://db_branch > schema_b.sql
102
+ migra --from-file schema_a.sql schema_b.sql
103
+ ```
104
+
105
+ This is the recommended approach for CI pipelines and security-conscious
106
+ environments — no production credentials required.
107
+
108
+ ### Scoped to a Schema
109
+
110
+ ```bash
111
+ # Single schema
112
+ migra --schema myschema postgres://db_a postgres://db_b
113
+
114
+ # Multiple schemas (comma-separated)
115
+ migra --schema public,reporting postgres://db_a postgres://db_b
116
+ ```
117
+
118
+ ### JSON Output
119
+
120
+ For programmatic consumption or CI pipelines:
121
+
122
+ ```bash
123
+ migra --output json postgres://db_a postgres://db_b
124
+ ```
125
+
126
+ Output includes per-statement risk classification (`safe`, `warning`,
127
+ `destructive`) and a summary with overall risk level.
128
+
129
+ ---
130
+
131
+ ## Development Setup
132
+
133
+ The test suite requires a running PostgreSQL instance. The easiest
134
+ way to get one is via Docker Compose:
135
+
136
+ ```bash
137
+ docker compose up -d
138
+ ```
139
+
140
+ This starts a Postgres 16 container on localhost:5432 with trust
141
+ authentication. No password required.
142
+
143
+ To stop it:
144
+
145
+ ```bash
146
+ docker compose down
147
+ ```
148
+
149
+ Data persists between restarts via the `migradiff-pgdata` volume.
150
+ To reset completely:
151
+
152
+ ```bash
153
+ docker compose down -v
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Docker
159
+
160
+ No Python environment? Use the official image:
161
+
162
+ ```bash
163
+ docker run --rm ghcr.io/migradiff/migra \
164
+ postgres://db_a postgres://db_b
165
+ ```
166
+
167
+ ---
168
+
169
+ ## GitHub Actions
170
+
171
+ Add schema diffing to your pull request workflow:
172
+
173
+ ```yaml
174
+ - uses: migradiff/migra@v1
175
+ with:
176
+ base_url: ${{ secrets.DB_PRODUCTION_URL }}
177
+ head_url: ${{ secrets.DB_BRANCH_URL }}
178
+ ```
179
+
180
+ Fail the build automatically if destructive operations are detected:
181
+
182
+ ```yaml
183
+ - uses: migradiff/migra@v1
184
+ with:
185
+ base_url: ${{ secrets.DB_PRODUCTION_URL }}
186
+ head_url: ${{ secrets.DB_BRANCH_URL }}
187
+ fail_on_destructive: "true"
188
+ ```
189
+
190
+ Use schema dump files instead of live connections:
191
+
192
+ ```yaml
193
+ - uses: migradiff/migra@v1
194
+ with:
195
+ base_file: schema_production.sql
196
+ head_file: schema_branch.sql
197
+ ```
198
+
199
+ See [docs/action-usage.md](docs/action-usage.md) for full configuration options.
200
+
201
+ ---
202
+
203
+ ## Pre-commit Hook
204
+
205
+ ```yaml
206
+ # .pre-commit-config.yaml
207
+ repos:
208
+ - repo: https://github.com/migradiff/migra
209
+ rev: v1.1.0
210
+ hooks:
211
+ - id: migra
212
+ ```
213
+
214
+ See `pre-commit-config.example.yaml` in the repo root for full
215
+ configuration options.
216
+
217
+ ---
218
+
219
+ ## What migra Understands
220
+
221
+ - Tables, columns, constraints, indexes
222
+ - Views and materialized views
223
+ - Functions and stored procedures
224
+ - Sequences
225
+ - Enums, composite types, domains
226
+ - Row-Level Security (RLS) policies
227
+ - Foreign data wrappers
228
+ - Column-level privileges
229
+ - Partitioned tables
230
+
231
+ ---
232
+
233
+ ## Improvements Over Upstream
234
+
235
+ | Area | Upstream (deprecated) | This Fork |
236
+ |---|---|---|
237
+ | Python 3.12+ | Deprecation warnings | Clean — no warnings |
238
+ | RLS policies | Partial, equality bug | Full CREATE/DROP, partition support |
239
+ | Error messages | Cryptic on unsupported types | Actionable with object name and issue link |
240
+ | --schema flag | Edge cases in multi-schema DBs | Comma-separated, cross-schema dependencies resolved |
241
+ | pg_dump input | Not supported | First-class `--from-file` mode |
242
+ | JSON output | Not supported | `--output json` with risk classification |
243
+ | Docker image | None | `ghcr.io/migradiff/migra` |
244
+ | GitHub Action | None | `migradiff/migra-action` |
245
+ | Pre-commit hook | None | `.pre-commit-hooks.yaml` |
246
+ | Dev environment | Manual Docker commands | `docker compose up -d` |
247
+
248
+ See [CHANGELOG.md](CHANGELOG.md) for the full fix history.
249
+
250
+ ---
251
+
252
+ ## Known Limitations
253
+
254
+ migra generates the SQL diff — it does not apply it. Review every
255
+ generated script before running against production. Destructive
256
+ operations (`DROP TABLE`, `DROP COLUMN`) are flagged in JSON output
257
+ mode but not blocked in plain SQL mode.
258
+
259
+ migra requires a live PostgreSQL connection to introspect schemas,
260
+ or schema dump files via `--from-file`. It does not parse raw DDL text.
261
+
262
+ ---
263
+
264
+ ## Contributing
265
+
266
+ Bug reports and PRs are welcome. If you're fixing something that was
267
+ reported upstream in `djrobstep/migra`, reference that issue number
268
+ in your PR — it helps us track what the community most needs fixed.
269
+
270
+ ```bash
271
+ git clone https://github.com/migradiff/migra
272
+ cd migra
273
+ docker compose up -d
274
+ pip install -e ".[dev]"
275
+ pytest
276
+ ```
277
+
278
+ ---
279
+
280
+ ## License
281
+
282
+ MIT. See [LICENSE](LICENSE).
283
+
284
+ ---
285
+
286
+ ## Acknowledgements
287
+
288
+ This project is a fork of [djrobstep/migra](https://github.com/djrobstep/migra),
289
+ created and originally maintained by Robert Lechte. The core diffing
290
+ engine is his work. We are grateful for it.
291
+
@@ -0,0 +1,262 @@
1
+ # migra — PostgreSQL Schema Diff Tool
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/migradiff)](https://pypi.org/project/migradiff/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/migradiff)](https://pypi.org/project/migradiff/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ **The actively maintained fork of [djrobstep/migra](https://github.com/djrobstep/migra).**
8
+
9
+ migra compares two PostgreSQL database schemas and generates the SQL
10
+ migration script needed to transform one into the other. Drop it into
11
+ your CI pipeline and stop writing `ALTER TABLE` by hand.
12
+
13
+ ---
14
+
15
+ ## Why This Fork
16
+
17
+ The original `migra` was officially deprecated in 2024. This fork picks
18
+ up where it left off — fixing known issues, adding Python 3.12+ support,
19
+ and extending coverage for advanced PostgreSQL features.
20
+
21
+ If you were using `djrobstep/migra`, this is your drop-in continuation.
22
+ Nothing has changed about how the tool works. We're just keeping the
23
+ lights on and making it better.
24
+
25
+ ---
26
+
27
+ ## Quickstart
28
+
29
+ ### Install
30
+
31
+ ```bash
32
+ pip install migradiff
33
+ ```
34
+
35
+ Requires Python 3.10+ and a running PostgreSQL instance (12+).
36
+
37
+ To install from source:
38
+
39
+ ```bash
40
+ git clone https://github.com/migradiff/migra
41
+ cd migra
42
+ pip install -e .
43
+ ```
44
+
45
+ > **Note:** PyPI package coming with v1.1.0.
46
+
47
+ ### Basic Usage
48
+
49
+ Point migra at two database connections and it outputs the DDL needed
50
+ to migrate from one to the other:
51
+
52
+ ```bash
53
+ migra \
54
+ postgresql://user:pass@localhost/db_production \
55
+ postgresql://user:pass@localhost/db_branch \
56
+ --unsafe
57
+ ```
58
+
59
+ Output is plain SQL — pipe it, review it, apply it:
60
+
61
+ ```bash
62
+ migra postgres://db_a postgres://db_b > migration.sql
63
+ psql postgres://db_production < migration.sql
64
+ ```
65
+
66
+ ### Schema Dumps (No Live Connection Required)
67
+
68
+ If you can't or don't want to point migra at a live database, use
69
+ `pg_dump -s` to generate a schema dump and diff that instead:
70
+
71
+ ```bash
72
+ pg_dump -s postgres://db_production > schema_a.sql
73
+ pg_dump -s postgres://db_branch > schema_b.sql
74
+ migra --from-file schema_a.sql schema_b.sql
75
+ ```
76
+
77
+ This is the recommended approach for CI pipelines and security-conscious
78
+ environments — no production credentials required.
79
+
80
+ ### Scoped to a Schema
81
+
82
+ ```bash
83
+ # Single schema
84
+ migra --schema myschema postgres://db_a postgres://db_b
85
+
86
+ # Multiple schemas (comma-separated)
87
+ migra --schema public,reporting postgres://db_a postgres://db_b
88
+ ```
89
+
90
+ ### JSON Output
91
+
92
+ For programmatic consumption or CI pipelines:
93
+
94
+ ```bash
95
+ migra --output json postgres://db_a postgres://db_b
96
+ ```
97
+
98
+ Output includes per-statement risk classification (`safe`, `warning`,
99
+ `destructive`) and a summary with overall risk level.
100
+
101
+ ---
102
+
103
+ ## Development Setup
104
+
105
+ The test suite requires a running PostgreSQL instance. The easiest
106
+ way to get one is via Docker Compose:
107
+
108
+ ```bash
109
+ docker compose up -d
110
+ ```
111
+
112
+ This starts a Postgres 16 container on localhost:5432 with trust
113
+ authentication. No password required.
114
+
115
+ To stop it:
116
+
117
+ ```bash
118
+ docker compose down
119
+ ```
120
+
121
+ Data persists between restarts via the `migradiff-pgdata` volume.
122
+ To reset completely:
123
+
124
+ ```bash
125
+ docker compose down -v
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Docker
131
+
132
+ No Python environment? Use the official image:
133
+
134
+ ```bash
135
+ docker run --rm ghcr.io/migradiff/migra \
136
+ postgres://db_a postgres://db_b
137
+ ```
138
+
139
+ ---
140
+
141
+ ## GitHub Actions
142
+
143
+ Add schema diffing to your pull request workflow:
144
+
145
+ ```yaml
146
+ - uses: migradiff/migra@v1
147
+ with:
148
+ base_url: ${{ secrets.DB_PRODUCTION_URL }}
149
+ head_url: ${{ secrets.DB_BRANCH_URL }}
150
+ ```
151
+
152
+ Fail the build automatically if destructive operations are detected:
153
+
154
+ ```yaml
155
+ - uses: migradiff/migra@v1
156
+ with:
157
+ base_url: ${{ secrets.DB_PRODUCTION_URL }}
158
+ head_url: ${{ secrets.DB_BRANCH_URL }}
159
+ fail_on_destructive: "true"
160
+ ```
161
+
162
+ Use schema dump files instead of live connections:
163
+
164
+ ```yaml
165
+ - uses: migradiff/migra@v1
166
+ with:
167
+ base_file: schema_production.sql
168
+ head_file: schema_branch.sql
169
+ ```
170
+
171
+ See [docs/action-usage.md](docs/action-usage.md) for full configuration options.
172
+
173
+ ---
174
+
175
+ ## Pre-commit Hook
176
+
177
+ ```yaml
178
+ # .pre-commit-config.yaml
179
+ repos:
180
+ - repo: https://github.com/migradiff/migra
181
+ rev: v1.1.0
182
+ hooks:
183
+ - id: migra
184
+ ```
185
+
186
+ See `pre-commit-config.example.yaml` in the repo root for full
187
+ configuration options.
188
+
189
+ ---
190
+
191
+ ## What migra Understands
192
+
193
+ - Tables, columns, constraints, indexes
194
+ - Views and materialized views
195
+ - Functions and stored procedures
196
+ - Sequences
197
+ - Enums, composite types, domains
198
+ - Row-Level Security (RLS) policies
199
+ - Foreign data wrappers
200
+ - Column-level privileges
201
+ - Partitioned tables
202
+
203
+ ---
204
+
205
+ ## Improvements Over Upstream
206
+
207
+ | Area | Upstream (deprecated) | This Fork |
208
+ |---|---|---|
209
+ | Python 3.12+ | Deprecation warnings | Clean — no warnings |
210
+ | RLS policies | Partial, equality bug | Full CREATE/DROP, partition support |
211
+ | Error messages | Cryptic on unsupported types | Actionable with object name and issue link |
212
+ | --schema flag | Edge cases in multi-schema DBs | Comma-separated, cross-schema dependencies resolved |
213
+ | pg_dump input | Not supported | First-class `--from-file` mode |
214
+ | JSON output | Not supported | `--output json` with risk classification |
215
+ | Docker image | None | `ghcr.io/migradiff/migra` |
216
+ | GitHub Action | None | `migradiff/migra-action` |
217
+ | Pre-commit hook | None | `.pre-commit-hooks.yaml` |
218
+ | Dev environment | Manual Docker commands | `docker compose up -d` |
219
+
220
+ See [CHANGELOG.md](CHANGELOG.md) for the full fix history.
221
+
222
+ ---
223
+
224
+ ## Known Limitations
225
+
226
+ migra generates the SQL diff — it does not apply it. Review every
227
+ generated script before running against production. Destructive
228
+ operations (`DROP TABLE`, `DROP COLUMN`) are flagged in JSON output
229
+ mode but not blocked in plain SQL mode.
230
+
231
+ migra requires a live PostgreSQL connection to introspect schemas,
232
+ or schema dump files via `--from-file`. It does not parse raw DDL text.
233
+
234
+ ---
235
+
236
+ ## Contributing
237
+
238
+ Bug reports and PRs are welcome. If you're fixing something that was
239
+ reported upstream in `djrobstep/migra`, reference that issue number
240
+ in your PR — it helps us track what the community most needs fixed.
241
+
242
+ ```bash
243
+ git clone https://github.com/migradiff/migra
244
+ cd migra
245
+ docker compose up -d
246
+ pip install -e ".[dev]"
247
+ pytest
248
+ ```
249
+
250
+ ---
251
+
252
+ ## License
253
+
254
+ MIT. See [LICENSE](LICENSE).
255
+
256
+ ---
257
+
258
+ ## Acknowledgements
259
+
260
+ This project is a fork of [djrobstep/migra](https://github.com/djrobstep/migra),
261
+ created and originally maintained by Robert Lechte. The core diffing
262
+ engine is his work. We are grateful for it.
@@ -0,0 +1,16 @@
1
+ from __future__ import unicode_literals
2
+
3
+ __version__ = "1.1.0"
4
+
5
+ from .changes import Changes
6
+ from .command import do_command
7
+ from .migra import Migration
8
+ from .statements import Statements, UnsafeMigrationException
9
+
10
+ __all__ = [
11
+ "Migration",
12
+ "Changes",
13
+ "Statements",
14
+ "UnsafeMigrationException",
15
+ "do_command",
16
+ ]