lunarphase-orm 0.1.3__tar.gz → 0.2.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.
Files changed (136) hide show
  1. lunarphase_orm-0.2.0/.github/workflows/ci.yml +89 -0
  2. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/.github/workflows/pypi-publish.yml +22 -8
  3. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/.gitignore +4 -0
  4. lunarphase_orm-0.2.0/CHANGELOG.md +153 -0
  5. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/Cargo.lock +1 -1
  6. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/Cargo.toml +1 -1
  7. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/DOCUMENTATION.md +9 -3
  8. lunarphase_orm-0.1.3/README.md → lunarphase_orm-0.2.0/PKG-INFO +42 -10
  9. lunarphase_orm-0.1.3/PKG-INFO → lunarphase_orm-0.2.0/README.md +21 -26
  10. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/getting-started.md +1 -1
  11. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/migrations-cli.md +36 -3
  12. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/query-builder.md +17 -0
  13. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/relations-and-batching.md +15 -8
  14. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/syntax-cheatsheet.md +6 -2
  15. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/unit-of-work.md +32 -8
  16. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/__init__.py +4 -2
  17. lunarphase_orm-0.2.0/lunarphase/_rust.py +32 -0
  18. lunarphase_orm-0.2.0/lunarphase/cli/main.py +135 -0
  19. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/core/ast.py +4 -1
  20. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/core/fields.py +82 -2
  21. lunarphase_orm-0.2.0/lunarphase/core/model.py +267 -0
  22. lunarphase_orm-0.2.0/lunarphase/core/relations.py +176 -0
  23. lunarphase_orm-0.2.0/lunarphase/core/state.py +92 -0
  24. lunarphase_orm-0.2.0/lunarphase/core/uow.py +196 -0
  25. lunarphase_orm-0.2.0/lunarphase/db/engine.py +445 -0
  26. lunarphase_orm-0.2.0/lunarphase/migrations/diff.py +66 -0
  27. lunarphase_orm-0.2.0/lunarphase/migrations/runner.py +165 -0
  28. lunarphase_orm-0.2.0/lunarphase/migrations/schema.py +116 -0
  29. lunarphase_orm-0.2.0/lunarphase/query/batcher.py +75 -0
  30. lunarphase_orm-0.2.0/lunarphase/query/builder.py +263 -0
  31. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/pyproject.toml +13 -1
  32. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/relations-and-batching/index.html +60 -10
  33. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/search/search_index.json +1 -1
  34. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/sitemap.xml.gz +0 -0
  35. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/src/compiler.rs +20 -3
  36. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/src/lib.rs +4 -0
  37. lunarphase_orm-0.2.0/src/migration_diff.rs +131 -0
  38. lunarphase_orm-0.2.0/src/state_tracker.rs +244 -0
  39. lunarphase_orm-0.2.0/tests/conftest.py +16 -0
  40. lunarphase_orm-0.2.0/tests/test_all_engines_deep.py +143 -0
  41. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_coverage_boost.py +2 -1
  42. lunarphase_orm-0.2.0/tests/test_regressions.py +682 -0
  43. lunarphase_orm-0.2.0/tests/test_version.py +25 -0
  44. lunarphase_orm-0.1.3/.github/workflows/ci.yml +0 -38
  45. lunarphase_orm-0.1.3/lunarphase/cli/main.py +0 -51
  46. lunarphase_orm-0.1.3/lunarphase/core/model.py +0 -179
  47. lunarphase_orm-0.1.3/lunarphase/core/relations.py +0 -114
  48. lunarphase_orm-0.1.3/lunarphase/core/state.py +0 -53
  49. lunarphase_orm-0.1.3/lunarphase/core/uow.py +0 -97
  50. lunarphase_orm-0.1.3/lunarphase/db/engine.py +0 -103
  51. lunarphase_orm-0.1.3/lunarphase/migrations/diff.py +0 -60
  52. lunarphase_orm-0.1.3/lunarphase/migrations/runner.py +0 -111
  53. lunarphase_orm-0.1.3/lunarphase/migrations/schema.py +0 -34
  54. lunarphase_orm-0.1.3/lunarphase/query/batcher.py +0 -53
  55. lunarphase_orm-0.1.3/lunarphase/query/builder.py +0 -152
  56. lunarphase_orm-0.1.3/src/migration_diff.rs +0 -104
  57. lunarphase_orm-0.1.3/src/state_tracker.rs +0 -163
  58. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/.readthedocs.yaml +0 -0
  59. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/BENCHMARK.md +0 -0
  60. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/LICENSE +0 -0
  61. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/ROADMAP.md +0 -0
  62. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/benchmarks/advanced_scale_benchmark.py +0 -0
  63. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/benchmarks/comprehensive_orm_benchmark.py +0 -0
  64. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/benchmarks/diagnostic_3way_benchmark.py +0 -0
  65. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/architecture.md +0 -0
  66. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/index.md +0 -0
  67. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/models-and-fields.md +0 -0
  68. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/docs/requirements.txt +0 -0
  69. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/cli/__init__.py +0 -0
  70. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/core/__init__.py +0 -0
  71. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/db/__init__.py +0 -0
  72. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/migrations/__init__.py +0 -0
  73. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/lunarphase/query/__init__.py +0 -0
  74. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/mkdocs.yml +0 -0
  75. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/404.html +0 -0
  76. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/architecture/index.html +0 -0
  77. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/images/favicon.png +0 -0
  78. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/bundle.d7400e89.min.js +0 -0
  79. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/bundle.d7400e89.min.js.map +0 -0
  80. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.ar.min.js +0 -0
  81. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.da.min.js +0 -0
  82. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.de.min.js +0 -0
  83. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.du.min.js +0 -0
  84. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.el.min.js +0 -0
  85. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.es.min.js +0 -0
  86. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.fi.min.js +0 -0
  87. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.fr.min.js +0 -0
  88. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.he.min.js +0 -0
  89. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.hi.min.js +0 -0
  90. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.hu.min.js +0 -0
  91. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.hy.min.js +0 -0
  92. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.it.min.js +0 -0
  93. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.ja.min.js +0 -0
  94. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.jp.min.js +0 -0
  95. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.kn.min.js +0 -0
  96. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.ko.min.js +0 -0
  97. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.multi.min.js +0 -0
  98. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.nl.min.js +0 -0
  99. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.no.min.js +0 -0
  100. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.pt.min.js +0 -0
  101. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.ro.min.js +0 -0
  102. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.ru.min.js +0 -0
  103. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.sa.min.js +0 -0
  104. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.stemmer.support.min.js +0 -0
  105. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.sv.min.js +0 -0
  106. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.ta.min.js +0 -0
  107. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.te.min.js +0 -0
  108. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.th.min.js +0 -0
  109. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.tr.min.js +0 -0
  110. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.vi.min.js +0 -0
  111. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/min/lunr.zh.min.js +0 -0
  112. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/tinyseg.js +0 -0
  113. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/lunr/wordcut.js +0 -0
  114. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/workers/search.2c215733.min.js +0 -0
  115. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/javascripts/workers/search.2c215733.min.js.map +0 -0
  116. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/stylesheets/main.ec1eaa64.min.css +0 -0
  117. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/stylesheets/main.ec1eaa64.min.css.map +0 -0
  118. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/stylesheets/palette.ab4e12ef.min.css +0 -0
  119. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/assets/stylesheets/palette.ab4e12ef.min.css.map +0 -0
  120. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/getting-started/index.html +0 -0
  121. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/index.html +0 -0
  122. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/migrations-cli/index.html +0 -0
  123. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/models-and-fields/index.html +0 -0
  124. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/query-builder/index.html +0 -0
  125. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/requirements.txt +0 -0
  126. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/sitemap.xml +0 -0
  127. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/syntax-cheatsheet/index.html +0 -0
  128. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/site/unit-of-work/index.html +0 -0
  129. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/src/batcher.rs +0 -0
  130. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_benchmarks.py +0 -0
  131. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_fase1_core_ast.py +0 -0
  132. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_fase2_async_drivers.py +0 -0
  133. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_fase3_auto_batching_relations.py +0 -0
  134. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_fase4_dirty_tracking_uow.py +0 -0
  135. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_fase5_auto_migrations_cli.py +0 -0
  136. {lunarphase_orm-0.1.3 → lunarphase_orm-0.2.0}/tests/test_rust_performance.py +0 -0
