Skip to content

Commit b1defa7

Browse files
committed
Bug fixes
1 parent d4c2350 commit b1defa7

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

text_2_sql/data_dictionary/data_dictionary_creator.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@
2020

2121

2222
class ForeignKeyRelationship(BaseModel):
23-
source_column: str = Field(..., alias="Column")
23+
column: str = Field(..., alias="Column")
2424
foreign_column: str = Field(..., alias="ForeignColumn")
2525

26+
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
27+
2628

2729
class EntityRelationship(BaseModel):
30+
entity: str = Field(..., alias="Entity")
2831
foreign_entity: str = Field(..., alias="ForeignEntity")
2932
foreign_keys: list[ForeignKeyRelationship] = Field(..., alias="ForeignKeys")
3033

31-
def pivot(self, entity: str):
34+
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
35+
36+
def pivot(self):
3237
"""A method to pivot the entity relationship."""
3338
return EntityRelationship(
34-
foreign_entity=entity,
39+
entity=self.foreign_entity,
40+
foreign_entity=self.entity,
3541
foreign_keys=[
3642
ForeignKeyRelationship(
3743
source_column=foreign_key.foreign_column,
@@ -53,7 +59,7 @@ def from_sql_row(cls, row, columns):
5359
foreign_entity=result["ForeignEntity"],
5460
foreign_keys=[
5561
ForeignKeyRelationship(
56-
source_column=result["Column"],
62+
column=result["Column"],
5763
foreign_column=result["ForeignColumn"],
5864
)
5965
],
@@ -100,7 +106,7 @@ class EntityItem(BaseModel):
100106
None, alias="EntityRelationships"
101107
)
102108

103-
complete_entity_relationship_graph = Optional[str] = Field(
109+
complete_entity_relationship_graph: Optional[str] = Field(
104110
None, alias="CompleteEntityRelationshipGraph"
105111
)
106112

text_2_sql/data_dictionary/sql_sever_data_dictionary_creator.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ def __init__(
2525
excluded_entities.extend(
2626
["dbo.BuildVersion", "dbo.ErrorLog", "sys.database_firewall_rules"]
2727
)
28-
cls = super().__init__(entities, excluded_entities, single_file)
29-
cls.database = os.environ["Text2Sql__DatabaseName"]
30-
31-
return cls
28+
super().__init__(entities, excluded_entities, single_file)
29+
self.database = os.environ["Text2Sql__DatabaseName"]
3230

3331
"""A class to extract data dictionary information from a SQL Server database."""
3432

@@ -85,12 +83,12 @@ def extract_columns_sql_query(self, entity: EntityItem) -> str:
8583
AND c.TABLE_NAME = '{entity.name}';"""
8684

8785
@property
88-
def extract_entity_relationships_sql_query() -> str:
86+
def extract_entity_relationships_sql_query(self) -> str:
8987
"""A property to extract entity relationships from a SQL Server database."""
9088
return """SELECT
9189
fk_tab.name AS Entity,
9290
pk_tab.name AS ForeignEntity,
93-
fk_col.name AS Column,
91+
fk_col.name AS [Column],
9492
pk_col.name AS ForeignColumn
9593
FROM
9694
sys.foreign_keys AS fk

0 commit comments

Comments
 (0)