sqlacodegen 3.2.0__tar.gz → 4.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.
Files changed (37) hide show
  1. sqlacodegen-4.0.0/.github/FUNDING.yml +1 -0
  2. sqlacodegen-4.0.0/.github/dependabot.yml +13 -0
  3. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.github/workflows/publish.yml +8 -5
  4. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.github/workflows/test.yml +3 -3
  5. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.pre-commit-config.yaml +2 -2
  6. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/CHANGES.rst +49 -0
  7. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/PKG-INFO +27 -7
  8. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/README.rst +26 -0
  9. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/pyproject.toml +10 -8
  10. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen/generators.py +386 -119
  11. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen/utils.py +1 -7
  12. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen.egg-info/PKG-INFO +27 -7
  13. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen.egg-info/SOURCES.txt +2 -0
  14. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen.egg-info/requires.txt +0 -7
  15. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/tests/test_generator_declarative.py +1094 -27
  16. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/tests/test_generator_sqlmodel.py +126 -1
  17. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/tests/test_generator_tables.py +177 -5
  18. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
  19. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  20. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.github/ISSUE_TEMPLATE/features_request.yaml +0 -0
  21. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.github/pull_request_template.md +0 -0
  22. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/.gitignore +0 -0
  23. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/CONTRIBUTING.rst +0 -0
  24. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/LICENSE +0 -0
  25. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/setup.cfg +0 -0
  26. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen/__init__.py +0 -0
  27. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen/__main__.py +0 -0
  28. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen/cli.py +0 -0
  29. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen/models.py +0 -0
  30. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen/py.typed +0 -0
  31. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen.egg-info/dependency_links.txt +0 -0
  32. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen.egg-info/entry_points.txt +0 -0
  33. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/src/sqlacodegen.egg-info/top_level.txt +0 -0
  34. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/tests/__init__.py +0 -0
  35. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/tests/conftest.py +0 -0
  36. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/tests/test_cli.py +0 -0
  37. {sqlacodegen-3.2.0 → sqlacodegen-4.0.0}/tests/test_generator_dataclass.py +0 -0
@@ -0,0 +1 @@
1
+ tidelift: pypi/sqlacodegen
@@ -0,0 +1,13 @@
1
+ # Keep GitHub Actions up to date with GitHub's Dependabot...
2
+ # https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
3
+ # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
4
+ version: 2
5
+ updates:
6
+ - package-ecosystem: github-actions
7
+ directory: /
8
+ groups:
9
+ github-actions:
10
+ patterns:
11
+ - "*" # Group all Actions updates into a single larger pull request
12
+ schedule:
13
+ interval: quarterly
@@ -14,9 +14,9 @@ jobs:
14
14
  runs-on: ubuntu-latest
15
15
  environment: release
16
16
  steps:
17
- - uses: actions/checkout@v4
17
+ - uses: actions/checkout@v6
18
18
  - name: Set up Python
19
- uses: actions/setup-python@v5
19
+ uses: actions/setup-python@v6
20
20
  with:
21
21
  python-version: 3.x
22
22
  - name: Install dependencies
@@ -24,7 +24,7 @@ jobs:
24
24
  - name: Create packages
25
25
  run: python -m build
26
26
  - name: Archive packages
27
- uses: actions/upload-artifact@v4
27
+ uses: actions/upload-artifact@v6
28
28
  with:
29
29
  name: dist
30
30
  path: dist
@@ -38,7 +38,10 @@ jobs:
38
38
  id-token: write
39
39
  steps:
40
40
  - name: Retrieve packages
41
- uses: actions/download-artifact@v4
41
+ uses: actions/download-artifact@v7
42
+ with:
43
+ name: dist
44
+ path: dist
42
45
  - name: Upload packages
43
46
  uses: pypa/gh-action-pypi-publish@release/v1
44
47
 
@@ -49,7 +52,7 @@ jobs:
49
52
  permissions:
50
53
  contents: write
