]> git.ipfire.org Git - pbs.git/commitdiff
builds: Adjust database layout to the rest
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Jul 2022 14:57:17 +0000 (14:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Jul 2022 14:57:17 +0000 (14:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/database.sql

index 443698e9f8e54230c7b2242756d6bc49139e9330..103c46be21bbdc82ecaab2809b99e00d8fe9b5fd 100644 (file)
@@ -64,7 +64,7 @@ class Builds(base.Object):
                if type == "release":
                        query += " ORDER BY packages.name,packages.epoch,packages.version,packages.release,id ASC"
                elif type == "scratch":
-                       query += " ORDER BY time_created DESC"
+                       query += " ORDER BY created_at DESC"
 
                query += " LIMIT %s OFFSET %s"
                args.extend([offset, limit])
@@ -85,7 +85,7 @@ class Builds(base.Object):
                        WHERE
                                packages.name = %s
                        ORDER BY
-                               builds.time_created DESC
+                               builds.created_at DESC
                        LIMIT 1""",
                        name,
                )
@@ -100,7 +100,7 @@ class Builds(base.Object):
                        FROM
                                builds
                        ORDER BY
-                               time_created DESC
+                               created_at DESC
                        LIMIT %s""",
                        limit,
                )
@@ -219,7 +219,7 @@ class Builds(base.Object):
                        query += " WHERE %s" % " AND ".join(wheres)
 
                # Sort everything.
-               query += " ORDER BY time_created DESC"
+               query += " ORDER BY created_at DESC"
 
                # Limits.
                query += " LIMIT %s OFFSET %s"
@@ -313,15 +313,12 @@ class Build(base.DataObject):
                return "%s-%s" % (self.pkg.name, self.pkg.evr)
 
        @property
-       def type(self):
-               """
-                       The type of this build.
-               """
-               return self.data.type
+       def created_at(self):
+               return self.data.created_at
 
        @property
-       def time_created(self):
-               return self.data.time_created
+       def finished_at(self):
+               return self.data.finished_at
 
        def get_owner(self):
                """
@@ -339,10 +336,6 @@ class Build(base.DataObject):
        def distro(self):
                return self.backend.distros.get_by_id(self.data.distro_id)
 
-       @property
-       def created(self):
-               return self.data.time_created
-
        def auto_update_state(self):
                """
                        Check if the state of this build can be updated and perform
index f45fad991bcc87db677e0f594604e6db06d62324..c885fbe46c2ba0bec274287d085377abb201fcc5 100644 (file)
@@ -36,6 +36,20 @@ SET default_tablespace = '';
 
 SET default_table_access_method = heap;
 
+--
+-- Name: build_packages; Type: TABLE; Schema: public; Owner: pakfire
+--
+
+CREATE TABLE public.build_packages (
+    build_id integer NOT NULL,
+    package_id integer NOT NULL,
+    job_id integer NOT NULL,
+    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+
+ALTER TABLE public.build_packages OWNER TO pakfire;
+
 --
 -- Name: builder_stats; Type: TABLE; Schema: public; Owner: pakfire
 --
@@ -169,16 +183,17 @@ CREATE TABLE public.builds (
     id integer NOT NULL,
     uuid uuid DEFAULT gen_random_uuid() NOT NULL,
     pkg_id integer NOT NULL,
-    type text DEFAULT 'release'::text NOT NULL,
     state text DEFAULT 'building'::text NOT NULL,
     severity text,
     message text,
-    time_created timestamp without time zone DEFAULT now() NOT NULL,
+    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
     distro_id integer NOT NULL,
     owner_id integer,
     priority integer DEFAULT 0 NOT NULL,
     deleted boolean DEFAULT false NOT NULL,
-    bug_ids integer[] DEFAULT ARRAY[]::integer[] NOT NULL
+    bug_ids integer[] DEFAULT ARRAY[]::integer[] NOT NULL,
+    finished_at timestamp without time zone,
+    failed boolean DEFAULT false NOT NULL
 );
 
 
@@ -1044,6 +1059,22 @@ CREATE VIEW public.relation_sizes AS
 
 ALTER TABLE public.relation_sizes OWNER TO pakfire;
 
+--
+-- Name: repo_builds; Type: TABLE; Schema: public; Owner: pakfire
+--
+
+CREATE TABLE public.repo_builds (
+    repo_id integer NOT NULL,
+    build_id integer NOT NULL,
+    added_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+    added_by integer,
+    removed_at timestamp without time zone,
+    removed_by integer
+);
+
+
+ALTER TABLE public.repo_builds OWNER TO pakfire;
+
 --
 -- Name: repositories; Type: TABLE; Schema: public; Owner: pakfire
 --
@@ -1666,6 +1697,14 @@ ALTER TABLE ONLY public.users_emails ALTER COLUMN id SET DEFAULT nextval('public
 ALTER TABLE ONLY public.users_permissions ALTER COLUMN id SET DEFAULT nextval('public.users_permissions_id_seq'::regclass);
 
 
+--
+-- Name: builds builds_pkey; Type: CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.builds
+    ADD CONSTRAINT builds_pkey PRIMARY KEY (id);
+
+
 --
 -- Name: distributions distributions_pkey; Type: CONSTRAINT; Schema: public; Owner: pakfire
 --
@@ -1690,14 +1729,6 @@ ALTER TABLE ONLY public.builders_history
     ADD CONSTRAINT idx_2197982_primary PRIMARY KEY (id);
 
 
---
--- Name: builds idx_2197988_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire
---
-
-ALTER TABLE ONLY public.builds
-    ADD CONSTRAINT idx_2197988_primary PRIMARY KEY (id);
-
-
 --
 -- Name: builds_bugs_updates idx_2198008_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire
 --
@@ -1939,75 +1970,75 @@ ALTER TABLE ONLY public.users
 
 
 --
--- Name: builders_name; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: build_packages_build_id; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE UNIQUE INDEX builders_name ON public.builders USING btree (name) WHERE (deleted IS FALSE);
+CREATE INDEX build_packages_build_id ON public.build_packages USING btree (build_id);
 
 
 --
--- Name: builds_watchers_build_id; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: builders_name; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE INDEX builds_watchers_build_id ON public.builds_watchers USING btree (build_id);
+CREATE UNIQUE INDEX builders_name ON public.builders USING btree (name) WHERE (deleted IS FALSE);
 
 
 --
--- Name: distributions_slug; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: builds_created_at; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE UNIQUE INDEX distributions_slug ON public.distributions USING btree (slug) WHERE (deleted IS FALSE);
+CREATE INDEX builds_created_at ON public.builds USING btree (created_at DESC);
 
 
 --
--- Name: filelists_name; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: builds_pkg_id; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE INDEX filelists_name ON public.filelists USING btree (name);
+CREATE INDEX builds_pkg_id ON public.builds USING btree (pkg_id);
 
 
 --
--- Name: filelists_pkg_id; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: builds_uuid; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE INDEX filelists_pkg_id ON public.filelists USING btree (pkg_id);
-
-ALTER TABLE public.filelists CLUSTER ON filelists_pkg_id;
+CREATE UNIQUE INDEX builds_uuid ON public.builds USING btree (uuid) WHERE (deleted IS FALSE);
 
 
 --
--- Name: idx_2197982_builder_id; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: builds_watchers_build_id; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE INDEX idx_2197982_builder_id ON public.builders_history USING btree (builder_id);
+CREATE INDEX builds_watchers_build_id ON public.builds_watchers USING btree (build_id);
 
 
 --
--- Name: idx_2197988_pkg_id; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: distributions_slug; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE INDEX idx_2197988_pkg_id ON public.builds USING btree (pkg_id);
+CREATE UNIQUE INDEX distributions_slug ON public.distributions USING btree (slug) WHERE (deleted IS FALSE);
 
 
 --
--- Name: idx_2197988_state; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: filelists_name; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE INDEX idx_2197988_state ON public.builds USING btree (state);
+CREATE INDEX filelists_name ON public.filelists USING btree (name);
 
 
 --
--- Name: idx_2197988_type; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: filelists_pkg_id; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE INDEX idx_2197988_type ON public.builds USING btree (type);
+CREATE INDEX filelists_pkg_id ON public.filelists USING btree (pkg_id);
+
+ALTER TABLE public.filelists CLUSTER ON filelists_pkg_id;
 
 
 --
--- Name: idx_2197988_uuid; Type: INDEX; Schema: public; Owner: pakfire
+-- Name: idx_2197982_builder_id; Type: INDEX; Schema: public; Owner: pakfire
 --
 
-CREATE UNIQUE INDEX idx_2197988_uuid ON public.builds USING btree (uuid);
+CREATE INDEX idx_2197982_builder_id ON public.builders_history USING btree (builder_id);
 
 
 --
@@ -2210,6 +2241,27 @@ CREATE INDEX packages_src_created_at ON public.packages USING btree (created_at
 CREATE UNIQUE INDEX packages_uuid ON public.packages USING btree (uuid) WHERE (deleted IS FALSE);
 
 
+--
+-- Name: repo_builds_build_id; Type: INDEX; Schema: public; Owner: pakfire
+--
+
+CREATE INDEX repo_builds_build_id ON public.repo_builds USING btree (build_id);
+
+
+--
+-- Name: repo_builds_repo_id; Type: INDEX; Schema: public; Owner: pakfire
+--
+
+CREATE INDEX repo_builds_repo_id ON public.repo_builds USING btree (repo_id);
+
+
+--
+-- Name: repo_builds_unique; Type: INDEX; Schema: public; Owner: pakfire
+--
+
+CREATE UNIQUE INDEX repo_builds_unique ON public.repo_builds USING btree (repo_id, build_id) WHERE ((added_at IS NOT NULL) AND (removed_at IS NULL));
+
+
 --
 -- Name: repositories_builds_repo_id; Type: INDEX; Schema: public; Owner: pakfire
 --
@@ -2238,6 +2290,30 @@ CREATE UNIQUE INDEX uploads_uuid ON public.uploads USING btree (uuid);
 CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION public.on_update_current_timestamp_sources();
 
 
+--
+-- Name: build_packages build_packages_build_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.build_packages
+    ADD CONSTRAINT build_packages_build_id FOREIGN KEY (build_id) REFERENCES public.builds(id);
+
+
+--
+-- Name: build_packages build_packages_job_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.build_packages
+    ADD CONSTRAINT build_packages_job_id FOREIGN KEY (job_id) REFERENCES public.jobs(id);
+
+
+--
+-- Name: build_packages build_packages_package_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.build_packages
+    ADD CONSTRAINT build_packages_package_id FOREIGN KEY (package_id) REFERENCES public.packages(id);
+
+
 --
 -- Name: builder_stats builder_stats_builder_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
 --
@@ -2486,6 +2562,38 @@ ALTER TABLE ONLY public.packages
     ADD CONSTRAINT packages_commit_id FOREIGN KEY (commit_id) REFERENCES public.sources_commits(id);
 
 
+--
+-- Name: repo_builds repo_builds_added_by; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.repo_builds
+    ADD CONSTRAINT repo_builds_added_by FOREIGN KEY (added_by) REFERENCES public.users(id);
+
+
+--
+-- Name: repo_builds repo_builds_build_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.repo_builds
+    ADD CONSTRAINT repo_builds_build_id FOREIGN KEY (build_id) REFERENCES public.builds(id);
+
+
+--
+-- Name: repo_builds repo_builds_removed_by; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.repo_builds
+    ADD CONSTRAINT repo_builds_removed_by FOREIGN KEY (removed_by) REFERENCES public.users(id);
+
+
+--
+-- Name: repo_builds repo_builds_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY public.repo_builds
+    ADD CONSTRAINT repo_builds_repo_id FOREIGN KEY (repo_id) REFERENCES public.repositories(id);
+
+
 --
 -- Name: repositories_builds repositories_builds_build_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
 --