Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow primary key to be specified for relationship #333

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pgsync/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"through_tables",
"type",
"variant",
"primary_key",
]

# Relationship foreign keys
Expand Down
7 changes: 3 additions & 4 deletions pgsync/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __post_init__(self):
self.through_tables: List[str] = self.relationship.get(
"through_tables", []
)
self.primary_key: List[str] = self.relationship.get("primary_key", [])
self.through_nodes: List[Node] = []

if not set(self.relationship.keys()).issubset(
Expand Down Expand Up @@ -97,7 +98,7 @@ def __post_init__(self):

def __str__(self):
return (
f"relationship: {self.variant}.{self.type}:{self.through_tables}"
f"relationship: {self.variant}.{self.type}:{self.through_tables}.{self.primary_key}"
)


Expand Down Expand Up @@ -149,7 +150,7 @@ def __post_init__(self):
table=through_table,
schema=self.schema,
parent=self,
primary_key=[],
primary_key=self.relationship.primary_key,
)
)

Expand Down Expand Up @@ -288,8 +289,6 @@ def build(self, data: dict) -> Node:
)

self.tables.add(node.table)
for through_node in node.relationship.through_nodes:
self.tables.add(through_node.table)

for child in data.get("children", []):
node.add_child(self.build(child))
Expand Down