51
54
  steps:
52
- - uses: actions/checkout@v4
55
+ - uses: actions/checkout@v6
53
56
  - id: changelog
54
57
  uses: agronholm/release-notes@v1
55
58
  with:
@@ -13,16 +13,16 @@ jobs:
13
13
  python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
14
14
  runs-on: ubuntu-latest
15
15
  steps:
16
- - uses: actions/checkout@v4
16
+ - uses: actions/checkout@v6
17
17
  - name: Set up Python ${{ matrix.python-version }}
18
- uses: actions/setup-python@v5
18
+ uses: actions/setup-python@v6
19
19
  with:
20
20
  python-version: ${{ matrix.python-version }}
21
21
  allow-prereleases: true
22
22
  cache: pip
23
23
  cache-dependency-path: pyproject.toml
24
24
  - name: Install dependencies
25
- run: pip install -e .[test]
25
+ run: pip install --group test -e .[sqlmodel,citext,geoalchemy2,pgvector]
26
26
  - name: Test with pytest
27
27
  run: coverage run -m pytest
28
28
  - name: Upload Coverage
@@ -16,14 +16,14 @@ repos:
16
16
  - id: trailing-whitespace
17
17
 
18
18
  - repo: https://github.com/astral-sh/ruff-pre-commit
19
- rev: v0.13.3
19
+ rev: v0.14.10
20
20
  hooks:
21
21
  - id: ruff
22
22
  args: [--fix, --show-fixes]
23
23
  - id: ruff-format
24
24
 
25
25
  - repo: https://github.com/pre-commit/mirrors-mypy
26
- rev: v1.18.2
26
+ rev: v1.19.1
27
27
  hooks:
28
28
  - id: mypy
29
29
  additional_dependencies:
@@ -1,6 +1,55 @@
1
1
  Version history
2
2
  ===============
3
3
 
4
+ **4.0.0**
5
+
6
+ - **BACKWARD INCOMPATIBLE** API changes (for those who customize code generation by
7
+ subclassing the existing generators):
8
+
9
+ * Added new optional keyword argument, ``explicit_foreign_keys`` to
10
+ ``DeclarativeGenerator``, to force foreign keys to be rendered as
11
+ ``ClassName.attribute_name`` string references
12
+ * Removed the ``render_relationship_args()`` method from the SQLModel generator
13
+ * Added two new methods for customizing relationship rendering in
14
+ ``DeclarativeGenerator``:
15
+
16
+ * ``render_relationship_annotation()``: returns the appropriate type annotation
17
+ (without the ``Mapped`` wrapper) for the relationship
18
+ * ``render_relationship_arguments()``: returns a dictionary of keyword arguments to
19
+ ``sqlalchemy.orm.relationship()``
20
+
21
+ **4.0.0rc3**
22
+
23
+ - **BACKWARD INCOMPATIBLE** Relationship names changed when multiple FKs or junction tables
24
+ connect to the same target table. Regenerating models will break existing code.
25
+ - Added support for generating Python enum classes for ``ARRAY(Enum(...))`` columns
26
+ (e.g., PostgreSQL ``ARRAY(ENUM)``). Supports named/unnamed enums, shared enums across
27
+ columns, and multi-dimensional arrays. Respects ``--options nonativeenums``.
28
+ (PR by @sheinbergon)
29
+ - Improved relationship naming: one-to-many uses FK column names (e.g.,
30
+ ``simple_items_parent_container``), many-to-many uses junction table names (e.g.,
31
+ ``students_enrollments``). Use ``--options nofknames`` to revert to old behavior. (PR by @sheinbergon)
32
+ - Fixed ``Index`` kwargs (e.g. ``mysql_length``) being ignored during code generation
33
+ (PR by @luliangce)
34
+ - Fixed the SQLModel generator not adding the ``foreign_keys`` parameters when
35
+ generating multiple relationships between the same two tables
36
+
37
+ **4.0.0rc2**
38
+
39
+ - Add ``values_callable`` lambda to generated native enums column definitions.
40
+ This allows for proper enum value insertion when working with ORM models (PR by @sheinbergon)
41
+
42
+ **4.0.0rc1**
43
+
44
+ - **BACKWARD INCOMPATIBLE** ``TablesGenerator.render_column_type()`` was changed to
45
+ receive the ``Column`` object instead of the column type object as its sole argument
46
+ - Added Python enum generation for native database ENUM types (e.g., PostgreSQL / MySQL ENUM).
47
+ Retained synthetic Python enum generation from CHECK constraints with
48
+ IN clauses (e.g., ``column IN ('val1', 'val2', ...)``). Use ``--options nonativeenums`` to
49
+ disable enum generation for native database enums. Use ``--options nosyntheticenums`` to
50
+ disable enum generation for synthetic database enums (VARCHAR columns with check constraints).
51
+ (PR by @sheinbergon)
52
+
4
53
  **3.2.0**