@@ -0,0 +1,89 @@
1
+ name: CI Test Suite
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ concurrency:
14
+ group: ci-${{ github.ref }}
15
+ cancel-in-progress: true
16
+
17
+ jobs:
18
+ test:
19
+ name: pytest (${{ matrix.os }}, Python ${{ matrix.python-version }})
20
+ runs-on: ${{ matrix.os }}
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ os: [ubuntu-latest, macos-latest]
25
+ python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
26
+ # ubuntu-latest (26.04) has no Python 3.9 build because 3.9 is
27
+ # end-of-life; keep testing the minimum supported version on 24.04.
28
+ exclude:
29
+ - os: ubuntu-latest
30
+ python-version: '3.9'
31
+ include:
32
+ - os: ubuntu-24.04
33
+ python-version: '3.9'
34
+
35
+ steps:
36
+ - uses: actions/checkout@v5
37
+
38
+ - name: Install Rust toolchain
39
+ uses: dtolnay/rust-toolchain@stable
40
+
41
+ - name: Cache Rust build
42
+ uses: Swatinem/rust-cache@v2
43
+
44
+ - name: Set up Python ${{ matrix.python-version }}
45
+ uses: actions/setup-python@v6
46
+ with:
47
+ python-version: ${{ matrix.python-version }}
48
+
49
+ # `maturin develop` installs into the active virtualenv and refuses to
50
+ # run without one, so create it and activate it for all later steps.
51
+ - name: Create virtualenv
52
+ run: |
53
+ python -m venv .venv
54
+ echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> "$GITHUB_ENV"
55
+ echo "$GITHUB_WORKSPACE/.venv/bin" >> "$GITHUB_PATH"
56
+
57
+ - name: Build Rust extension & install test dependencies
58
+ run: |
59
+ python -m pip install --upgrade pip maturin
60
+ maturin develop --release --extras test
61
+
62
+ - name: Run tests (Rust extension)
63
+ run: pytest --benchmark-disable --cov=lunarphase --cov-report=
64
+
65
+ # The pure-Python fallbacks must behave exactly like the Rust core.
66
+ - name: Run tests (pure-Python fallback)
67
+ env:
68
+ LUNARPHASE_DISABLE_RUST: "1"
69
+ run: pytest --benchmark-disable --cov=lunarphase --cov-append --cov-report=term-missing
70
+
71
+ rust-lint:
72
+ name: Rust fmt & clippy
73
+ runs-on: ubuntu-latest
74
+ steps:
75
+ - uses: actions/checkout@v5
76
+
77
+ - name: Install Rust toolchain
78
+ uses: dtolnay/rust-toolchain@stable
79
+ with:
80
+ components: rustfmt, clippy
81
+
82
+ - name: Cache Rust build
83
+ uses: Swatinem/rust-cache@v2
84
+
85
+ - name: cargo fmt
86
+ run: cargo fmt --check
87
+
88
+ - name: cargo clippy
89
+ run: cargo clippy --all-targets -- -D warnings
@@ -4,6 +4,15 @@ on:
4
4
  release:
