3030JSONVariant = JSON ().with_variant (JSONB (), "postgresql" )
3131
3232
33- class TimedStampedBase :
34- """
35- Base TimeStamp class that gives independent bheavior to Node and Revision classes.
36-
37- Mixin for providing timestamps of creation and update time.
38-
39- These are not used by application code, but they may be useful for
40- forensics.
41- """
42- time_updated = Column (
43- DateTime (timezone = False ), onupdate = func .now (), server_default = func .now ()
44- )
45-
46- def __repr__ (self ):
47- return (
48- f"{ type (self ).__name__ } ("
49- + ", " .join (
50- f"{ key } ={ value !r} "
51- for key , value in self .__dict__ .items ()
52- if not key .startswith ("_" )
53- )
54- + ")"
55- )
56-
57-
58- class Timestamped (TimedStampedBase ):
59- """
60- Mixin for providing timestamps of creation and update time.
61-
62- These are not used by application code, but they may be useful for
63- forensics.
64- """
65-
66- time_created = Column (DateTime (timezone = False ), server_default = func .now ())
67-
68-
69- class Node (Timestamped , Base ):
33+ class Node (Base ):
7034 """
7135 This describes a single Node and sometimes inlines descriptions of all its children.
7236 """
@@ -88,8 +52,10 @@ class Node(Timestamped, Base):
8852 metadata_ = Column ("metadata" , JSONVariant , nullable = False )
8953 specs = Column (JSONVariant , nullable = False )
9054 access_blob = Column ("access_blob" , JSONVariant , nullable = False )
55+ time_created = Column (DateTime (timezone = False ), server_default = func .now ())
56+ time_updated = Column (DateTime (timezone = False ), onupdate = func .now (), server_default = func .now ())
9157 created_by = Column ("created_by" , String , nullable = False )
92- updated_by = Column ("updated_by" , String , nullable = False )
58+ updated_by = Column ("updated_by" , String )
9359
9460 data_sources = relationship (
9561 "DataSource" ,
@@ -375,8 +341,8 @@ def update_closure_table(target, connection, **kw):
375341 connection .execute (
376342 text (
377343 """
378- INSERT INTO nodes(id, key, parent, structure_family, metadata, specs, access_blob)
379- SELECT 0, '', NULL, 'container', '{}', '[]', '{}';
344+ INSERT INTO nodes(id, key, parent, structure_family, metadata, specs, access_blob, created_by )
345+ SELECT 0, '', NULL, 'container', '{}', '[]', '{}', '' ;
380346"""
381347 )
382348 )
@@ -447,7 +413,7 @@ def create_virtual_table_fits5(target, connection, **kw):
447413 connection .execute (text (statement ))
448414
449415
450- class DataSource (Timestamped , Base ):
416+ class DataSource (Base ):
451417 """
452418 The describes how to open one or more file/blobs to extract data for a Node.
453419
@@ -477,6 +443,8 @@ class DataSource(Timestamped, Base):
477443 # This relates to the mutability of the data.
478444 management = Column (Enum (Management ), nullable = False )
479445 structure_family = Column (Enum (StructureFamily ), nullable = False )
446+ time_created = Column (DateTime (timezone = False ), server_default = func .now ())
447+ time_updated = Column (DateTime (timezone = False ), onupdate = func .now (), server_default = func .now ())
480448
481449 # many-to-one relationship to Structure
482450 structure : Mapped ["Structure" ] = relationship (
@@ -518,7 +486,7 @@ class Structure(Base):
518486 structure = Column (JSONVariant , nullable = False )
519487
520488
521- class Asset (Timestamped , Base ):
489+ class Asset (Base ):
522490 """
523491 This tracks individual files/blobs.
524492 """
@@ -533,6 +501,8 @@ class Asset(Timestamped, Base):
533501 hash_type = Column (Unicode (63 ), nullable = True )
534502 hash_content = Column (Unicode (1023 ), nullable = True )
535503 size = Column (Integer , nullable = True )
504+ time_created = Column (DateTime (timezone = False ), server_default = func .now ())
505+ time_updated = Column (DateTime (timezone = False ), onupdate = func .now (), server_default = func .now ())
536506
537507 # # many-to-many relationship to Asset, bypassing the `Association` class
538508 data_sources : Mapped [List ["DataSource" ]] = relationship (
@@ -546,7 +516,7 @@ class Asset(Timestamped, Base):
546516 )
547517
548518
549- class Revision (TimedStampedBase , Base ):
519+ class Revision (Base ):
550520 """
551521 This tracks history of metadata, specs, and access_blob supporting 'undo' functionality.
552522 """
@@ -565,7 +535,8 @@ class Revision(TimedStampedBase, Base):
565535 metadata_ = Column ("metadata" , JSONVariant , nullable = False )
566536 specs = Column (JSONVariant , nullable = False )
567537 access_blob = Column ("access_blob" , JSONVariant , nullable = False )
568- updated_by = Column ("updated_by" , String , nullable = False )
538+ time_updated = Column (DateTime (timezone = False ), onupdate = func .now (), server_default = func .now ())
539+ updated_by = Column ("updated_by" , String , )
569540
570541 __table_args__ = (
571542 UniqueConstraint (
0 commit comments