diff --git a/eralchemy/sqla.py b/eralchemy/sqla.py index afda6d338b714a2f8e6da7293adef6b873b21b27..6900f93a0f64791d6a4156ad8fbf03de7e6b3d2d 100644 --- a/eralchemy/sqla.py +++ b/eralchemy/sqla.py @@ -20,14 +20,14 @@ if TYPE_CHECKING: def check_all_compound_same_parent(fk: sa.ForeignKey): """Checks if all other ForeignKey Constraints of our table are on the same parent table as the current one.""" - table = fk.column.table.fullname + table = get_sa_table_name(fk.column.table) if not fk.constraint: return True for col in fk.constraint.table.columns: if not col.foreign_keys: return False for foreign_column in col.foreign_keys: - if table != foreign_column.column.table.fullname: + if table != get_sa_table_name(foreign_column.column.table): return False return True @@ -47,9 +47,9 @@ def relation_to_intermediary(fk: sa.ForeignKey) -> Relation: # if this is the case, we are not optional and must be unique right_cardinality = "1" if check_all_compound_same_parent(fk) else "*" return Relation( - right_table=format_name(fk.parent.table.fullname), + right_table=format_name(get_sa_table_name(fk.parent.table)), right_column=format_name(fk.parent.name), - left_table=format_name(fk.column.table.fullname), + left_table=format_name(get_sa_table_name(fk.column.table)), left_column=format_name(fk.column.name), right_cardinality=right_cardinality, left_cardinality="?" if fk.parent.nullable else "1", @@ -81,12 +81,15 @@ def column_to_intermediary( is_null=col.nullable, ) +def get_sa_table_name(t: sa.Table) -> str: + return (t.schema + '.' + t.name) if t.schema else t.name + def table_to_intermediary(table: sa.Table) -> Table: """Transform an SQLAlchemy Table object to its intermediary representation.""" table_columns = getattr(table.c, "_colset", getattr(table.c, "_data", {}).values()) return Table( - name=table.fullname, + name=get_sa_table_name(table), columns=[column_to_intermediary(col) for col in table_columns], ) diff --git a/pyproject.toml b/pyproject.toml index 0f3c4407d6844045885f05aa0e213ea4b1374ed1..690e192de2d57c1510d58b3efe4bc75d5d4e0900 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "eralchemy" -version = "1.5.0" +version = "1.5.1" description = "Simple entity relation (ER) diagrams generation" authors = [ { name = "Alexis Benoist", email = "Alexis-benoist@users.noreply.github.com"},