5
5
  types: [published]
6
6
  workflow_dispatch:
7
+ # Build (but never publish) on PRs that touch packaging, so a broken
8
+ # release build is caught before a release is cut.
9
+ pull_request:
10
+ branches: [ main ]
11
+ paths:
12
+ - '.github/workflows/pypi-publish.yml'
13
+ - 'pyproject.toml'
14
+ - 'Cargo.toml'
15
+ - 'Cargo.lock'
7
16
 
8
17
  permissions:
9
18
  contents: read
@@ -26,7 +35,8 @@ jobs:
26
35
  # macOS Apple Silicon (arm64) & Intel (x86_64)
27
36
  - os: macos-15-intel
28
37
  target: x86_64
29
- - os: macos-14
38
+ # macos-14 images were retired; macos-latest is Apple Silicon.
39
+ - os: macos-latest
30
40
  target: aarch64
31
41
 
32
42
  # Windows x86_64
@@ -34,11 +44,14 @@ jobs:
34
44
  target: x64
35
45
 
36
46
  steps:
37
- - uses: actions/checkout@v4
47
+ - uses: actions/checkout@v5
38
48
 
39
- - uses: actions/setup-python@v5
49
+ # The wheels are abi3 (cp39-abi3, set by pyo3's abi3-py39 feature), so
50
+ # the host interpreter version does not change the output. 3.9 is no
51
+ # longer available on ubuntu-latest (26.04).
52
+ - uses: actions/setup-python@v6
40
53
  with:
41
- python-version: '3.9'
54
+ python-version: '3.12'
42
55
 
43
56
  - name: Build wheels via Maturin Action
44
57
  uses: PyO3/maturin-action@v1
@@ -57,11 +70,11 @@ jobs:
57
70
  name: Build source distribution (sdist)
58
71
  runs-on: ubuntu-latest
59
72
  steps:
60
- - uses: actions/checkout@v4
73
+ - uses: actions/checkout@v5
61
74
 
62
- - uses: actions/setup-python@v5
75
+ - uses: actions/setup-python@v6
63
76
  with:
64
- python-version: '3.9'
77
+ python-version: '3.12'
65
78
 
66
79
  - name: Build sdist via Maturin Action
67
80
  uses: PyO3/maturin-action@v1
@@ -79,7 +92,8 @@ jobs:
79
92
  name: Publish package to PyPI
80
93
  runs-on: ubuntu-latest
81
94
  needs: [build-wheels, build-sdist]
82
-
95
+ if: github.event_name != 'pull_request'
96
+
83
97
  environment:
84
98
  name: pypi
85
99
  url: https://pypi.org/p/lunarphase-orm
@@ -46,3 +46,7 @@ Thumbs.db
46
46
  .idea/
47
47
  *.swp
48
48
  *.swo
