From: Michael Tremer Date: Tue, 30 Dec 2025 12:10:31 +0000 (+0000) Subject: reports: Use a UUID as primary key X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6eb157362d2c66923c508c6b2e00ea1e1a39d9f;p=dbl.git reports: Use a UUID as primary key Signed-off-by: Michael Tremer --- diff --git a/src/database.sql b/src/database.sql index 1e9aff7..979d869 100644 --- a/src/database.sql +++ b/src/database.sql @@ -2,7 +2,7 @@ -- PostgreSQL database dump -- -\restrict delNzbfbaFwfjowYSA0Hv8h5YKH5ddoC9grkkzzBvFQDPYVsiqb0QZFyQzEzwfL +\restrict Hq2I33CNLRM7K7kcCycXF0u7UASfMPt7lX7HhX0lOG4SePHngyo8IfElIz9I44O -- Dumped from database version 17.6 (Debian 17.6-0+deb13u1) -- Dumped by pg_dump version 17.6 (Debian 17.6-0+deb13u1) @@ -144,7 +144,7 @@ ALTER SEQUENCE public.nameservers_id_seq OWNED BY public.nameservers.id; -- CREATE TABLE public.reports ( - id integer NOT NULL, + id uuid DEFAULT gen_random_uuid() NOT NULL, list_id integer NOT NULL, name text NOT NULL, reported_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, @@ -157,26 +157,6 @@ CREATE TABLE public.reports ( ); --- --- Name: reports_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.reports_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: reports_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.reports_id_seq OWNED BY public.reports.id; - - -- -- Name: source_domains; Type: TABLE; Schema: public; Owner: - -- @@ -274,13 +254,6 @@ ALTER TABLE ONLY public.lists ALTER COLUMN id SET DEFAULT nextval('public.lists_ ALTER TABLE ONLY public.nameservers ALTER COLUMN id SET DEFAULT nextval('public.nameservers_id_seq'::regclass); --- --- Name: reports id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.reports ALTER COLUMN id SET DEFAULT nextval('public.reports_id_seq'::regclass); - - -- -- Name: source_domains id; Type: DEFAULT; Schema: public; Owner: - -- @@ -421,5 +394,5 @@ ALTER TABLE ONLY public.sources -- PostgreSQL database dump complete -- -\unrestrict delNzbfbaFwfjowYSA0Hv8h5YKH5ddoC9grkkzzBvFQDPYVsiqb0QZFyQzEzwfL +\unrestrict Hq2I33CNLRM7K7kcCycXF0u7UASfMPt7lX7HhX0lOG4SePHngyo8IfElIz9I44O diff --git a/src/dnsbl/api/reports.py b/src/dnsbl/api/reports.py index 84f3f04..c928471 100644 --- a/src/dnsbl/api/reports.py +++ b/src/dnsbl/api/reports.py @@ -20,6 +20,7 @@ import fastapi import typing +import uuid from .. import reports @@ -33,7 +34,7 @@ router = fastapi.APIRouter( tags=["Reports"], ) -def get_report_from_path(id: str = fastapi.Path(...)) -> reports.Report: +def get_report_from_path(id: uuid.UUID = fastapi.Path(...)) -> reports.Report: """ Fetches a report by its ID """ diff --git a/src/dnsbl/reports.py b/src/dnsbl/reports.py index 15f0910..5ba4434 100644 --- a/src/dnsbl/reports.py +++ b/src/dnsbl/reports.py @@ -20,6 +20,7 @@ import datetime import sqlmodel +import uuid from . import database @@ -71,7 +72,7 @@ class Report(sqlmodel.SQLModel, database.BackendMixin, table=True): __tablename__ = "reports" # ID - id : int = sqlmodel.Field(primary_key=True) + id : uuid.UUID = sqlmodel.Field(primary_key=True) # List ID list_id : int = sqlmodel.Field(foreign_key="lists.id", exclude=True)