From: Michael Tremer Date: Wed, 7 Jun 2023 10:46:55 +0000 (+0000) Subject: builds: Move test builds view into code X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a556aee178611513492acda41eb3b5e2e7906f54;p=pbs.git builds: Move test builds view into code Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index e91b2ffb..f6f2e09b 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -28,6 +28,27 @@ class Builds(base.Object): for row in res: yield Build(self.backend, row.id, data=row) + def init(self): + self.db.execute(""" + CREATE TEMPORARY VIEW build_test_builds AS ( + SELECT + builds.id AS build_id, + test_builds.id AS test_build_id + FROM + builds + JOIN + build_groups ON builds.test_group_id = build_groups.id + JOIN + builds test_builds ON test_builds.build_group_id = build_groups.id + WHERE + builds.deleted_at IS NULL + AND + builds.test IS FALSE + AND + build_groups.deleted_at IS NULL + ) + """) + def __len__(self): res = self.db.get(""" SELECT diff --git a/src/database.sql b/src/database.sql index 92976bff..90b63eaa 100644 --- a/src/database.sql +++ b/src/database.sql @@ -27,6 +27,52 @@ SET default_tablespace = ''; SET default_table_access_method = heap; +-- +-- Name: build_groups; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.build_groups ( + id integer NOT NULL, + uuid uuid DEFAULT gen_random_uuid() NOT NULL, + created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + created_by integer, + deleted_at timestamp without time zone, + deleted_by integer, + finished_at timestamp without time zone, + failed boolean DEFAULT false NOT NULL, + tested_build_id integer +); + + +-- +-- Name: builds; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.builds ( + id integer NOT NULL, + uuid uuid DEFAULT gen_random_uuid() NOT NULL, + pkg_id integer NOT NULL, + severity text, + message text, + created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + build_repo_id integer NOT NULL, + owner_id integer, + priority integer DEFAULT 0 NOT NULL, + finished_at timestamp without time zone, + failed boolean DEFAULT false NOT NULL, + deleted_at timestamp without time zone, + deleted_by integer, + build_group_id integer, + deprecating_build_id integer, + deprecated_at timestamp without time zone, + deprecated_by integer, + test_group_id integer, + test boolean DEFAULT false NOT NULL, + disable_test_builds boolean DEFAULT false NOT NULL, + points integer DEFAULT 0 NOT NULL +); + + -- -- Name: build_bugs; Type: TABLE; Schema: public; Owner: - -- @@ -56,23 +102,6 @@ CREATE TABLE public.build_comments ( ); --- --- Name: build_groups; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.build_groups ( - id integer NOT NULL, - uuid uuid DEFAULT gen_random_uuid() NOT NULL, - created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, - created_by integer, - deleted_at timestamp without time zone, - deleted_by integer, - finished_at timestamp without time zone, - failed boolean DEFAULT false NOT NULL, - tested_build_id integer -); - - -- -- Name: build_points; Type: TABLE; Schema: public; Owner: - -- @@ -126,35 +155,6 @@ CREATE TABLE public.builders ( ); --- --- Name: builds; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.builds ( - id integer NOT NULL, - uuid uuid DEFAULT gen_random_uuid() NOT NULL, - pkg_id integer NOT NULL, - severity text, - message text, - created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, - build_repo_id integer NOT NULL, - owner_id integer, - priority integer DEFAULT 0 NOT NULL, - finished_at timestamp without time zone, - failed boolean DEFAULT false NOT NULL, - deleted_at timestamp without time zone, - deleted_by integer, - build_group_id integer, - deprecating_build_id integer, - deprecated_at timestamp without time zone, - deprecated_by integer, - test_group_id integer, - test boolean DEFAULT false NOT NULL, - disable_test_builds boolean DEFAULT false NOT NULL, - points integer DEFAULT 0 NOT NULL -); - - -- -- Name: jobs; Type: TABLE; Schema: public; Owner: - -- @@ -376,19 +376,6 @@ CREATE TABLE public.build_packages ( ); --- --- Name: build_test_builds; Type: VIEW; Schema: public; Owner: - --- - -CREATE VIEW public.build_test_builds AS - SELECT builds.id AS build_id, - test_builds.id AS test_build_id - FROM ((public.builds - JOIN public.build_groups ON ((builds.test_group_id = build_groups.id))) - JOIN public.builds test_builds ON ((test_builds.build_group_id = build_groups.id))) - WHERE ((builds.deleted_at IS NULL) AND (build_groups.deleted_at IS NULL)); - - -- -- Name: builder_stats; Type: TABLE; Schema: public; Owner: - --