5
54
 
6
55
  - Dropped support for Python 3.9
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlacodegen
3
- Version: 3.2.0
3
+ Version: 4.0.0
4
4
  Summary: Automatic model code generator for SQLAlchemy
5
5
  Author-email: Alex Grönholm <alex.gronholm@nextday.fi>
6
6
  Maintainer-email: Idan Sheinberg <ishinberg0@gmail.com>
@@ -25,12 +25,6 @@ Description-Content-Type: text/x-rst
25
25
  License-File: LICENSE
26
26
  Requires-Dist: SQLAlchemy>=2.0.29
27
27
  Requires-Dist: inflect>=4.0.0
28
- Provides-Extra: test
29
- Requires-Dist: sqlacodegen[geoalchemy2,pgvector,sqlmodel]; extra == "test"
30
- Requires-Dist: pytest>=7.4; extra == "test"
31
- Requires-Dist: coverage>=7; extra == "test"
32
- Requires-Dist: psycopg[binary]; extra == "test"
33
- Requires-Dist: mysql-connector-python; extra == "test"
34
28
  Provides-Extra: sqlmodel
35
29
  Requires-Dist: sqlmodel>=0.0.22; extra == "sqlmodel"
36
30
  Provides-Extra: citext
@@ -47,6 +41,9 @@ Dynamic: license-file
47
41
  .. image:: https://coveralls.io/repos/github/agronholm/sqlacodegen/badge.svg?branch=master
48
42
  :target: https://coveralls.io/github/agronholm/sqlacodegen?branch=master
49
43
  :alt: Code Coverage
44
+ .. image:: https://tidelift.com/badges/package/pypi/sqlacodegen
45
+ :target: https://tidelift.com/subscription/pkg/pypi-sqlacodegen
46
+ :alt: Tidelift
50
47
 
51
48
  This is a tool that reads the structure of an existing database and generates the
52
49
  appropriate SQLAlchemy model code, using the declarative style if possible.
@@ -146,6 +143,8 @@ values must be delimited by commas, e.g. ``--options noconstraints,nobidi``):
146
143
  * ``noconstraints``: ignore constraints (foreign key, unique etc.)
147
144
  * ``nocomments``: ignore table/column comments
148
145
  * ``noindexes``: ignore indexes
146
+ * ``nonativeenums``: don't generate Python enum classes for native database ENUM types (e.g., PostgreSQL ENUM); use plain string mapping instead
147
+ * ``nosyntheticenums``: don't generate Python enum classes from CHECK constraints with IN clauses (e.g., ``column IN ('value1', 'value2', ...)``); preserves CHECK constraints as-is
149
148
  * ``noidsuffix``: prevent the special naming logic for single column many-to-one
150
149
  and one-to-one relationships (see `Relationship naming logic`_ for details)
151
150
  * ``include_dialect_options``: render a table' dialect options, such as ``starrocks_partition`` for StarRocks' specific options.
