return builds
- def create(self, repo, package, owner=None):
+ def create(self, repo, package, owner=None, group=None):
"""
Creates a new build based on the given distribution and package
"""
(
build_repo_id,
pkg_id,
- owner_id
+ owner_id,
+ build_group_id
)
VALUES
(
- %s,
- %s,
- %s
+ %s, %s, %s, %s
)
RETURNING *""",
repo,
package,
owner,
+ group,
)
+ # Populate cache
+ if group:
+ build.group = group
+
# Create all jobs
build._create_jobs()
return build
+ # Groups
+
+ @lazy_property
+ def groups(self):
+ """
+ Build Groups
+ """
+ return Groups(self.backend)
+
# Comments
@lazy_property
def distro(self):
return self.build_repo.distro
+ # Group
+
+ @lazy_property
+ def group(self):
+ if self.data.build_group_id:
+ return self.backend.builds.groups.get_by_id(self.data.build_group_id)
+
@property
def state(self):
return self.data.state
self._update_bug(bug_id, status=status, resolution=resolution, comment=comment)
+class Groups(base.Object):
+ """
+ Build Groups are simple objects that group multiple builds together
+ """
+ def _get_groups(self, query, *args):
+ res = self.db.query(query, *args)
+
+ for row in res:
+ yield Group(self.backend, row.id, data=row)
+
+ def _get_group(self, query, *args):
+ res = self.db.get(query, *args)
+
+ if res:
+ return Group(self.backend, res.id, data=res)
+
+ def get_by_id(self, id):
+ return self._get_group("""
+ SELECT
+ *
+ FROM
+ build_groups
+ WHERE
+ id = %s
+ """, id,
+ )
+
+ def create(self):
+ """
+ Creates a new Build Group
+ """
+ return self._get_group("""
+ INSERT INTO
+ build_groups
+ DEFAULT VALUES
+ RETURNING
+ *
+ """,
+ )
+
+
+class Group(base.DataObject):
+ table = "build_groups"
+
+ # UUID
+
+ @property
+ def uuid(self):
+ return self.data.uuid
+
+ # Created At
+
+ @property
+ def created_at(self):
+ return self.data.created_at
+
+ # Builds
+
+ @lazy_property
+ def builds(self):
+ builds = self.backend.builds._get_builds("""
+ SELECT
+ *
+ FROM
+ builds
+ WHERE
+ deleted_at IS FALSE
+ AND
+ build_group_id = %s
+ """, self.id,
+ )
+
+ return list(builds)
+
+
class Comments(base.Object):
def _get_comments(self, query, *args):
res = self.db.query(query, *args)
);
+--
+-- 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
+);
+
+
+--
+-- Name: build_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE public.build_groups_id_seq
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: build_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE public.build_groups_id_seq OWNED BY public.build_groups.id;
+
+
--
-- Name: build_packages; Type: TABLE; Schema: public; Owner: -
--
finished_at timestamp without time zone,
failed boolean DEFAULT false NOT NULL,
deleted_at timestamp without time zone,
- deleted_by integer
+ deleted_by integer,
+ build_group_id integer
);
ALTER TABLE ONLY public.build_comments ALTER COLUMN id SET DEFAULT nextval('public.builds_comments_id_seq'::regclass);
+--
+-- Name: build_groups id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_groups ALTER COLUMN id SET DEFAULT nextval('public.build_groups_id_seq'::regclass);
+
+
--
-- Name: builders id; Type: DEFAULT; Schema: public; Owner: -
--
ADD CONSTRAINT build_comments_pkey PRIMARY KEY (id);
+--
+-- Name: build_groups build_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.build_groups
+ ADD CONSTRAINT build_groups_pkey PRIMARY KEY (id);
+
+
--
-- Name: builds builds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
CREATE INDEX build_comments_user_id ON public.build_comments USING btree (user_id) WHERE (deleted IS FALSE);
+--
+-- Name: build_groups_uuid; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE UNIQUE INDEX build_groups_uuid ON public.build_groups USING btree (uuid);
+
+
--
-- Name: build_packages_build_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX builders_name ON public.builders USING btree (name) WHERE (deleted IS FALSE);
+--
+-- Name: builds_build_group_id; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX builds_build_group_id ON public.builds USING btree (build_group_id) WHERE (deleted_at IS NULL);
+
+
--
-- Name: builds_created_at; Type: INDEX; Schema: public; Owner: -
--
ADD CONSTRAINT builder_stats_builder_id FOREIGN KEY (builder_id) REFERENCES public.builders(id);
+--
+-- Name: builds builds_build_group_id; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.builds
+ ADD CONSTRAINT builds_build_group_id FOREIGN KEY (build_group_id) REFERENCES public.build_groups(id);
+
+
--
-- Name: builds builds_build_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--