From: Michael Tremer Date: Wed, 22 Jan 2025 14:40:42 +0000 (+0000) Subject: builds: Add a relationship to commits X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=22c77691b2338847014754a0a3c1741e2227171c;p=pbs.git builds: Add a relationship to commits Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 57688a80..d7593802 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -471,12 +471,15 @@ class Build(database.Base, database.BackendMixin, database.SoftDeleteMixin): severity = Column(Text) + # Commit ID + + commit_id = Column(Integer, ForeignKey("source_commits.id")) + # Commit - @lazy_property - def commit(self): - if self.pkg and self.pkg.commit: - return self.pkg.commit + commit = sqlalchemy.orm.relationship( + "SourceCommit", foreign_keys=[commit_id], lazy="selectin", + ) def has_perm(self, user): """ diff --git a/src/database.sql b/src/database.sql index d451a757..de203f33 100644 --- a/src/database.sql +++ b/src/database.sql @@ -255,7 +255,8 @@ CREATE TABLE public.builds ( test_group_id integer, test boolean DEFAULT false NOT NULL, disable_test_builds boolean DEFAULT false NOT NULL, - points integer DEFAULT 0 NOT NULL + points integer DEFAULT 0 NOT NULL, + commit_id integer ); @@ -2077,6 +2078,14 @@ ALTER TABLE ONLY public.build_comments ADD CONSTRAINT builds_comments_user_id FOREIGN KEY (user_id) REFERENCES public.users(id); +-- +-- Name: builds builds_commit_id; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.builds + ADD CONSTRAINT builds_commit_id FOREIGN KEY (commit_id) REFERENCES public.source_commits(id) NOT VALID; + + -- -- Name: builds builds_deleted_by; Type: FK CONSTRAINT; Schema: public; Owner: - --