@@ -160,6 +159,11 @@ values must be delimited by commas, e.g. ``--options noconstraints,nobidi``):
160
159
  * ``nobidi``: generate relationships in a unidirectional fashion, so only the
161
160
  many-to-one or first side of many-to-many relationships gets a relationship
162
161
  attribute, as on v2.X
162
+ * ``nofknames``: disable improved relationship naming when multiple FKs or
163
+ junction tables connect to the same target. By default, uses FK column names
164
+ for one-to-many (e.g., ``simple_items_parent_container``) and junction table
165
+ names for many-to-many (e.g., ``students_enrollments``). Reverts to
166
+ underscore suffixes (``simple_items_``, ``student_``).
163
167
 
164
168
  * ``dataclasses``
165
169
 
@@ -227,6 +231,14 @@ due to that ``_id`` suffix.
227
231
  For self referential relationships, the reverse side of the relationship will be named
228
232
  with the ``_reverse`` suffix appended to it.
229
233
 
234
+ When multiple foreign keys or junction tables connect to the same target table,
235
+ relationships use qualifiers for disambiguation. One-to-many relationships use FK
236
+ column names (e.g., ``simple_items_parent_container``, ``simple_items_top_container``).
237
+ Many-to-many relationships use junction table names (e.g., ``students_enrollments``,
238
+ ``students_waitlist``), except for self-referential cases which use FK column names
239
+ (e.g., ``parent``, ``child``). The ``nofknames`` option reverts to underscore suffixes
240
+ (``simple_items_``, ``student_``).
241
+
230
242
  Customizing code generation logic
231
243
  =================================
232
244
 
@@ -251,3 +263,11 @@ sqlalchemy_ room on Gitter.
251
263
 
252
264
  .. _sqlacodegen discussion forum: https://github.com/agronholm/sqlacodegen/discussions/categories/q-a
253
265
  .. _sqlalchemy: https://app.gitter.im/#/room/#sqlalchemy_community:gitter.im
266
+
267
+ Security contact information
268
+ ============================
269
+
270
+ To report a security vulnerability, please use the `Tidelift security contact`_.
271
+ Tidelift will coordinate the fix and disclosure.
272
+
273
+ .. _Tidelift security contact: https://tidelift.com/security
@@ -4,6 +4,9 @@
4
4
  .. image:: https://coveralls.io/repos/github/agronholm/sqlacodegen/badge.svg?branch=master
5
5
  :target: https://coveralls.io/github/agronholm/sqlacodegen?branch=master
6
6
  :alt: Code Coverage
7
+ .. image:: https://tidelift.com/badges/package/pypi/sqlacodegen
8
+ :target: https://tidelift.com/subscription/pkg/pypi-sqlacodegen
9
+ :alt: Tidelift
7
10
 
8
11
  This is a tool that reads the structure of an existing database and generates the
9
12
  appropriate SQLAlchemy model code, using the declarative style if possible.
@@ -103,6 +106,8 @@ values must be delimited by commas, e.g. ``--options noconstraints,nobidi``):
103
106
  * ``noconstraints``: ignore constraints (foreign key, unique etc.)
104
107
  * ``nocomments``: ignore table/column comments
105
108
  * ``noindexes``: ignore indexes
109
+ * ``nonativeenums``: don't generate Python enum classes for native database ENUM types (e.g., PostgreSQL ENUM); use plain string mapping instead
110
+ * ``nosyntheticenums``: don't generate Python enum classes from CHECK constraints with IN clauses (e.g., ``column IN ('value1', 'value2', ...)``); preserves CHECK constraints as-is
106
111
  * ``noidsuffix``: prevent the special naming logic for single column many-to-one
107
112
  and one-to-one relationships (see `Relationship naming logic`_ for details)
108
113
  * ``include_dialect_options``: render a table' dialect options, such as ``starrocks_partition`` for StarRocks' specific options.
