🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More
Socket
Book a DemoSign in
Socket

sqlacodegen

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqlacodegen - pypi Package Compare versions

Comparing version
4.0.0rc2
to
4.0.0rc3
+16
-2
CHANGES.rst
Version history
===============
**4.0.0rc3**
- **BACKWARD INCOMPATIBLE** Relationship names changed when multiple FKs or junction tables
connect to the same target table. Regenerating models will break existing code.
- Added support for generating Python enum classes for ``ARRAY(Enum(...))`` columns
(e.g., PostgreSQL ``ARRAY(ENUM)``). Supports named/unnamed enums, shared enums across
columns, and multi-dimensional arrays. Respects ``--options nonativeenums``.
(PR by @sheinbergon)
- Improved relationship naming: one-to-many uses FK column names (e.g.,
``simple_items_parent_container``), many-to-many uses junction table names (e.g.,
``students_enrollments``). Use ``--options nofknames`` to revert to old behavior. (PR by @sheinbergon)
- Fixed ``Index`` kwargs (e.g. ``mysql_length``) being ignored during code generation
(PR by @luliangce)
**4.0.0rc2**
- Add ``values_callable`` lambda to generated native enums column definitions.
This allows for proper enum value insertion when working with ORM models (PR by @sheinbergon)
- Add ``values_callable`` lambda to generated native enums column definitions.
This allows for proper enum value insertion when working with ORM models (PR by @sheinbergon)

@@ -9,0 +23,0 @@ **4.0.0rc1**

Metadata-Version: 2.4
Name: sqlacodegen
Version: 4.0.0rc2
Version: 4.0.0rc3
Summary: Automatic model code generator for SQLAlchemy

@@ -162,2 +162,7 @@ Author-email: Alex Grönholm <alex.gronholm@nextday.fi>

attribute, as on v2.X
* ``nofknames``: disable improved relationship naming when multiple FKs or
junction tables connect to the same target. By default, uses FK column names
for one-to-many (e.g., ``simple_items_parent_container``) and junction table
names for many-to-many (e.g., ``students_enrollments``). Reverts to
underscore suffixes (``simple_items_``, ``student_``).

@@ -230,2 +235,10 @@ * ``dataclasses``

When multiple foreign keys or junction tables connect to the same target table,
relationships use qualifiers for disambiguation. One-to-many relationships use FK
column names (e.g., ``simple_items_parent_container``, ``simple_items_top_container``).
Many-to-many relationships use junction table names (e.g., ``students_enrollments``,
``students_waitlist``), except for self-referential cases which use FK column names
(e.g., ``parent``, ``child``). The ``nofknames`` option reverts to underscore suffixes
(``simple_items_``, ``student_``).
Customizing code generation logic

@@ -232,0 +245,0 @@ =================================

@@ -125,2 +125,7 @@ .. image:: https://github.com/agronholm/sqlacodegen/actions/workflows/test.yml/badge.svg

attribute, as on v2.X
* ``nofknames``: disable improved relationship naming when multiple FKs or
junction tables connect to the same target. By default, uses FK column names
for one-to-many (e.g., ``simple_items_parent_container``) and junction table
names for many-to-many (e.g., ``students_enrollments``). Reverts to
underscore suffixes (``simple_items_``, ``student_``).

@@ -193,2 +198,10 @@ * ``dataclasses``

When multiple foreign keys or junction tables connect to the same target table,
relationships use qualifiers for disambiguation. One-to-many relationships use FK
column names (e.g., ``simple_items_parent_container``, ``simple_items_top_container``).
Many-to-many relationships use junction table names (e.g., ``students_enrollments``,
``students_waitlist``), except for self-referential cases which use FK column names
(e.g., ``parent``, ``child``). The ``nofknames`` option reverts to underscore suffixes
(``simple_items_``, ``student_``).
Customizing code generation logic

@@ -195,0 +208,0 @@ =================================

Metadata-Version: 2.4
Name: sqlacodegen
Version: 4.0.0rc2
Version: 4.0.0rc3
Summary: Automatic model code generator for SQLAlchemy

