3434
3535from macaron .artifact .maven import MavenSubjectPURLMatcher
3636from macaron .database .database_manager import ORMBase
37- from macaron .database .db_custom_types import RFC3339DateTime
37+ from macaron .database .db_custom_types import DBJsonDict , RFC3339DateTime
3838from macaron .errors import InvalidPURLError
3939from macaron .slsa_analyzer .provenance .intoto import InTotoPayload , ProvenanceSubjectPURLMatcher
4040from macaron .slsa_analyzer .slsa_req import ReqName
@@ -161,7 +161,7 @@ class Component(PackageURLMixin, ORMBase):
161161 checkfacts : Mapped [list ["CheckFacts" ]] = relationship (back_populates = "component" , lazy = "immediate" )
162162
163163 #: The one-to-many relationship with provenances.
164- provenance : Mapped [list ["Provenance " ]] = relationship (back_populates = "component" , lazy = "immediate" )
164+ provenance : Mapped [list ["ProvenanceFacts " ]] = relationship (back_populates = "component" , lazy = "immediate" )
165165
166166 #: The bidirectional many-to-many relationship for component dependencies.
167167 dependencies : Mapped [list ["Component" ]] = relationship (
@@ -464,7 +464,7 @@ class CheckFacts(ORMBase):
464464 }
465465
466466
467- class Provenance (ORMBase ):
467+ class ProvenanceFacts (ORMBase ):
468468 """ORM class for a provenance document."""
469469
470470 __tablename__ = "_provenance"
@@ -479,7 +479,7 @@ class Provenance(ORMBase):
479479 component : Mapped ["Component" ] = relationship (back_populates = "provenance" )
480480
481481 #: The SLSA version.
482- version : Mapped [str ] = mapped_column (String , nullable = False )
482+ version : Mapped [str ] = mapped_column (String , nullable = True )
483483
484484 #: The release tag commit sha.
485485 release_commit_sha : Mapped [str ] = mapped_column (String , nullable = True )
@@ -488,12 +488,189 @@ class Provenance(ORMBase):
488488 release_tag : Mapped [str ] = mapped_column (String , nullable = True )
489489
490490 #: The provenance payload content in JSON format.
491- provenance_json : Mapped [str ] = mapped_column (String , nullable = False )
491+ provenance_json : Mapped [dict ] = mapped_column (DBJsonDict , nullable = False )
492+
493+ #: The provenance statement.
494+ statement : Mapped ["Statement" ] = relationship (back_populates = "provenance" )
492495
493496 #: A one-to-many relationship with the release artifacts.
494497 artifact : Mapped [list ["ReleaseArtifact" ]] = relationship (back_populates = "provenance" )
495498
496499
500+ class Statement (ORMBase ):
501+ """The ORM class for provenance statement."""
502+
503+ __tablename__ = "_statement"
504+
505+ #: The primary key.
506+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
507+
508+ #: The foreign key to the software component.
509+ provenance_id : Mapped [int ] = mapped_column (Integer , ForeignKey (ProvenanceFacts .id ), nullable = False )
510+
511+ #: A one-to-one relationship with software components.
512+ provenance : Mapped ["ProvenanceFacts" ] = relationship (back_populates = "statement" )
513+
514+ #: Statement type.
515+ _type : Mapped [str ] = mapped_column (String , nullable = False )
516+
517+ #: Predicate Type.
518+ predicate_type : Mapped [str ] = mapped_column (String , nullable = False )
519+
520+ #: Provenance Subjects.
521+ subject : Mapped [list ["ProvenanceSubjectRaw" ]] = relationship (back_populates = "statement" )
522+
523+ #: Provenance predicate.
524+ predicate : Mapped ["Predicate" ] = relationship (back_populates = "statement" )
525+
526+
527+ class ProvenanceSubjectRaw (ORMBase ):
528+ """The ORM class for the provenance subject containing all the information."""
529+
530+ __tablename__ = "_subject"
531+
532+ #: The primary key.
533+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
534+
535+ #: The foreign key to the software component.
536+ statement_id : Mapped [int ] = mapped_column (Integer , ForeignKey (Statement .id ), nullable = False )
537+
538+ #: A one-to-one relationship with provenance statement.
539+ statement : Mapped ["Statement" ] = relationship (back_populates = "subject" )
540+
541+ #: Subject name.
542+ name : Mapped [str ] = mapped_column (String , nullable = False )
543+
544+ #: Subject digests.
545+ digest : Mapped ["SubjectDigest" ] = relationship (back_populates = "subject" )
546+
547+
548+ class SubjectDigest (ORMBase ):
549+ """The ORM class for the provenance subject digest."""
550+
551+ __tablename__ = "_subject_digest"
552+
553+ #: The primary key.
554+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
555+
556+ #: The foreign key to the provenance subject.
557+ subject_id : Mapped [int ] = mapped_column (Integer , ForeignKey (ProvenanceSubjectRaw .id ), nullable = False )
558+
559+ #: A one-to-one relationship with provenance subject.
560+ subject : Mapped ["ProvenanceSubjectRaw" ] = relationship (back_populates = "digest" )
561+
562+ #: Digest.
563+ sha512 : Mapped [str ] = mapped_column (String , nullable = False )
564+
565+
566+ class Predicate (ORMBase ):
567+ """The ORM class for provenance predicate."""
568+
569+ __tablename__ = "_predicate"
570+
571+ #: The primary key.
572+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
573+
574+ #: The foreign key to the software component.
575+ statement_id : Mapped [int ] = mapped_column (Integer , ForeignKey (Statement .id ), nullable = False )
576+
577+ #: A one-to-one relationship with provenance statement.
578+ statement : Mapped ["Statement" ] = relationship (back_populates = "predicate" )
579+
580+ #: Build definition.
581+ build_definition : Mapped ["BuildDefinition" ] = relationship (back_populates = "predicate" )
582+
583+
584+ class BuildDefinition (ORMBase ):
585+ """The ORM class for provenance predicate build definition."""
586+
587+ __tablename__ = "_build_definition"
588+
589+ #: The primary key.
590+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
591+
592+ #: The foreign key to the software component.
593+ predicate_id : Mapped [int ] = mapped_column (Integer , ForeignKey (Predicate .id ), nullable = False )
594+
595+ #: A one-to-one relationship with provenance predicate.
596+ predicate : Mapped ["Predicate" ] = relationship (back_populates = "build_definition" )
597+
598+ #: Build type.
599+ build_type : Mapped [str ] = mapped_column (String , nullable = False )
600+
601+ #: External parameters in build definitions.
602+ external_parameters : Mapped ["ExternalParameters" ] = relationship (back_populates = "build_definition" )
603+
604+ #: Internal parameters in build definitions.
605+ internal_parameters : Mapped ["InternalParameters" ] = relationship (back_populates = "build_definition" )
606+
607+
608+ class ExternalParameters (ORMBase ):
609+ """The ORM class for provenance predicate build definition external parameters."""
610+
611+ __tablename__ = "_external_parameters"
612+
613+ #: The primary key.
614+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
615+
616+ #: The foreign key to the software component.
617+ build_definition_id : Mapped [int ] = mapped_column (Integer , ForeignKey (BuildDefinition .id ), nullable = False )
618+
619+ #: A one-to-one relationship with build definition.
620+ build_definition : Mapped ["BuildDefinition" ] = relationship (back_populates = "external_parameters" )
621+
622+ #: External parameters in build definitions.
623+ workflow : Mapped ["Workflow" ] = relationship (back_populates = "external_parameters" )
624+
625+
626+ class Workflow (ORMBase ):
627+ """The ORM class for provenance predicate build definition external parameters workflows."""
628+
629+ __tablename__ = "_workflow"
630+
631+ #: The primary key.
632+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
633+
634+ #: The foreign key to the software component.
635+ external_parameters_id : Mapped [int ] = mapped_column (Integer , ForeignKey (ExternalParameters .id ), nullable = False )
636+
637+ #: A one-to-one relationship with external_parameters.
638+ external_parameters : Mapped ["ExternalParameters" ] = relationship (back_populates = "workflow" )
639+
640+ #: Workflow reference.
641+ ref : Mapped [str ] = mapped_column (String , nullable = False )
642+
643+ #: Workflow repository.
644+ repository : Mapped [str ] = mapped_column (String , nullable = False )
645+
646+ #: Workflow path.
647+ path : Mapped [str ] = mapped_column (String , nullable = False )
648+
649+
650+ class InternalParameters (ORMBase ):
651+ """The ORM class for provenance predicate build definition internal parameters."""
652+
653+ __tablename__ = "_internal_parameters"
654+
655+ #: The primary key.
656+ id : Mapped [int ] = mapped_column (Integer , primary_key = True , autoincrement = True ) # noqa: A003
657+
658+ #: The foreign key to the software component.
659+ build_definition_id : Mapped [int ] = mapped_column (Integer , ForeignKey (BuildDefinition .id ), nullable = False )
660+
661+ #: A one-to-one relationship with build definition.
662+ build_definition : Mapped ["BuildDefinition" ] = relationship (back_populates = "internal_parameters" )
663+
664+ #: The GitHub event that triggered the publish.
665+ github_event_name : Mapped [str ] = mapped_column (String , nullable = False )
666+
667+ #: The GitHub repository ID that triggered the publish.
668+ github_repository_id : Mapped [str ] = mapped_column (String , nullable = False )
669+
670+ #: The GitHub repository owner ID that triggered the publish.
671+ github_repository_owner_id : Mapped [str ] = mapped_column (String , nullable = False )
672+
673+
497674class ReleaseArtifact (ORMBase ):
498675 """The ORM class for release artifacts."""
499676
@@ -509,10 +686,10 @@ class ReleaseArtifact(ORMBase):
509686 slsa_verified : Mapped [bool ] = mapped_column (Boolean , nullable = True )
510687
511688 #: The foreign key to the SLSA provenance.
512- provenance_id : Mapped [int ] = mapped_column (Integer , ForeignKey (Provenance .id ), nullable = True )
689+ provenance_id : Mapped [int ] = mapped_column (Integer , ForeignKey (ProvenanceFacts .id ), nullable = True )
513690
514691 #: A many-to-one relationship with the SLSA provenance.
515- provenance : Mapped ["Provenance " ] = relationship (back_populates = "artifact" )
692+ provenance : Mapped ["ProvenanceFacts " ] = relationship (back_populates = "artifact" )
516693
517694 #: The one-to-many relationship with the hash digests for this artifact.
518695 digests : Mapped [list ["HashDigest" ]] = relationship (back_populates = "artifact" )
0 commit comments