@@ -64,7 +64,7 @@ class Node(Timestamped, Base):
6464
6565 # This id is internal, never exposed to the client.
6666 id = Column (Integer , primary_key = True , index = True , autoincrement = True )
67- parent_id = Column (Integer , ForeignKey ("nodes.id" ), nullable = True )
67+ parent = Column (Integer , ForeignKey ("nodes.id" ), nullable = True )
6868
6969 key = Column (Unicode (1023 ), nullable = False )
7070 ancestors = Column (JSONVariant , nullable = True )
@@ -86,17 +86,16 @@ class Node(Timestamped, Base):
8686 passive_deletes = True ,
8787 )
8888
89- # This a self-referencing relationship between parent and children
90- parent = relationship ("Node" , remote_side = [id ], back_populates = "children " )
91- children = relationship ("Node" , back_populates = "parent " )
89+ # This is a self-referencing relationship between parent and children
90+ prnt_rel = relationship ("Node" , remote_side = [id ], back_populates = "chld_rel " )
91+ chld_rel = relationship ("Node" , back_populates = "prnt_rel " )
9292
9393 __table_args__ = (
94- UniqueConstraint ("key" , "parent_id " , name = "key_parent_id_unique_constraint " ),
94+ UniqueConstraint ("key" , "parent " , name = "key_parent_unique_constraint " ),
9595 # This index supports comparison operations (==, <, ...).
9696 # For key-existence operations we will need a GIN index additionally.
9797 Index (
9898 "top_level_metadata" ,
99- "parent_id" ,
10099 # include the keys of the default sorting ('time_created', 'id'),
101100 # used to avoid creating a temp sort index
102101 "time_created" ,
@@ -115,11 +114,11 @@ class NodesClosure(Base):
115114
116115 __tablename__ = "nodes_closure"
117116
118- parent = Column (Integer , ForeignKey ("nodes.id" ), primary_key = True )
119- child = Column (Integer , ForeignKey ("nodes.id" ), primary_key = True )
117+ ancestor = Column (Integer , ForeignKey ("nodes.id" ), primary_key = True )
118+ descendant = Column (Integer , ForeignKey ("nodes.id" ), primary_key = True )
120119 depth = Column (Integer , nullable = False )
121120
122- __table_args__ = (UniqueConstraint ("parent " , "child " , name = "parent_child_unique_constraint " ),
121+ __table_args__ = (UniqueConstraint ("ancestor " , "descendant " , name = "ancestor_descendant_unique_constraint " ),
123122 )
124123
125124class DataSourceAssetAssociation (Base ):
@@ -294,12 +293,12 @@ def update_closure_table(target, connection, **kw):
294293CREATE TRIGGER update_closure_table_when_inserting
295294AFTER INSERT ON nodes
296295BEGIN
297- INSERT INTO nodes_closure(parent, child , depth)
296+ INSERT INTO nodes_closure(ancestor, descendant , depth)
298297 SELECT NEW.id, NEW.id, 0;
299- INSERT INTO nodes_closure(parent, child , depth)
300- SELECT p.parent , c.child , p.depth+c.depth+1
298+ INSERT INTO nodes_closure(ancestor, descendant , depth)
299+ SELECT p.ancestor , c.descendant , p.depth+c.depth+1
301300 FROM nodes_closure p, nodes_closure c
302- WHERE p.child =NEW.parent_id and c.parent =NEW.id;
301+ WHERE p.descendant =NEW.parent and c.ancestor =NEW.id;
303302END"""
304303 )
305304 )
@@ -310,10 +309,10 @@ def update_closure_table(target, connection, **kw):
310309BEFORE DELETE ON nodes
311310BEGIN
312311 DELETE FROM nodes_closure
313- WHERE (parent, child ) IN (
314- SELECT p.parent , c.child
312+ WHERE (ancestor, descendant ) IN (
313+ SELECT p.ancestor , c.descendant
315314 FROM nodes_closure p, nodes_closure c
316- WHERE (p.child =OLD.parent_id OR p.child =OLD.id) AND c.parent =OLD.id);
315+ WHERE (p.descendant =OLD.parent OR p.descendant =OLD.id) AND c.ancestor =OLD.id);
317316END"""
318317 )
319318 )
0 commit comments