dbwarden 1.0.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.
- dbwarden-1.0.0/.gitattributes +2 -0
- dbwarden-1.0.0/.gitignore +160 -0
- dbwarden-1.0.0/LICENSE +21 -0
- dbwarden-1.0.0/PKG-INFO +124 -0
- dbwarden-1.0.0/README.md +87 -0
- dbwarden-1.0.0/dbwarden/__init__.py +1 -0
- dbwarden-1.0.0/dbwarden/cli/__init__.py +3 -0
- dbwarden-1.0.0/dbwarden/cli/main.py +181 -0
- dbwarden-1.0.0/dbwarden/cli/validators.py +22 -0
- dbwarden-1.0.0/dbwarden/commands/__init__.py +103 -0
- dbwarden-1.0.0/dbwarden/commands/check_db.py +95 -0
- dbwarden-1.0.0/dbwarden/commands/extra.py +89 -0
- dbwarden-1.0.0/dbwarden/commands/history.py +42 -0
- dbwarden-1.0.0/dbwarden/commands/init.py +23 -0
- dbwarden-1.0.0/dbwarden/commands/make_migrations.py +193 -0
- dbwarden-1.0.0/dbwarden/commands/migrate.py +181 -0
- dbwarden-1.0.0/dbwarden/commands/rollback.py +100 -0
- dbwarden-1.0.0/dbwarden/commands/status.py +54 -0
- dbwarden-1.0.0/dbwarden/commands/utils.py +35 -0
- dbwarden-1.0.0/dbwarden/config.py +135 -0
- dbwarden-1.0.0/dbwarden/constants.py +12 -0
- dbwarden-1.0.0/dbwarden/database/__init__.py +14 -0
- dbwarden-1.0.0/dbwarden/database/connection.py +112 -0
- dbwarden-1.0.0/dbwarden/database/queries.py +123 -0
- dbwarden-1.0.0/dbwarden/engine/__init__.py +1 -0
- dbwarden-1.0.0/dbwarden/engine/checksum.py +16 -0
- dbwarden-1.0.0/dbwarden/engine/file_parser.py +104 -0
- dbwarden-1.0.0/dbwarden/engine/lock.py +60 -0
- dbwarden-1.0.0/dbwarden/engine/model_discovery.py +441 -0
- dbwarden-1.0.0/dbwarden/engine/version.py +221 -0
- dbwarden-1.0.0/dbwarden/exceptions.py +52 -0
- dbwarden-1.0.0/dbwarden/logging.py +125 -0
- dbwarden-1.0.0/dbwarden/models.py +82 -0
- dbwarden-1.0.0/dbwarden/repositories/__init__.py +35 -0
- dbwarden-1.0.0/dbwarden/repositories/lock_repo.py +48 -0
- dbwarden-1.0.0/dbwarden/repositories/migrations_repo.py +213 -0
- dbwarden-1.0.0/docs/advanced.md +503 -0
- dbwarden-1.0.0/docs/cli-reference.md +374 -0
- dbwarden-1.0.0/docs/commands/check-db.md +204 -0
- dbwarden-1.0.0/docs/commands/diff.md +129 -0
- dbwarden-1.0.0/docs/commands/env.md +98 -0
- dbwarden-1.0.0/docs/commands/history.md +136 -0
- dbwarden-1.0.0/docs/commands/init.md +55 -0
- dbwarden-1.0.0/docs/commands/lock.md +219 -0
- dbwarden-1.0.0/docs/commands/make-migrations.md +185 -0
- dbwarden-1.0.0/docs/commands/migrate.md +267 -0
- dbwarden-1.0.0/docs/commands/mode.md +112 -0
- dbwarden-1.0.0/docs/commands/new.md +269 -0
- dbwarden-1.0.0/docs/commands/rollback.md +309 -0
- dbwarden-1.0.0/docs/commands/squash.md +160 -0
- dbwarden-1.0.0/docs/commands/status.md +186 -0
- dbwarden-1.0.0/docs/commands/version.md +47 -0
- dbwarden-1.0.0/docs/commands.md +173 -0
- dbwarden-1.0.0/docs/configuration.md +209 -0
- dbwarden-1.0.0/docs/databases.md +395 -0
- dbwarden-1.0.0/docs/index.md +72 -0
- dbwarden-1.0.0/docs/installation.md +230 -0
- dbwarden-1.0.0/docs/migration-files.md +338 -0
- dbwarden-1.0.0/docs/models.md +401 -0
- dbwarden-1.0.0/docs/quickstart.md +268 -0
- dbwarden-1.0.0/mkdocs.yml +50 -0
- dbwarden-1.0.0/pyproject.toml +61 -0
- dbwarden-1.0.0/tests/__init__.py +1 -0
- dbwarden-1.0.0/tests/test_config.py +240 -0
- dbwarden-1.0.0/tests/test_file_parser.py +149 -0
- dbwarden-1.0.0/tests/test_model_discovery.py +233 -0
- dbwarden-1.0.0/tests/test_sql_integration.py +257 -0
- dbwarden-1.0.0/tests/test_sync_async.py +276 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
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
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
160
|
+
#.idea/
|
dbwarden-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Emiliano Gandini Outeda
|
|
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.
|
dbwarden-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbwarden
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Professional database migration system for Python/SQLAlchemy projects
|
|
5
|
+
Author-email: DBWarden <dbwarden@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: database,fastapi,migrations,postgres,sqlalchemy
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: aiosqlite>=0.22.1
|
|
18
|
+
Requires-Dist: asyncpg<0.32.0,>=0.29.0
|
|
19
|
+
Requires-Dist: packaging>=25.0
|
|
20
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
21
|
+
Requires-Dist: pyyaml>=6.0
|
|
22
|
+
Requires-Dist: rich>=12.2.0
|
|
23
|
+
Requires-Dist: sqlalchemy>=2.0.10
|
|
24
|
+
Requires-Dist: typer>=0.12.3
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: psycopg2-binary>=2.9.11; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.4.2; extra == 'dev'
|
|
29
|
+
Provides-Extra: postgres-async
|
|
30
|
+
Requires-Dist: asyncpg<0.32.0,>=0.29.0; extra == 'postgres-async'
|
|
31
|
+
Requires-Dist: sqlalchemy[postgresql]>=2.0.10; extra == 'postgres-async'
|
|
32
|
+
Provides-Extra: postgres-sync
|
|
33
|
+
Requires-Dist: psycopg2-binary>=2.9.11; extra == 'postgres-sync'
|
|
34
|
+
Provides-Extra: sqlite-async
|
|
35
|
+
Requires-Dist: aiosqlite>=0.22.1; extra == 'sqlite-async'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# DBWarden
|
|
39
|
+
|
|
40
|
+
**DBWarden** is a database migration system for Python/SQLAlchemy projects.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install dbwarden
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
Create `.env` in your project:
|
|
51
|
+
|
|
52
|
+
```env
|
|
53
|
+
DBWARDEN_SQLALCHEMY_URL=postgresql://user:pass@localhost/db
|
|
54
|
+
DBWARDEN_ASYNC=false # or true for async mode
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Basic Commands
|
|
58
|
+
|
|
59
|
+
| Command | Description |
|
|
60
|
+
|---------|-------------|
|
|
61
|
+
| `dbwarden init` | Initialize migrations directory |
|
|
62
|
+
| `dbwarden make-migrations "name"` | Generate SQL from SQLAlchemy models |
|
|
63
|
+
| `dbwarden migrate` | Apply pending migrations |
|
|
64
|
+
| `dbwarden migrate --verbose` | Apply with detailed logging |
|
|
65
|
+
| `dbwarden rollback` | Revert the last migration |
|
|
66
|
+
| `dbwarden history` | Show migration history |
|
|
67
|
+
| `dbwarden status` | Show current status |
|
|
68
|
+
| `dbwarden mode` | Show sync/async mode |
|
|
69
|
+
| `dbwarden check-db` | Inspect DB schema |
|
|
70
|
+
| `dbwarden diff` | Show models vs DB differences |
|
|
71
|
+
|
|
72
|
+
## SQLAlchemy Models
|
|
73
|
+
|
|
74
|
+
DBWarden automatically detects models in `models/`:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
# models/user.py
|
|
78
|
+
from sqlalchemy import Column, Integer, String
|
|
79
|
+
from sqlalchemy.orm import declarative_base
|
|
80
|
+
|
|
81
|
+
Base = declarative_base()
|
|
82
|
+
|
|
83
|
+
class User(Base):
|
|
84
|
+
__tablename__ = "users"
|
|
85
|
+
id = Column(Integer, primary_key=True)
|
|
86
|
+
name = Column(String(100))
|
|
87
|
+
email = Column(String(255), unique=True)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Complete Example
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# 1. Initialize
|
|
94
|
+
dbwarden init
|
|
95
|
+
|
|
96
|
+
# 2. Create models in models/
|
|
97
|
+
|
|
98
|
+
# 3. Generate migration from models
|
|
99
|
+
dbwarden make-migrations "create users table"
|
|
100
|
+
|
|
101
|
+
# 4. Apply
|
|
102
|
+
dbwarden migrate --verbose
|
|
103
|
+
|
|
104
|
+
# 5. View history
|
|
105
|
+
dbwarden history
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Environment Variables
|
|
109
|
+
|
|
110
|
+
| Variable | Description |
|
|
111
|
+
|----------|-------------|
|
|
112
|
+
| `DBWARDEN_SQLALCHEMY_URL` | DB connection URL |
|
|
113
|
+
| `DBWARDEN_ASYNC` | Async mode (`true`/`false`) |
|
|
114
|
+
| `DBWARDEN_MODEL_PATHS` | Paths to SQLAlchemy models |
|
|
115
|
+
|
|
116
|
+
## Supported Databases
|
|
117
|
+
|
|
118
|
+
- PostgreSQL (sync + async)
|
|
119
|
+
- SQLite (sync + async)
|
|
120
|
+
- MySQL (sync)
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT
|
dbwarden-1.0.0/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# DBWarden
|
|
2
|
+
|
|
3
|
+
**DBWarden** is a database migration system for Python/SQLAlchemy projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install dbwarden
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
Create `.env` in your project:
|
|
14
|
+
|
|
15
|
+
```env
|
|
16
|
+
DBWARDEN_SQLALCHEMY_URL=postgresql://user:pass@localhost/db
|
|
17
|
+
DBWARDEN_ASYNC=false # or true for async mode
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Basic Commands
|
|
21
|
+
|
|
22
|
+
| Command | Description |
|
|
23
|
+
|---------|-------------|
|
|
24
|
+
| `dbwarden init` | Initialize migrations directory |
|
|
25
|
+
| `dbwarden make-migrations "name"` | Generate SQL from SQLAlchemy models |
|
|
26
|
+
| `dbwarden migrate` | Apply pending migrations |
|
|
27
|
+
| `dbwarden migrate --verbose` | Apply with detailed logging |
|
|
28
|
+
| `dbwarden rollback` | Revert the last migration |
|
|
29
|
+
| `dbwarden history` | Show migration history |
|
|
30
|
+
| `dbwarden status` | Show current status |
|
|
31
|
+
| `dbwarden mode` | Show sync/async mode |
|
|
32
|
+
| `dbwarden check-db` | Inspect DB schema |
|
|
33
|
+
| `dbwarden diff` | Show models vs DB differences |
|
|
34
|
+
|
|
35
|
+
## SQLAlchemy Models
|
|
36
|
+
|
|
37
|
+
DBWarden automatically detects models in `models/`:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
# models/user.py
|
|
41
|
+
from sqlalchemy import Column, Integer, String
|
|
42
|
+
from sqlalchemy.orm import declarative_base
|
|
43
|
+
|
|
44
|
+
Base = declarative_base()
|
|
45
|
+
|
|
46
|
+
class User(Base):
|
|
47
|
+
__tablename__ = "users"
|
|
48
|
+
id = Column(Integer, primary_key=True)
|
|
49
|
+
name = Column(String(100))
|
|
50
|
+
email = Column(String(255), unique=True)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Complete Example
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# 1. Initialize
|
|
57
|
+
dbwarden init
|
|
58
|
+
|
|
59
|
+
# 2. Create models in models/
|
|
60
|
+
|
|
61
|
+
# 3. Generate migration from models
|
|
62
|
+
dbwarden make-migrations "create users table"
|
|
63
|
+
|
|
64
|
+
# 4. Apply
|
|
65
|
+
dbwarden migrate --verbose
|
|
66
|
+
|
|
67
|
+
# 5. View history
|
|
68
|
+
dbwarden history
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Environment Variables
|
|
72
|
+
|
|
73
|
+
| Variable | Description |
|
|
74
|
+
|----------|-------------|
|
|
75
|
+
| `DBWARDEN_SQLALCHEMY_URL` | DB connection URL |
|
|
76
|
+
| `DBWARDEN_ASYNC` | Async mode (`true`/`false`) |
|
|
77
|
+
| `DBWARDEN_MODEL_PATHS` | Paths to SQLAlchemy models |
|
|
78
|
+
|
|
79
|
+
## Supported Databases
|
|
80
|
+
|
|
81
|
+
- PostgreSQL (sync + async)
|
|
82
|
+
- SQLite (sync + async)
|
|
83
|
+
- MySQL (sync)
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dbwarden.cli.validators import validate_directory
|
|
4
|
+
from dbwarden.commands import (
|
|
5
|
+
handle_check_db,
|
|
6
|
+
handle_diff,
|
|
7
|
+
handle_env,
|
|
8
|
+
handle_history,
|
|
9
|
+
handle_init,
|
|
10
|
+
handle_lock_status,
|
|
11
|
+
handle_make_migrations,
|
|
12
|
+
handle_migrate,
|
|
13
|
+
handle_mode,
|
|
14
|
+
handle_new,
|
|
15
|
+
handle_rollback,
|
|
16
|
+
handle_squash,
|
|
17
|
+
handle_status,
|
|
18
|
+
handle_unlock,
|
|
19
|
+
handle_version,
|
|
20
|
+
)
|
|
21
|
+
from dbwarden.logging import get_logger
|
|
22
|
+
|
|
23
|
+
app = typer.Typer(
|
|
24
|
+
help="DBWarden - Professional database migration system for Python models",
|
|
25
|
+
add_completion=False,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@app.command()
|
|
30
|
+
def init():
|
|
31
|
+
"""Initialize the migrations directory."""
|
|
32
|
+
handle_init()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.command()
|
|
36
|
+
def make_migrations(
|
|
37
|
+
description: str = typer.Argument(None, help="Description for the migration"),
|
|
38
|
+
verbose: bool = typer.Option(
|
|
39
|
+
False, "--verbose", "-v", help="Enable verbose logging"
|
|
40
|
+
),
|
|
41
|
+
):
|
|
42
|
+
"""Auto-generate SQL migration from SQLAlchemy models."""
|
|
43
|
+
validate_directory()
|
|
44
|
+
handle_make_migrations(description=description, verbose=verbose)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@app.command()
|
|
48
|
+
def new(
|
|
49
|
+
description: str = typer.Argument(..., help="Description of the migration"),
|
|
50
|
+
version: str = typer.Option(
|
|
51
|
+
None, "--version", "-v", help="Version of the migration"
|
|
52
|
+
),
|
|
53
|
+
):
|
|
54
|
+
"""Create a new manual migration file."""
|
|
55
|
+
validate_directory()
|
|
56
|
+
handle_new(description=description, version=version)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@app.command()
|
|
60
|
+
def migrate(
|
|
61
|
+
count: int = typer.Option(
|
|
62
|
+
None, "--count", "-c", help="Number of migrations to apply"
|
|
63
|
+
),
|
|
64
|
+
to_version: str = typer.Option(
|
|
65
|
+
None, "--to-version", "-t", help="Migrate to a specific version"
|
|
66
|
+
),
|
|
67
|
+
verbose: bool = typer.Option(
|
|
68
|
+
False, "--verbose", "-v", help="Enable verbose logging"
|
|
69
|
+
),
|
|
70
|
+
):
|
|
71
|
+
"""Apply pending migrations to the database."""
|
|
72
|
+
validate_directory()
|
|
73
|
+
handle_migrate(count=count, to_version=to_version, verbose=verbose)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@app.command()
|
|
77
|
+
def rollback(
|
|
78
|
+
count: int = typer.Option(
|
|
79
|
+
None, "--count", "-c", help="Number of migrations to rollback"
|
|
80
|
+
),
|
|
81
|
+
to_version: str = typer.Option(
|
|
82
|
+
None, "--to-version", "-t", help="Rollback to a specific version"
|
|
83
|
+
),
|
|
84
|
+
verbose: bool = typer.Option(
|
|
85
|
+
False, "--verbose", "-v", help="Enable verbose logging"
|
|
86
|
+
),
|
|
87
|
+
):
|
|
88
|
+
"""Rollback the last applied migration."""
|
|
89
|
+
validate_directory()
|
|
90
|
+
handle_rollback(count=count, to_version=to_version, verbose=verbose)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@app.command()
|
|
94
|
+
def history():
|
|
95
|
+
"""Show the full migration history."""
|
|
96
|
+
validate_directory()
|
|
97
|
+
handle_history()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@app.command()
|
|
101
|
+
def status():
|
|
102
|
+
"""Show migration status (applied and pending)."""
|
|
103
|
+
validate_directory()
|
|
104
|
+
handle_status()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@app.command()
|
|
108
|
+
def check_db(
|
|
109
|
+
output: str = typer.Option(
|
|
110
|
+
"txt", "--out", "-o", help="Output format (json, yaml, sql, txt)"
|
|
111
|
+
),
|
|
112
|
+
):
|
|
113
|
+
"""Inspect the live database schema."""
|
|
114
|
+
validate_directory()
|
|
115
|
+
handle_check_db(output_format=output)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@app.command()
|
|
119
|
+
def diff(
|
|
120
|
+
diff_type: str = typer.Argument(
|
|
121
|
+
"all", help="Type of diff (models, migrations, all)"
|
|
122
|
+
),
|
|
123
|
+
verbose: bool = typer.Option(
|
|
124
|
+
False, "--verbose", "-v", help="Enable verbose logging"
|
|
125
|
+
),
|
|
126
|
+
):
|
|
127
|
+
"""Show structural differences between models and database."""
|
|
128
|
+
validate_directory()
|
|
129
|
+
handle_diff(diff_type=diff_type, verbose=verbose)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@app.command()
|
|
133
|
+
def mode():
|
|
134
|
+
"""Display whether execution is sync or async."""
|
|
135
|
+
handle_mode()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@app.command()
|
|
139
|
+
def squash(
|
|
140
|
+
verbose: bool = typer.Option(
|
|
141
|
+
False, "--verbose", "-v", help="Enable verbose logging"
|
|
142
|
+
),
|
|
143
|
+
):
|
|
144
|
+
"""Merge multiple consecutive migrations into one."""
|
|
145
|
+
validate_directory()
|
|
146
|
+
handle_squash(verbose=verbose)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@app.command()
|
|
150
|
+
def env():
|
|
151
|
+
"""Display relevant environment variables without leaking secrets."""
|
|
152
|
+
handle_env()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@app.command()
|
|
156
|
+
def version():
|
|
157
|
+
"""Display DBWarden version and compatibility information."""
|
|
158
|
+
handle_version()
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@app.command()
|
|
162
|
+
def lock_status():
|
|
163
|
+
"""Check if migration is currently locked."""
|
|
164
|
+
validate_directory()
|
|
165
|
+
handle_lock_status()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@app.command()
|
|
169
|
+
def unlock():
|
|
170
|
+
"""Release the migration lock."""
|
|
171
|
+
validate_directory()
|
|
172
|
+
handle_unlock()
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def main() -> None:
|
|
176
|
+
"""Main entry point for DBWarden CLI."""
|
|
177
|
+
app()
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
if __name__ == "__main__":
|
|
181
|
+
main()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from dbwarden.constants import MIGRATIONS_DIR
|
|
4
|
+
from dbwarden.exceptions import DirectoryNotFoundError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def validate_directory() -> None:
|
|
8
|
+
"""
|
|
9
|
+
Ensure command is run from a project directory with migrations/ folder.
|
|
10
|
+
|
|
11
|
+
Raises:
|
|
12
|
+
DirectoryNotFoundError: If no valid migrations directory is found.
|
|
13
|
+
"""
|
|
14
|
+
current_dir = Path.cwd()
|
|
15
|
+
|
|
16
|
+
migrations_dir = current_dir / MIGRATIONS_DIR
|
|
17
|
+
if migrations_dir.exists() and migrations_dir.is_dir():
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
raise DirectoryNotFoundError(
|
|
21
|
+
"migrations directory not found. Please run 'dbwarden init' first."
|
|
22
|
+
)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from dbwarden.commands.check_db import check_db_cmd
|
|
2
|
+
from dbwarden.commands.extra import diff_cmd, lock_status_cmd, squash_cmd, unlock_cmd
|
|
3
|
+
from dbwarden.commands.history import history_cmd
|
|
4
|
+
from dbwarden.commands.init import init_cmd
|
|
5
|
+
from dbwarden.commands.make_migrations import make_migrations_cmd, new_migration_cmd
|
|
6
|
+
from dbwarden.commands.migrate import migrate_cmd
|
|
7
|
+
from dbwarden.commands.rollback import rollback_cmd
|
|
8
|
+
from dbwarden.commands.status import status_cmd
|
|
9
|
+
from dbwarden.commands.utils import env_cmd, mode_cmd, version_cmd
|
|
10
|
+
from dbwarden.exceptions import DirectoryNotFoundError
|
|
11
|
+
from dbwarden.logging import get_logger
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def handle_init() -> None:
|
|
15
|
+
"""Handle init command."""
|
|
16
|
+
init_cmd()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def handle_make_migrations(description: str | None, verbose: bool) -> None:
|
|
20
|
+
"""Handle make-migrations command."""
|
|
21
|
+
logger = get_logger(verbose=verbose)
|
|
22
|
+
logger.log_execution_mode("async" if is_async_enabled() else "sync")
|
|
23
|
+
make_migrations_cmd(description=description, verbose=verbose)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def handle_new(description: str, version: str | None) -> None:
|
|
27
|
+
"""Handle new command."""
|
|
28
|
+
new_migration_cmd(description=description, version=version)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def handle_migrate(
|
|
32
|
+
count: int | None,
|
|
33
|
+
to_version: str | None,
|
|
34
|
+
verbose: bool,
|
|
35
|
+
) -> None:
|
|
36
|
+
"""Handle migrate command."""
|
|
37
|
+
migrate_cmd(count=count, to_version=to_version, verbose=verbose)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def handle_rollback(
|
|
41
|
+
count: int | None,
|
|
42
|
+
to_version: str | None,
|
|
43
|
+
verbose: bool,
|
|
44
|
+
) -> None:
|
|
45
|
+
"""Handle rollback command."""
|
|
46
|
+
rollback_cmd(count=count, to_version=to_version, verbose=verbose)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def handle_history() -> None:
|
|
50
|
+
"""Handle history command."""
|
|
51
|
+
history_cmd()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def handle_status() -> None:
|
|
55
|
+
"""Handle status command."""
|
|
56
|
+
status_cmd()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def handle_check_db(output_format: str) -> None:
|
|
60
|
+
"""Handle check-db command."""
|
|
61
|
+
check_db_cmd(output_format=output_format)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def handle_diff(diff_type: str, verbose: bool) -> None:
|
|
65
|
+
"""Handle diff command."""
|
|
66
|
+
diff_cmd(diff_type=diff_type, verbose=verbose)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def handle_mode() -> None:
|
|
70
|
+
"""Handle mode command."""
|
|
71
|
+
mode_cmd()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def handle_squash(verbose: bool) -> None:
|
|
75
|
+
"""Handle squash command."""
|
|
76
|
+
squash_cmd(verbose=verbose)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def handle_env() -> None:
|
|
80
|
+
"""Handle env command."""
|
|
81
|
+
env_cmd()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def handle_version() -> None:
|
|
85
|
+
"""Handle version command."""
|
|
86
|
+
version_cmd()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def handle_lock_status() -> None:
|
|
90
|
+
"""Handle lock-status command."""
|
|
91
|
+
lock_status_cmd()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def handle_unlock() -> None:
|
|
95
|
+
"""Handle unlock command."""
|
|
96
|
+
unlock_cmd()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def is_async_enabled() -> bool:
|
|
100
|
+
"""Check if async mode is enabled."""
|
|
101
|
+
from dbwarden.database.connection import is_async_enabled
|
|
102
|
+
|
|
103
|
+
return is_async_enabled()
|