@@ -117,6 +122,11 @@ values must be delimited by commas, e.g. ``--options noconstraints,nobidi``):
117
122
  * ``nobidi``: generate relationships in a unidirectional fashion, so only the
118
123
  many-to-one or first side of many-to-many relationships gets a relationship
119
124
  attribute, as on v2.X
125
+ * ``nofknames``: disable improved relationship naming when multiple FKs or
126
+ junction tables connect to the same target. By default, uses FK column names
127
+ for one-to-many (e.g., ``simple_items_parent_container``) and junction table
128
+ names for many-to-many (e.g., ``students_enrollments``). Reverts to
129
+ underscore suffixes (``simple_items_``, ``student_``).
120
130
 
121
131
  * ``dataclasses``
122
132
 
@@ -184,6 +194,14 @@ due to that ``_id`` suffix.
184
194
  For self referential relationships, the reverse side of the relationship will be named
185
195
  with the ``_reverse`` suffix appended to it.
186
196
 
197
+ When multiple foreign keys or junction tables connect to the same target table,
198
+ relationships use qualifiers for disambiguation. One-to-many relationships use FK
199
+ column names (e.g., ``simple_items_parent_container``, ``simple_items_top_container``).
200
+ Many-to-many relationships use junction table names (e.g., ``students_enrollments``,
201
+ ``students_waitlist``), except for self-referential cases which use FK column names
202
+ (e.g., ``parent``, ``child``). The ``nofknames`` option reverts to underscore suffixes
203
+ (``simple_items_``, ``student_``).
204
+
187
205
  Customizing code generation logic
188
206
  =================================
189
207
 
@@ -208,3 +226,11 @@ sqlalchemy_ room on Gitter.
208
226
 
209
227
  .. _sqlacodegen discussion forum: https://github.com/agronholm/sqlacodegen/discussions/categories/q-a
210
228
  .. _sqlalchemy: https://app.gitter.im/#/room/#sqlalchemy_community:gitter.im
229
+
230
+ Security contact information
231
+ ============================
232
+
233
+ To report a security vulnerability, please use the `Tidelift security contact`_.
234
+ Tidelift will coordinate the fix and disclosure.
235
+
236
+ .. _Tidelift security contact: https://tidelift.com/security
@@ -39,13 +39,6 @@ dynamic = ["version"]
39
39
  "Source Code" = "https://github.com/agronholm/sqlacodegen"
40
40
 
41
41
  [project.optional-dependencies]
42
- test = [
43
- "sqlacodegen[sqlmodel,pgvector,geoalchemy2]",
44
- "pytest >= 7.4",
45
- "coverage >= 7",
46
- "psycopg[binary]",
47
- "mysql-connector-python",
48
- ]
49
42
  sqlmodel = ["sqlmodel >= 0.0.22"]
50
43
  citext = ["sqlalchemy-citext >= 1.7.0"]
51
44
  geoalchemy2 = ["geoalchemy2 >= 0.17.0"]
@@ -60,6 +53,14 @@ sqlmodels = "sqlacodegen.generators:SQLModelGenerator"
60
53
  [project.scripts]
61
54
  sqlacodegen = "sqlacodegen.cli:main"
62
55
 
56
+ [dependency-groups]
57
+ test = [
58
+ "pytest >= 7.4",
59
+ "coverage >= 7",
60
+ "psycopg[binary]",
61
+ "mysql-connector-python",
62
+ ]
63
+
63
64
  [tool.setuptools_scm]
64
65
  version_scheme = "post-release"
65
66
  local_scheme = "dirty-tag"
@@ -99,4 +100,5 @@ skip_missing_interpreters = true
99
100
  [tool.tox.env_run_base]
100
101
  package = "editable"
101
102
  commands = [["python", "-m", "pytest", { replace = "posargs", extend = true }]]
102
- extras = ["test"]
103
+ dependency_groups = ["test"]
104
+ extras = ["sqlmodel", "citext", "geoalchemy2", "pgvector"]