49
+
50
+ tests_live_mysql/
51
+ live_mysql_migrations/
52
+ ROADMAP.md
@@ -0,0 +1,153 @@
1
+ # Changelog
2
+
3
+ All notable changes to LunarPhaseORM are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). While the version is below 1.0, minor releases (0.x.0) may contain breaking changes.
6
+
7
+ ## [0.2.0] - 2026-11-30
8
+
9
+ This release fixes the problems found in an audit of 0.1.4. Several documented features did not work (eager loading, auto-batching, atomic Unit of Work commits, the migration CLI), and some bugs silently lost data or produced invalid SQL. Fixing them required breaking changes; see **Upgrading from 0.1.x** below.
10
+
11
+ ### ⚠️ Breaking changes and upgrade guide
12
+
13
+ - **An engine must be configured before running queries.** `get_engine()` used to create a throwaway in-memory SQLite database when none was configured, so data could silently disappear. It now raises `RuntimeError`.
14
+ *Upgrade:* call `create_engine(url)` (or `set_engine(engine)`) at startup. CLI users pass `--database-url` or set `LUNARPHASE_DATABASE_URL`.
15
+ - **`QueryBuilder` is immutable.** Every chained call returns a new builder; the original is unchanged (previously `q.first()` permanently added `LIMIT 1` to `q`).
16
+ *Upgrade:* reassign when building queries step by step: `q = q.where(...)`.
17
+ - **Invalid input raises instead of being ignored:**
18
+ - `Model(...)` raises `TypeError` for unknown fields.
19
+ - `create_engine()` raises `ValueError` for unsupported URL schemes. They were previously treated as an SQLite file path.
20
+ - `where()` positional arguments must be expressions such as `User.age > 18`.
21
+ - `with_relations()` raises `ValueError` for unknown relation names.
22
+ - **Query input is validated to prevent SQL injection:**
23
+ - `select()` and `order_by()` accept column names (`"name"`, `"users.name"`, `"*"`) or field descriptors; raw expressions such as `"COUNT(*)"` are rejected.
24
+ - The `order_by()` direction must be `"asc"` or `"desc"`.
25
+ - `limit()`, `offset()` and `paginate()` require non-negative integers.
26
+ - `join()` only accepts standard join types.
27
+ - **`JSONField` values are serialized automatically.** Assign Python objects (`dict`, `list`, ...). They are stored as JSON text and decoded when loaded, and rows written as JSON text by 0.1.x decode as well.
28
+ *Upgrade:* stop calling `json.dumps()` yourself; a pre-serialized string would now be stored as a JSON string.
29
+ - **`DateTimeField` and `BooleanField` return Python types.** They now return `datetime` and `bool`, instead of SQLite's raw strings and `0`/`1`. On SQLite, datetimes are stored as `YYYY-MM-DD HH:MM:SS[.ffffff]`.
30
+ - **Generated migrations can contain `DROP COLUMN`** for columns that no longer exist on the model. Review migration files before running them. On SQLite, `DROP COLUMN` requires SQLite 3.35 or newer. A `NOT NULL` field without a default is added to an existing table as nullable.
31
+ - **`lunarphase make:migration` requires `--models`** (or `LUNARPHASE_MODELS`). It previously diffed an empty model list and never produced a migration. The CLI now exits with `2` for configuration errors and `1` for failed commands.
32
+ - **Unit of Work semantics changed:**
33
+ - Inside `async with uow.begin():`, instances loaded by queries are tracked, and if modified they are saved on commit.
34
+ - `rollback()` reverts unsaved changes on tracked instances.
35
+ - Commits write rows in registration order.
36
+ - **Custom engines** (subclasses of `DatabaseEngine`) must:
37
+ - accept the new `pk_name` keyword in `execute_insert(sql, params=(), pk_name="id")`;
38
+ - implement `_begin()` if they need `transaction()`.
39
+
40
+ ### Added
41
+
42
+ - `engine.transaction()`: an async context manager that runs the enclosed queries atomically on one pinned connection. Nested calls join the outer transaction.
43
+ - Engines are async context managers: `async with create_engine(url) as engine: ...`.
44
+ - Eager loading (`with_relations()`) for `HasOne` and `BelongsTo` relations.
45
+ - `Model.select()`, `Model.order_by()` and `Model.with_relations()` shortcuts.
46
+ - `Model.discard_changes()` reverts unsaved attribute changes.
47
+ - `save()` and `delete()` accept an explicit `engine=` argument.
48
+ - Identity map integration: inside `uow.begin()`, every row maps to one shared instance.
49
+ - CLI options `--database-url`, `--models`, `--migrations-dir` and the matching environment variables `LUNARPHASE_DATABASE_URL`, `LUNARPHASE_MODELS`, `LUNARPHASE_MIGRATIONS_DIR`.
50
+ - `lunarphase status` lists pending migrations as well as applied ones.
51
+ - `__abstract__ = True` marks base models that get no table.
52
+ - Field hooks `get_default()`, `to_db()`, `from_db()` and `db_type()` for custom field types.
53
+ - `LUNARPHASE_DISABLE_RUST=1` forces the pure-Python implementations, which is useful for debugging and for parity tests.
54
+ - A `test` extra: `maturin develop --extras test` installs the test dependencies.
55
+
56
+ ### Fixed
57
+
58
+ - Scripts and test runs no longer hang on exit when an SQLite engine was never disconnected. aiosqlite ≥ 0.22 runs connections on non-daemon threads.
59
+ - `save()` inserts rows whose primary key is set explicitly (`Tag.create(code="py")`, `User.create(id=5)`); they were silently skipped. After `delete()`, `save()` inserts the row again.
60
+ - Relations loaded with `with_relations()` are served from memory instead of being queried again.
61
+ - Concurrent relation accesses (e.g. `asyncio.gather(*(a.posts for a in authors))`) are batched into a single `IN (...)` query.
62
+ - `JSONField` values can be saved; dicts previously raised `ProgrammingError`.
63
+ - Dirty tracking detects in-place mutation (`user.meta["k"] = 2`) and type changes (`26` → `"26"`), with identical results from the Rust and Python implementations.
64
+ - Unit of Work commits are atomic. After a failed commit, in-memory objects are restored (generated ids reset to `None`) and the commit can be retried.
65
+ - Queries:
66
+ - `where(field=None)` and `Field == None` compile to `IS NULL`. They previously compiled to `= NULL`, which is always false, or to `IS ?`, which is invalid on Postgres.
67
+ - An empty `IN` list produces valid SQL.
68
+ - `OFFSET` without `LIMIT` works on SQLite and MySQL.
69
+ - Migrations:
70
+ - Column order in generated `CREATE TABLE` statements is deterministic.
71
+ - Non-integer primary keys keep their type.
72
+ - `DEFAULT` values are emitted.
73
+ - Postgres gets `TIMESTAMP` and `DOUBLE PRECISION` column types.
74
+ - Each migration runs in a transaction.
75
+ - Connection errors during schema introspection are reported instead of being treated as "table does not exist".
76
+ - Model subclasses inherit a custom primary key instead of getting an extra `id` column, and parent field descriptors keep pointing at the parent table.
77
+ - Callable defaults are called per instance, and mutable defaults (`[]`, `{}`) are no longer shared between instances.
78
+ - Postgres inserts return the model's real primary key (it was hard-coded to `id`).
79
+ - Database URLs are parsed with `urllib`: `mysql+aiomysql://`, `postgresql+asyncpg://` and percent-encoded credentials work. MySQL URLs that the old pattern could not parse no longer silently fall back to `root@localhost`.
80
+ - A literal `%` in SQL no longer breaks MySQL queries.
81
+ - `DeferredAutoBatcher` no longer caches results forever and works across event loops.
82
+
83
+ ### Changed
84
+
85
+ - The Rust `StateTracker` stores snapshots as Python objects and compares with `==`. In the bundled benchmark it is about 3.3× faster than the Python implementation.
86
+ - WHERE clauses use table-qualified column names (`users.age > ?`).
87
+ - SQLite connections use autocommit with explicit `BEGIN`/`COMMIT` for transactions.
88
+
89
+ ### CI
90
+
91
+ - Fixed the test workflow. It had never passed, because `maturin develop` requires a virtualenv and the async test dependencies were missing.
92
+ - The suite runs with both the Rust extension and the pure-Python fallback, on Ubuntu and macOS, Python 3.9–3.14.
93
+ - New `rust-lint` job (`cargo fmt --check`, `cargo clippy -D warnings`).
94
+
95
+ ## [0.1.4] - 2026-10-13
96
+
97
+ ### Changed
98
+
99
+ - Pinned `pyo3` back to 0.22.6 (reverting the 0.29.0 upgrade from 0.1.3).
100
+
101
+ ### Documentation
102
+
103
+ - Added benchmark metrics to the relations and batching documentation.
104
+
105
+ ## [0.1.3] - 2026-08-19
106
+
107
+ ### Added
108
+
109
+ - MkDocs documentation site with multilingual search, with expanded guides (getting started, models and fields, query builder, migrations).
110
+
111
+ ### Fixed
112
+
113
+ - CLI migration commands close the engine connection when they finish.
114
+
115
+ ### Changed
116
+
117
+ - Upgraded `pyo3` to 0.29.0.
118
+ - The PyPI publish workflow is no longer triggered by tags and skips already-published files.
119
+
120
+ ## [0.1.2] - 2026-08-17
121
+
122
+ ### Fixed
123
+
124
+ - Wheel packaging of subpackages.
125
+ - Generic typing compatibility with Python 3.9–3.14.
126
+
127
+ ## [0.1.1] - 2026-08-17
128
+
129
+ ### Changed
130
+
131
+ - `QueryBuilder` supports generic types; forward references use postponed annotations.
132
+ - PyPI publish workflow updates.
133
+
134
+ ## [0.1.0] - 2026-08-15
135
+
136
+ ### Added
137
+
138
+ - Initial release:
139
+ - Async ORM core with model field descriptors and a fluent query builder.
140
+ - SQLite, MySQL and PostgreSQL engines.
141
+ - Relationship descriptors with deferred batching.
142
+ - Unit of Work.
143
+ - CLI migrations.
144
+ - Rust core (`_lunarphase_rs`): `StateTracker`, `QueryCompiler`, `BatchAggregator`, `SchemaDiffEngine`.
145
+ - Benchmarking suite.
146
+ - GitHub Actions workflows for CI and PyPI publishing.
147
+
148
+ [0.2.0]: https://github.com/LunarPy-Labs/LunarPhaseORM/compare/v0.1.4...v0.2.0
149
+ [0.1.4]: https://github.com/LunarPy-Labs/LunarPhaseORM/compare/v0.1.3...v0.1.4
150
+ [0.1.3]: https://github.com/LunarPy-Labs/LunarPhaseORM/compare/v0.1.2...v0.1.3
151
+ [0.1.2]: https://github.com/LunarPy-Labs/LunarPhaseORM/compare/v0.1.1...v0.1.2
152
+ [0.1.1]: https://github.com/LunarPy-Labs/LunarPhaseORM/compare/v0.1.0...v0.1.1
153
+ [0.1.0]: https://github.com/LunarPy-Labs/LunarPhaseORM/releases/tag/v0.1.0
@@ -43,7 +43,7 @@ checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
43
43
 