@@ -162,2 +162,7 @@ Author-email: Alex Grönholm <alex.gronholm@nextday.fi>

attribute, as on v2.X
* ``nofknames``: disable improved relationship naming when multiple FKs or
junction tables connect to the same target. By default, uses FK column names
for one-to-many (e.g., ``simple_items_parent_container``) and junction table
names for many-to-many (e.g., ``students_enrollments``). Reverts to
underscore suffixes (``simple_items_``, ``student_``).

@@ -230,2 +235,10 @@ * ``dataclasses``

When multiple foreign keys or junction tables connect to the same target table,
relationships use qualifiers for disambiguation. One-to-many relationships use FK
column names (e.g., ``simple_items_parent_container``, ``simple_items_top_container``).
Many-to-many relationships use junction table names (e.g., ``students_enrollments``,
``students_waitlist``), except for self-referential cases which use FK column names
(e.g., ``parent``, ``child``). The ``nofknames`` option reverts to underscore suffixes
(``simple_items_``, ``student_``).
Customizing code generation logic

@@ -232,0 +245,0 @@ =================================

@@ -7,2 +7,3 @@ from __future__ import annotations

from _pytest.fixtures import FixtureRequest
from sqlalchemy import Enum as SAEnum
from sqlalchemy import TypeDecorator

@@ -25,3 +26,3 @@ from sqlalchemy.dialects import mysql, postgresql, registry

from sqlalchemy.sql.sqltypes import DateTime, NullType
from sqlalchemy.types import INTEGER, NUMERIC, SMALLINT, VARCHAR, Text
from sqlalchemy.types import ARRAY, INTEGER, NUMERIC, SMALLINT, VARCHAR, Text

@@ -325,2 +326,79 @@ from sqlacodegen.generators import CodeGenerator, TablesGenerator

def test_array_enum_named(generator: CodeGenerator) -> None:
Table(
"users",
generator.metadata,
Column("id", INTEGER, primary_key=True),
Column("roles", ARRAY(SAEnum("admin", "user", "moderator", name="role_enum"))),
)
validate_code(
generator.generate(),
"""\
import enum
from sqlalchemy import ARRAY, Column, Enum, Integer, MetaData, Table
metadata = MetaData()
class RoleEnum(str, enum.Enum):
ADMIN = 'admin'
USER = 'user'
MODERATOR = 'moderator'
t_users = Table(
'users', metadata,
Column('id', Integer, primary_key=True),
Column('roles', ARRAY(Enum(RoleEnum, values_callable=lambda cls: [member.value for member in cls])))
)
""",
)
def test_array_enum_shared(generator: CodeGenerator) -> None:
Table(
"users",
generator.metadata,
Column("id", INTEGER, primary_key=True),
Column("roles", ARRAY(SAEnum("admin", "user", name="role_enum"))),
)
Table(
"groups",
generator.metadata,
Column("id", INTEGER, primary_key=True),
Column("allowed_roles", ARRAY(SAEnum("admin", "user", name="role_enum"))),
)
validate_code(
generator.generate(),
"""\
import enum
from sqlalchemy import ARRAY, Column, Enum, Integer, MetaData, Table
metadata = MetaData()
class RoleEnum(str, enum.Enum):
ADMIN = 'admin'
USER = 'user'
t_groups = Table(
'groups', metadata,
Column('id', Integer, primary_key=True),
Column('allowed_roles', ARRAY(Enum(RoleEnum, values_callable=lambda cls: [member.value for member in cls])))
)
t_users = Table(
'users', metadata,
Column('id', Integer, primary_key=True),
Column('roles', ARRAY(Enum(RoleEnum, values_callable=lambda cls: [member.value for member in cls])))
)
""",
)
@pytest.mark.parametrize("engine", ["postgresql"], indirect=["engine"])

@@ -327,0 +405,0 @@ def test_domain_text(generator: CodeGenerator) -> None:

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display