From: Michael Tremer Date: Sun, 9 Feb 2025 11:45:46 +0000 (+0000) Subject: images: Build out class and add the table X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=03fd7852900f11fd4fa2bc81efb7a30538dd44df;p=pbs.git images: Build out class and add the table Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/images.py b/src/buildservice/images.py index f261ab09..e3c832ed 100644 --- a/src/buildservice/images.py +++ b/src/buildservice/images.py @@ -22,7 +22,7 @@ import logging import sqlalchemy from sqlalchemy import Column, ForeignKey -from sqlalchemy import Integer, Text +from sqlalchemy import BigInteger, DateTime, Integer, LargeBinary, Text from . import database @@ -30,7 +30,7 @@ from . import database log = logging.getLogger("pbs.images") class Image(database.Base, database.BackendMixin, database.SoftDeleteMixin): - __tablename__ = "release_images" + __tablename__ = "images" # ID @@ -42,10 +42,70 @@ class Image(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Release - release = sqlalchemy.orm.relationship( - "Release", foreign_keys=[release_id], lazy="joined", innerjoin=True, - ) + release = sqlalchemy.orm.relationship("Release", foreign_keys=[release_id], + back_populates="images", lazy="joined") + + # Type + + type = Column(Text, nullable=False) # Arch arch = Column(Text, nullable=False) + + # Created At + + created_at = Column(DateTime(timezone=False), nullable=False, + server_default=sqlalchemy.func.current_timestamp()) + + # Created By ID + + created_by_id = Column(Integer, ForeignKey("users.id")) + + # Created By + + created_by = sqlalchemy.orm.relationship( + "User", foreign_keys=[created_by_id], lazy="joined", + ) + + # Deleted By ID + + deleted_by_id = Column(Integer, ForeignKey("users.id")) + + # Deleted By + + deleted_by = sqlalchemy.orm.relationship( + "User", foreign_keys=[deleted_by_id], lazy="selectin", + ) + + # Path + + path = Column(Text, nullable=False) + + # Size + + size = Column(BigInteger, nullable=False) + + # Checksum SHA3-512 + + checksum_sha3_512 = Column(LargeBinary, nullable=False) + + # Checksum SHA3-256 + + checksum_sha3_256 = Column(LargeBinary, nullable=False) + + # Checksum BLAKE2B512 + + checksum_blake2b512 = Column(LargeBinary, nullable=False) + + # Checksum BLAKE2S256 + + checksum_blake2s256 = Column(LargeBinary, nullable=False) + + # Checksum SHA2-512 + + checksum_sha2_512 = Column(LargeBinary, nullable=False) + + # Checksum SHA2-256 + + checksum_sha2_256 = Column(LargeBinary, nullable=False) diff --git a/src/buildservice/releases.py b/src/buildservice/releases.py index ae19b059..379e129d 100644 --- a/src/buildservice/releases.py +++ b/src/buildservice/releases.py @@ -26,6 +26,7 @@ from sqlalchemy import Column, Computed, ForeignKey from sqlalchemy import ARRAY, Boolean, DateTime, Integer, Text from . import database +from . import images # Setup logging log = logging.getLogger("pbs.releases") @@ -133,7 +134,9 @@ class Release(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Images - #images = sqlalchemy.orm.relationship("Image", back_populates="release") + images = sqlalchemy.orm.relationship( + "Image", back_populates="release", lazy="selectin", + ) @property def XXXimages(self): diff --git a/src/database.sql b/src/database.sql index 83522bfb..a028b888 100644 --- a/src/database.sql +++ b/src/database.sql @@ -344,6 +344,50 @@ CREATE SEQUENCE public.distributions_id_seq ALTER SEQUENCE public.distributions_id_seq OWNED BY public.distributions.id; +-- +-- Name: images; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.images ( + id integer NOT NULL, + release_id integer NOT NULL, + type text NOT NULL, + arch text NOT NULL, + created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + created_by_id integer, + deleted_at timestamp without time zone, + deleted_by_id integer, + path text NOT NULL, + size bigint NOT NULL, + checksum_sha3_512 bytea NOT NULL, + checksum_sha3_256 bytea NOT NULL, + checksum_blake2b512 bytea NOT NULL, + checksum_blake2s256 bytea NOT NULL, + checksum_sha2_512 bytea NOT NULL, + checksum_sha2_256 bytea NOT NULL +); + + +-- +-- Name: images_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.images_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: images_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.images_id_seq OWNED BY public.images.id; + + -- -- Name: images_types; Type: TABLE; Schema: public; Owner: - -- @@ -1196,6 +1240,13 @@ ALTER TABLE ONLY public.builds ALTER COLUMN id SET DEFAULT nextval('public.build ALTER TABLE ONLY public.distributions ALTER COLUMN id SET DEFAULT nextval('public.distributions_id_seq'::regclass); +-- +-- Name: images id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.images ALTER COLUMN id SET DEFAULT nextval('public.images_id_seq'::regclass); + + -- -- Name: images_types id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1385,6 +1436,22 @@ ALTER TABLE ONLY public.images_types ADD CONSTRAINT image_types_pkey PRIMARY KEY (id); +-- +-- Name: images images_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.images + ADD CONSTRAINT images_pkey PRIMARY KEY (id); + + +-- +-- Name: images images_unique; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.images + ADD CONSTRAINT images_unique UNIQUE (release_id, type, arch); + + -- -- Name: jobs jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2110,6 +2177,30 @@ ALTER TABLE ONLY public.builds ADD CONSTRAINT builds_repo_id FOREIGN KEY (repo_id) REFERENCES public.repositories(id); +-- +-- Name: images images_created_by_id; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.images + ADD CONSTRAINT images_created_by_id FOREIGN KEY (created_by_id) REFERENCES public.users(id); + + +-- +-- Name: images images_deleted_by_id; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.images + ADD CONSTRAINT images_deleted_by_id FOREIGN KEY (deleted_by_id) REFERENCES public.users(id); + + +-- +-- Name: images images_release_id; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.images + ADD CONSTRAINT images_release_id FOREIGN KEY (release_id) REFERENCES public.releases(id); + + -- -- Name: job_packages job_packages_job_id; Type: FK CONSTRAINT; Schema: public; Owner: - --