mongomig 0.1.0.dev0__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.
- mongomig-0.1.0.dev0/.github/workflows/ci.yml +57 -0
- mongomig-0.1.0.dev0/.github/workflows/release.yml +58 -0
- mongomig-0.1.0.dev0/.gitignore +218 -0
- mongomig-0.1.0.dev0/CHANGELOG.md +16 -0
- mongomig-0.1.0.dev0/LICENSE +21 -0
- mongomig-0.1.0.dev0/Makefile +33 -0
- mongomig-0.1.0.dev0/PKG-INFO +177 -0
- mongomig-0.1.0.dev0/README.md +140 -0
- mongomig-0.1.0.dev0/docker-compose.yml +33 -0
- mongomig-0.1.0.dev0/pyproject.toml +85 -0
- mongomig-0.1.0.dev0/src/mongomig/__init__.py +26 -0
- mongomig-0.1.0.dev0/src/mongomig/__main__.py +4 -0
- mongomig-0.1.0.dev0/src/mongomig/_version.py +1 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/__init__.py +0 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/app.py +135 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/commands/__init__.py +0 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/commands/current.py +72 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/commands/heads.py +40 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/commands/history.py +48 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/commands/init.py +71 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/commands/revision.py +41 -0
- mongomig-0.1.0.dev0/src/mongomig/cli/context.py +47 -0
- mongomig-0.1.0.dev0/src/mongomig/config/__init__.py +0 -0
- mongomig-0.1.0.dev0/src/mongomig/config/envpy.py +58 -0
- mongomig-0.1.0.dev0/src/mongomig/config/loader.py +178 -0
- mongomig-0.1.0.dev0/src/mongomig/config/models.py +87 -0
- mongomig-0.1.0.dev0/src/mongomig/database/__init__.py +0 -0
- mongomig-0.1.0.dev0/src/mongomig/database/client.py +82 -0
- mongomig-0.1.0.dev0/src/mongomig/database/redact.py +70 -0
- mongomig-0.1.0.dev0/src/mongomig/errors.py +108 -0
- mongomig-0.1.0.dev0/src/mongomig/migrations/__init__.py +0 -0
- mongomig-0.1.0.dev0/src/mongomig/migrations/graph.py +161 -0
- mongomig-0.1.0.dev0/src/mongomig/migrations/revision.py +107 -0
- mongomig-0.1.0.dev0/src/mongomig/migrations/script.py +198 -0
- mongomig-0.1.0.dev0/src/mongomig/migrations/tracker.py +149 -0
- mongomig-0.1.0.dev0/src/mongomig/output/__init__.py +0 -0
- mongomig-0.1.0.dev0/src/mongomig/output/console.py +88 -0
- mongomig-0.1.0.dev0/src/mongomig/py.typed +0 -0
- mongomig-0.1.0.dev0/src/mongomig/schema/__init__.py +0 -0
- mongomig-0.1.0.dev0/src/mongomig/schema/snapshot.py +35 -0
- mongomig-0.1.0.dev0/src/mongomig/templates/env.py.tmpl +18 -0
- mongomig-0.1.0.dev0/src/mongomig/templates/mongomig.yaml.tmpl +25 -0
- mongomig-0.1.0.dev0/src/mongomig/templates/revision.py.tmpl +22 -0
- mongomig-0.1.0.dev0/tests/__init__.py +0 -0
- mongomig-0.1.0.dev0/tests/conftest.py +19 -0
- mongomig-0.1.0.dev0/tests/helpers.py +36 -0
- mongomig-0.1.0.dev0/tests/integration/__init__.py +0 -0
- mongomig-0.1.0.dev0/tests/integration/conftest.py +51 -0
- mongomig-0.1.0.dev0/tests/integration/test_current_cli.py +86 -0
- mongomig-0.1.0.dev0/tests/integration/test_tracker.py +56 -0
- mongomig-0.1.0.dev0/tests/unit/__init__.py +0 -0
- mongomig-0.1.0.dev0/tests/unit/test_cli.py +159 -0
- mongomig-0.1.0.dev0/tests/unit/test_config.py +125 -0
- mongomig-0.1.0.dev0/tests/unit/test_envpy.py +49 -0
- mongomig-0.1.0.dev0/tests/unit/test_graph.py +123 -0
- mongomig-0.1.0.dev0/tests/unit/test_redact.py +61 -0
- mongomig-0.1.0.dev0/tests/unit/test_revision_and_script.py +153 -0
- mongomig-0.1.0.dev0/tests/unit/test_tracker_state.py +49 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: astral-sh/setup-uv@v6
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
- run: uv venv && uv pip install -e ".[dev]"
|
|
21
|
+
- run: .venv/bin/ruff check src tests
|
|
22
|
+
- run: .venv/bin/ruff format --check src tests
|
|
23
|
+
- run: .venv/bin/mypy
|
|
24
|
+
|
|
25
|
+
unit:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
strategy:
|
|
28
|
+
fail-fast: false
|
|
29
|
+
matrix:
|
|
30
|
+
python: ["3.11", "3.12", "3.13"]
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
- uses: astral-sh/setup-uv@v6
|
|
34
|
+
with:
|
|
35
|
+
python-version: ${{ matrix.python }}
|
|
36
|
+
- run: uv venv && uv pip install -e ".[dev]"
|
|
37
|
+
- run: .venv/bin/pytest tests/unit --cov=mongomig --cov-report=term-missing
|
|
38
|
+
|
|
39
|
+
integration:
|
|
40
|
+
runs-on: ubuntu-latest
|
|
41
|
+
strategy:
|
|
42
|
+
fail-fast: false
|
|
43
|
+
matrix:
|
|
44
|
+
mongo: ["6.0", "7.0", "8.0"]
|
|
45
|
+
env:
|
|
46
|
+
MONGO_VERSION: ${{ matrix.mongo }}
|
|
47
|
+
MONGOMIG_REQUIRE_MONGO: "1"
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v4
|
|
50
|
+
- uses: astral-sh/setup-uv@v6
|
|
51
|
+
with:
|
|
52
|
+
python-version: "3.12"
|
|
53
|
+
- run: docker compose up -d --wait
|
|
54
|
+
- run: uv venv && uv pip install -e ".[dev]"
|
|
55
|
+
- run: .venv/bin/pytest tests/integration -m integration
|
|
56
|
+
- if: failure()
|
|
57
|
+
run: docker compose logs mongo
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Publishes to PyPI when a GitHub Release is published.
|
|
4
|
+
# Uses PyPI Trusted Publishing (OIDC): no API tokens are stored in the repo.
|
|
5
|
+
# One-time setup: add a "pending publisher" on pypi.org for this repo,
|
|
6
|
+
# workflow `release.yml`, environment `pypi`.
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: astral-sh/setup-uv@v6
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
|
|
21
|
+
- name: Check release tag matches package version
|
|
22
|
+
run: |
|
|
23
|
+
TAG="${GITHUB_REF_NAME#v}"
|
|
24
|
+
VERSION=$(python -c "exec(open('src/mongomig/_version.py').read()); print(__version__)")
|
|
25
|
+
if [ "$TAG" != "$VERSION" ]; then
|
|
26
|
+
echo "::error::Release tag v$TAG does not match _version.py ($VERSION)"
|
|
27
|
+
exit 1
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
- name: Build sdist and wheel
|
|
31
|
+
run: uv build
|
|
32
|
+
|
|
33
|
+
- name: Smoke-test the built wheel
|
|
34
|
+
run: |
|
|
35
|
+
uv venv /tmp/smoke
|
|
36
|
+
uv pip install --python /tmp/smoke dist/*.whl
|
|
37
|
+
/tmp/smoke/bin/mongomig --version
|
|
38
|
+
cd "$(mktemp -d)" && /tmp/smoke/bin/mongomig init && /tmp/smoke/bin/mongomig history
|
|
39
|
+
|
|
40
|
+
- uses: actions/upload-artifact@v4
|
|
41
|
+
with:
|
|
42
|
+
name: dist
|
|
43
|
+
path: dist/
|
|
44
|
+
|
|
45
|
+
publish:
|
|
46
|
+
needs: build
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
environment:
|
|
49
|
+
name: pypi
|
|
50
|
+
url: https://pypi.org/p/mongomig
|
|
51
|
+
permissions:
|
|
52
|
+
id-token: write # required for Trusted Publishing
|
|
53
|
+
steps:
|
|
54
|
+
- uses: actions/download-artifact@v4
|
|
55
|
+
with:
|
|
56
|
+
name: dist
|
|
57
|
+
path: dist/
|
|
58
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Project foundation (Milestone 1): packaging, CLI, configuration with `${VAR}` interpolation
|
|
11
|
+
and environment overlays, credential redaction, MongoDB connection handling.
|
|
12
|
+
- Revision files with random 12-hex ids, AST-based loading (no code execution for offline
|
|
13
|
+
commands), checksums, and a revision graph with heads, branches, merges, prefix resolution.
|
|
14
|
+
- Migration tracking collection (`__mongomig_migrations`).
|
|
15
|
+
- Commands: `init`, `revision`, `heads`, `history`, `current`; `--json` output everywhere.
|
|
16
|
+
- Docker Compose MongoDB (single-node replica set) and CI for Python 3.11–3.13 × MongoDB 6/7/8.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aurosmruti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.PHONY: install lint format typecheck test test-unit test-integration check mongo-up mongo-down
|
|
2
|
+
|
|
3
|
+
install: ## Create .venv and install mongomig with dev extras (needs uv)
|
|
4
|
+
uv venv --python 3.12 .venv
|
|
5
|
+
uv pip install -e ".[dev]"
|
|
6
|
+
|
|
7
|
+
lint:
|
|
8
|
+
.venv/bin/ruff check src tests
|
|
9
|
+
.venv/bin/ruff format --check src tests
|
|
10
|
+
|
|
11
|
+
format:
|
|
12
|
+
.venv/bin/ruff check --fix src tests
|
|
13
|
+
.venv/bin/ruff format src tests
|
|
14
|
+
|
|
15
|
+
typecheck:
|
|
16
|
+
.venv/bin/mypy
|
|
17
|
+
|
|
18
|
+
test: ## All tests (integration tests skip if MongoDB is not running)
|
|
19
|
+
.venv/bin/pytest
|
|
20
|
+
|
|
21
|
+
test-unit:
|
|
22
|
+
.venv/bin/pytest tests/unit
|
|
23
|
+
|
|
24
|
+
test-integration: ## Requires `make mongo-up`
|
|
25
|
+
MONGOMIG_REQUIRE_MONGO=1 .venv/bin/pytest tests/integration
|
|
26
|
+
|
|
27
|
+
check: lint typecheck test
|
|
28
|
+
|
|
29
|
+
mongo-up:
|
|
30
|
+
docker compose up -d --wait
|
|
31
|
+
|
|
32
|
+
mongo-down:
|
|
33
|
+
docker compose down -v
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mongomig
|
|
3
|
+
Version: 0.1.0.dev0
|
|
4
|
+
Summary: Alembic-style schema evolution and migrations for MongoDB.
|
|
5
|
+
Project-URL: Homepage, https://github.com/anon-000/mongomig
|
|
6
|
+
Project-URL: Issues, https://github.com/anon-000/mongomig/issues
|
|
7
|
+
Author: aurosmruti
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: alembic,fastapi,migrations,mongodb,pydantic,pymongo,schema
|
|
11
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: pydantic>=2.6
|
|
24
|
+
Requires-Dist: pymongo>=4.6
|
|
25
|
+
Requires-Dist: pyyaml>=6.0
|
|
26
|
+
Requires-Dist: rich>=13.7
|
|
27
|
+
Requires-Dist: typer>=0.12
|
|
28
|
+
Provides-Extra: beanie
|
|
29
|
+
Requires-Dist: beanie>=1.26; extra == 'beanie'
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
35
|
+
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# MongoMig
|
|
39
|
+
|
|
40
|
+
**Alembic-style schema evolution and migrations for MongoDB.**
|
|
41
|
+
|
|
42
|
+
Built for Python services (FastAPI, Flask, workers) on PyMongo, Motor or Beanie.
|
|
43
|
+
|
|
44
|
+
> **Status: pre-alpha.** Milestone 1 (foundation) is done. Running migrations (`upgrade` /
|
|
45
|
+
> `downgrade`), schema diff and autogenerate are coming next. See the roadmap below.
|
|
46
|
+
|
|
47
|
+
```console
|
|
48
|
+
$ mongomig init
|
|
49
|
+
$ mongomig revision -m "add user profile"
|
|
50
|
+
Created revision 7be204a1c9e0 → migrations/versions/20260924_1432_7be204a1c9e0_add_user_profile.py
|
|
51
|
+
|
|
52
|
+
$ mongomig history
|
|
53
|
+
a1f3c9d20b44 -> 7be204a1c9e0 (head), add user profile
|
|
54
|
+
<base> -> a1f3c9d20b44, initial
|
|
55
|
+
|
|
56
|
+
$ mongomig current
|
|
57
|
+
Database: app
|
|
58
|
+
Current: a1f3c9d20b44 initial
|
|
59
|
+
Pending: 1
|
|
60
|
+
- 7be204a1c9e0 add user profile
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Install
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install mongomig # not yet published — install from source for now
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Requires Python 3.11+ and MongoDB 6.0+.
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
mongomig init # creates mongomig.yaml + migrations/
|
|
75
|
+
export MONGODB_URI="mongodb://localhost:27017"
|
|
76
|
+
mongomig revision -m "initial" # new revision file
|
|
77
|
+
mongomig current # what's applied vs pending
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`mongomig init` creates:
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
mongomig.yaml # connection + execution settings (no secrets!)
|
|
84
|
+
migrations/
|
|
85
|
+
├── env.py # Python: points MongoMig at your models
|
|
86
|
+
├── schema_snapshot.json # last known expected schema (used by autogenerate)
|
|
87
|
+
└── versions/ # one file per revision
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Configuration
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
database:
|
|
94
|
+
uri: ${MONGODB_URI} # ${VAR} and ${VAR:-default} are expanded
|
|
95
|
+
name: ${MONGODB_DATABASE:-app}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Per-environment overrides live in `mongomig.<env>.yaml` and are merged on top:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
mongomig --env production current # or MONGOMIG_ENV=production
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
MongoMig never prints passwords or full connection strings. It warns you if a password is
|
|
105
|
+
written directly into the config file.
|
|
106
|
+
|
|
107
|
+
### Revision files
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
"""add user profile"""
|
|
111
|
+
|
|
112
|
+
revision = "7be204a1c9e0"
|
|
113
|
+
down_revision = "a1f3c9d20b44"
|
|
114
|
+
reversible = True
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def upgrade(ctx):
|
|
118
|
+
...
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def downgrade(ctx):
|
|
122
|
+
...
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Revision order comes from `down_revision`, not from the file name. Revision ids are random,
|
|
126
|
+
so two developers working on separate branches never get the same id. If both branches add a
|
|
127
|
+
revision, `mongomig heads` shows two heads, and `mongomig revision` refuses to continue until
|
|
128
|
+
you choose a parent with `--head`.
|
|
129
|
+
|
|
130
|
+
Revision ids can be shortened to a unique prefix of 4 or more characters, the same way git
|
|
131
|
+
handles commit hashes.
|
|
132
|
+
|
|
133
|
+
### Commands
|
|
134
|
+
|
|
135
|
+
| Command | Needs MongoDB | Description |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| `init` | no | Create config and migrations directory |
|
|
138
|
+
| `revision -m MSG [--head REV]` | no | Create a new revision |
|
|
139
|
+
| `heads` | no | Show head revision(s) |
|
|
140
|
+
| `history` | no | List revisions, newest first |
|
|
141
|
+
| `current` | yes | Applied vs pending revisions (read-only) |
|
|
142
|
+
|
|
143
|
+
Global options: `--config PATH`, `--env NAME`, `--json`, `--verbose`, `--version`.
|
|
144
|
+
|
|
145
|
+
Exit codes: `0` success · `1` validation · `2` execution/connection · `3` configuration ·
|
|
146
|
+
`4` revision conflict · `5` lock · `6` checksum mismatch.
|
|
147
|
+
|
|
148
|
+
## Roadmap
|
|
149
|
+
|
|
150
|
+
- [x] **M1 Foundation**: config, CLI, revision files, revision graph, tracking
|
|
151
|
+
- [ ] **M2 Migration engine**: `upgrade`, `downgrade`, locking, `merge`, checksums, FastAPI lifespan helper
|
|
152
|
+
- [ ] **M3 Schema engine**: `@collection` models, Beanie support, `inspect`, snapshots
|
|
153
|
+
- [ ] **M4 Autogenerate**: `diff`, `revision --autogenerate`, index/validator diff
|
|
154
|
+
- [ ] **M5 Production safety**: `--dry-run`, `plan`, batching, progress
|
|
155
|
+
- [ ] **M6 Release**: `validate`, `doctor`, docs, PyPI
|
|
156
|
+
|
|
157
|
+
## Development
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
make install # uv venv + editable install with dev extras
|
|
161
|
+
make mongo-up # MongoDB 7 single-node replica set in Docker
|
|
162
|
+
make check # ruff + mypy --strict + pytest
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Integration tests are skipped automatically when MongoDB isn't running. To test against another
|
|
166
|
+
MongoDB version, run `MONGO_VERSION=8.0 make mongo-up`.
|
|
167
|
+
|
|
168
|
+
### Releasing
|
|
169
|
+
|
|
170
|
+
1. Bump `src/mongomig/_version.py` and update `CHANGELOG.md`, then merge to `main`.
|
|
171
|
+
2. On GitHub, create a Release with tag `v<version>` (e.g. `v0.1.0`) and publish it.
|
|
172
|
+
3. `.github/workflows/release.yml` checks that the tag matches the version, builds and
|
|
173
|
+
smoke-tests the wheel, then publishes to PyPI through Trusted Publishing.
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|