44
44
  [[package]]
45
45
  name = "lunarphase_rs"
46
- version = "0.1.3"
46
+ version = "0.2.0"
47
47
  dependencies = [
48
48
  "pyo3",
49
49
  "rustc-hash",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "lunarphase_rs"
3
- version = "0.1.3"
3
+ version = "0.2.0"
4
4
  edition = "2021"
5
5
  readme = "README.md"
6
6
 
@@ -206,9 +206,9 @@ items, total_count, total_pages = await User.where(User.age > 18).paginate(page=
206
206
 
207
207
  ---
208
208
 
209
- ## 6. Relationships & Auto-Batching Engine (Zero N+1 Query)
209
+ ## 6. Relationships & Auto-Batching Engine (N+1 Query Prevention)
210
210
 
211
- Solving the $N+1$ query problem is automatic in LunarPhaseORM using `DeferredAutoBatcher` micro-task flushing via `asyncio.get_running_loop().call_soon()`.
211
+ Concurrent relation accesses (for example `await asyncio.gather(*(a.posts for a in authors))`) are coalesced into one `WHERE ... IN (...)` query by `DeferredAutoBatcher` micro-task flushing via `asyncio.get_running_loop().call_soon()`. Sequential `await`s in a `for` loop cannot be coalesced; use eager loading (`with_relations`) for those.
212
212
 
213
213
  ### Defining Relationships
214
214
 
@@ -241,10 +241,12 @@ author = await post.author # Returns parent Author
241
241
 
242
242
  ### Eager Loading (`with_relations`)
243
243
 
244
- To load relations up front for multiple items:
244
+ To load relations up front for multiple items (one query per relation; later `await author.posts` calls are served from memory):
245
245
 
246
246
  ```python
247
247
  authors = await Author.where(Author.id > 0).with_relations("posts").all()
248
+ for author in authors:
249
+ posts = await author.posts # no query
248
250
  ```
249
251
 
250
252
  ---
@@ -277,6 +279,10 @@ LunarPhaseORM includes an automated schema diffing CLI powered by Rust `SchemaDi
277
279
  ### CLI Commands
278
280
 
279
281
  ```bash
282
+ # Tell the CLI where the database and the models are (or use --database-url / --models)
283
+ export LUNARPHASE_DATABASE_URL="sqlite:///app.db"
284
+ export LUNARPHASE_MODELS="myapp.models"
285
+
280
286
  # Check migration status
281
287
  lunarphase status
282
288
 
@@ -1,3 +1,23 @@
1
+ Metadata-Version: 2.4
2
+ Name: lunarphase-orm
3
+ Version: 0.2.0
4
+ Classifier: Programming Language :: Python :: 3
5
+ Classifier: Programming Language :: Rust
6
+ Classifier: Framework :: AsyncIO
7
+ Requires-Dist: aiosqlite>=0.19.0
8
+ Requires-Dist: pydantic>=2.0.0
9
+ Requires-Dist: pytest>=7.0 ; extra == 'test'
10
+ Requires-Dist: pytest-asyncio>=0.24 ; extra == 'test'
11
+ Requires-Dist: pytest-cov>=4.0 ; extra == 'test'
12
+ Requires-Dist: pytest-benchmark>=4.0 ; extra == 'test'
13
+ Provides-Extra: test
14
+ License-File: LICENSE
15
+ Summary: Smart, Async-Native, High-Performance Python & Rust Object-Relational Mapper
16
+ Keywords: orm,async,sqlite,postgres,mysql,rust,active-record,data-mapper
17
+ Author: LunarPy-Labs
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
20
+
1
21
  <div align="center">
2
22
  <img width="220" height="220" alt="LunarPhaseORM logo" src="https://github.com/user-attachments/assets/32b24c36-eb89-4736-b288-9745280f78c5" />
3
23
 
@@ -23,7 +43,7 @@
23
43
  ## ✨ Key Features
24
44
 
25
45
  - 🦀 **Rust-Powered Performance**: Offloads snapshot isolation state tracking, dirty diffing, AST compilation, and schema diffing to C-level Rust structs (`_lunarphase_rs`), drastically reducing Python RAM overhead.
26
- - ⚡ **Zero N+1 Query Problem**: Solves N+1 query issues automatically via `asyncio` event loop micro-task flushing (`DeferredAutoBatcher`). Relation access inside loops is automatically batched into single `WHERE id IN (...)` queries.
46
+ - ⚡ **N+1 Query Prevention**: Concurrent relation access (e.g. `asyncio.gather(*(a.posts for a in authors))`) is coalesced into a single `WHERE ... IN (...)` query via `asyncio` event loop micro-task flushing (`DeferredAutoBatcher`). For plain `for` loops, `with_relations()` eager-loads every relation in one query per relation.
27
47
  - 🎯 **Precise Dirty Tracking**: Computes dirty attribute diffs in Rust. Calling `await user.save()` executes SQL `UPDATE` only on modified columns, and skips database I/O completely if no fields were altered.
28
48
  - 🛡️ **Type-Safe Query Builder**: Fluent API with native Python operator overloading (`User.age > 18`) producing AST query nodes cleanly.
29
49
  - 🔄 **Unit of Work & Session Transactions**: Guarantees object identity via `IdentityMap` and provides atomic transaction blocks (`async with session.begin()`) with automatic rollback on failure.
@@ -46,8 +66,11 @@ git clone https://github.com/LunarPy-Labs/LunarPhaseORM.git
46
66
  cd LunarPhaseORM
47
67
  python3 -m venv .venv
48
68
  source .venv/bin/activate
49
- pip install maturin aiosqlite pydantic
50
- maturin develop
69
+ pip install maturin
70
+ maturin develop --extras test # builds the Rust core + installs test dependencies
71
+
72
+ pytest --benchmark-disable # with the Rust core
73
+ LUNARPHASE_DISABLE_RUST=1 pytest --benchmark-disable # pure-Python fallback
51
74
  ```
52
75
 
53
76
  ---
@@ -96,17 +119,21 @@ async def main():
96
119
  await Post.create(title="A Study in Scarlet", author_id=author.id)
97
120
  await Post.create(title="The Sign of the Four", author_id=author.id)
98
121
 
99
- # 5. Access Relations (Zero N+1 Query Problem!)
100
- fetched_author = await Author.where(name="Arthur Conan Doyle").first()
101
- posts = await fetched_author.posts
102
- print(f"Author: {fetched_author.name}")
103
- for p in posts:
104
- print(f" - Post: {p.title}")
122
+ # 5. Access Relations (eager-loaded: 1 query for all authors' posts)
123
+ authors = await Author.with_relations("posts").all()
124
+ for fetched_author in authors:
125
+ print(f"Author: {fetched_author.name}")
126
+ for p in await fetched_author.posts: # served from memory, no query
127
+ print(f" - Post: {p.title}")
105
128
 
106
129
  # 6. Precise Dirty Tracking Update
130
+ fetched_author = authors[0]
107
131
  fetched_author.name = "Sir Arthur Conan Doyle"
108
132
  await fetched_author.save() # Updates ONLY 'name' column in SQL!
109
133
 
134
+ # 7. Close the connection (or use `async with create_engine(...) as engine:`)
135
+ await engine.disconnect()
136
+
110
137
  if __name__ == "__main__":
111
138
  asyncio.run(main())
112
139
  ```
@@ -128,9 +155,12 @@ if __name__ == "__main__":
128
155
 
129
156
  ## 🛠 CLI Migration Commands
130
157
 
131
- LunarPhaseORM includes a command-line tool for managing schema migrations:
158
+ LunarPhaseORM includes a command-line tool for managing schema migrations. Point it at your database and your models module (flags or environment variables):
132
159
 
133
160
  ```bash
161
+ export LUNARPHASE_DATABASE_URL="sqlite:///app.db" # or --database-url
162
+ export LUNARPHASE_MODELS="myapp.models" # or --models (make:migration only)
163
+
134
164
  # Check migration status
135
165
  lunarphase status
136
166
 
@@ -164,9 +194,11 @@ For full timeline details, research disclaimers, and milestone tracking, see [RO
164
194
 
165
195
  For in-depth technical documentation, API references, and advanced usage patterns, read [DOCUMENTATION.md](DOCUMENTATION.md).
166
196
  For detailed empirical benchmark reports, execution speeds, and memory metrics, read [BENCHMARK.md](BENCHMARK.md).
197
+ For release notes and upgrade instructions (including the breaking changes in 0.2.0), read [CHANGELOG.md](CHANGELOG.md).
167
198
 
168
199
  ---
169
200
 
170
201
  ## 📄 License
171
202
 
172
203
  This project is licensed under the [MIT License](LICENSE).
204
+
@@ -1,18 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: lunarphase-orm
3
- Version: 0.1.3
4
- Classifier: Programming Language :: Python :: 3
5
- Classifier: Programming Language :: Rust
6
- Classifier: Framework :: AsyncIO
7
- Requires-Dist: aiosqlite>=0.19.0
8
- Requires-Dist: pydantic>=2.0.0
9
- License-File: LICENSE
10
- Summary: Smart, Async-Native, High-Performance Python & Rust Object-Relational Mapper
11
- Keywords: orm,async,sqlite,postgres,mysql,rust,active-record,data-mapper
12
- Author: LunarPy-Labs
13
- Requires-Python: >=3.9
14
- Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
15
-
16
1
  <div align="center">
17
2
  <img width="220" height="220" alt="LunarPhaseORM logo" src="https://github.com/user-attachments/assets/32b24c36-eb89-4736-b288-9745280f78c5" />
18
3
 
@@ -38,7 +23,7 @@ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
38
23
  ## ✨ Key Features
39
24
 
40
25
  - 🦀 **Rust-Powered Performance**: Offloads snapshot isolation state tracking, dirty diffing, AST compilation, and schema diffing to C-level Rust structs (`_lunarphase_rs`), drastically reducing Python RAM overhead.
41
- - ⚡ **Zero N+1 Query Problem**: Solves N+1 query issues automatically via `asyncio` event loop micro-task flushing (`DeferredAutoBatcher`). Relation access inside loops is automatically batched into single `WHERE id IN (...)` queries.
26
+ - ⚡ **N+1 Query Prevention**: Concurrent relation access (e.g. `asyncio.gather(*(a.posts for a in authors))`) is coalesced into a single `WHERE ... IN (...)` query via `asyncio` event loop micro-task flushing (`DeferredAutoBatcher`). For plain `for` loops, `with_relations()` eager-loads every relation in one query per relation.
42
27
  - 🎯 **Precise Dirty Tracking**: Computes dirty attribute diffs in Rust. Calling `await user.save()` executes SQL `UPDATE` only on modified columns, and skips database I/O completely if no fields were altered.
43
28
  - 🛡️ **Type-Safe Query Builder**: Fluent API with native Python operator overloading (`User.age > 18`) producing AST query nodes cleanly.
44
29
  - 🔄 **Unit of Work & Session Transactions**: Guarantees object identity via `IdentityMap` and provides atomic transaction blocks (`async with session.begin()`) with automatic rollback on failure.
@@ -61,8 +46,11 @@ git clone https://github.com/LunarPy-Labs/LunarPhaseORM.git
61
46
  cd LunarPhaseORM
62
47
  python3 -m venv .venv
63
48
  source .venv/bin/activate
64
- pip install maturin aiosqlite pydantic
65
- maturin develop
49
+ pip install maturin
50
+ maturin develop --extras test # builds the Rust core + installs test dependencies
51
+
52
+ pytest --benchmark-disable # with the Rust core
53
+ LUNARPHASE_DISABLE_RUST=1 pytest --benchmark-disable # pure-Python fallback
66
54
  ```
67
55
 
68
56
  ---
@@ -111,17 +99,21 @@ async def main():
111
99
  await Post.create(title="A Study in Scarlet", author_id=author.id)
112
100
  await Post.create(title="The Sign of the Four", author_id=author.id)
113
101
 
114
- # 5. Access Relations (Zero N+1 Query Problem!)
115
- fetched_author = await Author.where(name="Arthur Conan Doyle").first()
116
- posts = await fetched_author.posts
117
- print(f"Author: {fetched_author.name}")
118
- for p in posts:
119
- print(f" - Post: {p.title}")
102
+ # 5. Access Relations (eager-loaded: 1 query for all authors' posts)
103
+ authors = await Author.with_relations("posts").all()
104
+ for fetched_author in authors:
105
+ print(f"Author: {fetched_author.name}")
106
+ for p in await fetched_author.posts: # served from memory, no query
107
+ print(f" - Post: {p.title}")
120
108
 
121
109
  # 6. Precise Dirty Tracking Update
110
+ fetched_author = authors[0]
122
111
  fetched_author.name = "Sir Arthur Conan Doyle"
123
112
  await fetched_author.save() # Updates ONLY 'name' column in SQL!
124
113
 
114
+ # 7. Close the connection (or use `async with create_engine(...) as engine:`)
115
+ await engine.disconnect()
116
+
125
117
  if __name__ == "__main__":
126
118
  asyncio.run(main())
127
119
  ```
@@ -143,9 +135,12 @@ if __name__ == "__main__":
143
135
 
144
136
  ## 🛠 CLI Migration Commands
145
137
 
146
- LunarPhaseORM includes a command-line tool for managing schema migrations:
138
+ LunarPhaseORM includes a command-line tool for managing schema migrations. Point it at your database and your models module (flags or environment variables):
147
139
 
148
140
  ```bash
141
+ export LUNARPHASE_DATABASE_URL="sqlite:///app.db" # or --database-url
142
+ export LUNARPHASE_MODELS="myapp.models" # or --models (make:migration only)
143
+
149
144
  # Check migration status
150
145
  lunarphase status
151
146
 
@@ -179,10 +174,10 @@ For full timeline details, research disclaimers, and milestone tracking, see [RO
179
174
 
180
175
  For in-depth technical documentation, API references, and advanced usage patterns, read [DOCUMENTATION.md](DOCUMENTATION.md).
181
176
  For detailed empirical benchmark reports, execution speeds, and memory metrics, read [BENCHMARK.md](BENCHMARK.md).
177
+ For release notes and upgrade instructions (including the breaking changes in 0.2.0), read [CHANGELOG.md](CHANGELOG.md).
182
178
 
183
179
  ---
184
180
 
185
181
  ## 📄 License
186
182
 
187
183
  This project is licensed under the [MIT License](LICENSE).
188
-
@@ -19,7 +19,7 @@ Verify the package installation in Python:
19
19
  ```python
20
20
  import lunarphase
21
21
  print(lunarphase.__version__)
22
- # Output: 0.1.3
22
+ # Output: 0.2.0
23
23
  ```
24
24
 
25
25
  ---
@@ -17,6 +17,31 @@ The `lunarphase` CLI manages database schema migrations, status inspections, and
17
17
  | `lunarphase migrate` | Applies all pending migrations sequentially | `lunarphase migrate` |
18
18
  | `lunarphase rollback` | Rolls back the most recently applied migration | `lunarphase rollback` |
19
19
 
20
+ ### Configuration
21
+
22
+ Every command needs to know which database to use; `make:migration` also needs to know where your models live. Use flags or environment variables:
23
+
24
+ | Flag | Environment variable | Purpose |
25
+ |---|---|---|
26
+ | `--database-url`, `-d` | `LUNARPHASE_DATABASE_URL` | Database URL, e.g. `sqlite:///app.db`, `postgresql://user:pass@host/db`, `mysql://user:pass@host/db` |
27
+ | `--models`, `-m` (repeatable) | `LUNARPHASE_MODELS` (comma-separated) | Importable module(s) that define your models, e.g. `myapp.models` |
28
+ | `--migrations-dir` | `LUNARPHASE_MIGRATIONS_DIR` | Where migration files live (default: `migrations`) |
29
+
30
+ ```bash
31
+ lunarphase make:migration "create_users_table" --models myapp.models --database-url sqlite:///app.db
32
+ lunarphase migrate --database-url sqlite:///app.db
33
+ ```
34
+
35
+ Modules are imported from the current directory. Base classes that should not get a table are marked abstract:
36
+
37
+ ```python
38
+ class TimestampedModel(Model):
39
+ __abstract__ = True
40
+ created_at = DateTimeField()
41
+ ```
42
+
43
+ The CLI exits with status `0` on success, `1` when a command fails and `2` for configuration errors.
44
+
20
45
  ---
21
46
 
22
47
  ## 2. Step-by-Step CLI Migration Walkthrough
@@ -29,7 +54,7 @@ Check current database migration state:
29
54
  $ lunarphase status
30
55
 
31
56
  --- LunarPhaseORM Migration Status ---
32
- No migrations applied yet.
57
+ No migrations found.
33
58
  --------------------------------------
34
59
  ```
35
60
 
@@ -38,10 +63,18 @@ No migrations applied yet.
38
63
  Generate a new migration script based on your defined models:
39
64
 
40
65
  ```bash
41
- $ lunarphase make:migration "create_users_table"
66
+ $ lunarphase make:migration "create_users_table" --models myapp.models
42
67
  Created migration file: migrations/1723872000_create_users_table.py
43
68
  ```
44
69
 
70
+ The diff compares each model with the live table:
71
+
72
+ - a missing table becomes `CREATE TABLE` (columns in declaration order, with `NOT NULL` and literal `DEFAULT`s);
73
+ - a model field missing from the table becomes `ADD COLUMN` (a `NOT NULL` column without a default is added as nullable, because existing rows would violate it);
74
+ - a table column no longer declared on the model becomes `DROP COLUMN`. **Review generated files before running them**: dropping a column deletes its data. On SQLite, `DROP COLUMN` (also used by the downgrade of `ADD COLUMN`) requires SQLite 3.35 or newer.
75
+
76
+ Column type changes are not detected yet.
77
+
45
78
  ### Step 2.3: Generated Migration File Structure
46
79
 
47
80
  The CLI creates a Python migration script exporting `upgrade(engine)` and `downgrade(engine)` functions:
@@ -69,7 +102,7 @@ async def downgrade(engine):
69
102
 
70
103
  ### Step 2.4: Applying Migrations (`lunarphase migrate`)
71
104
 
72
- Execute pending migrations:
105
+ Execute pending migrations. Each migration and its bookkeeping row run in one transaction, so a failing migration leaves no partial changes (except on MySQL, where DDL commits implicitly):
73
106
 
74
107
  ```bash
75
108
  $ lunarphase migrate