]> git.ipfire.org Git - people/jschlag/pbs.git/blobdiff - src/database.sql
Allow jobs to be superseeded by each other
[people/jschlag/pbs.git] / src / database.sql
index d03fcb14046fb8eec48471e68a92cb53ffe28c4f..03d24015dec5cf84b6aad33e3542c36fe0c27c4a 100644 (file)
@@ -37,66 +37,6 @@ CREATE TYPE arches_binary AS ENUM (
 
 ALTER TYPE arches_binary OWNER TO pakfire;
 
---
--- Name: builders_arches_enabled; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE builders_arches_enabled AS ENUM (
-    'Y',
-    'N'
-);
-
-
-ALTER TYPE builders_arches_enabled OWNER TO pakfire;
-
---
--- Name: builders_build_release; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE builders_build_release AS ENUM (
-    'Y',
-    'N'
-);
-
-
-ALTER TYPE builders_build_release OWNER TO pakfire;
-
---
--- Name: builders_build_scratch; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE builders_build_scratch AS ENUM (
-    'Y',
-    'N'
-);
-
-
-ALTER TYPE builders_build_scratch OWNER TO pakfire;
-
---
--- Name: builders_build_test; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE builders_build_test AS ENUM (
-    'Y',
-    'N'
-);
-
-
-ALTER TYPE builders_build_test OWNER TO pakfire;
-
---
--- Name: builders_deleted; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE builders_deleted AS ENUM (
-    'Y',
-    'N'
-);
-
-
-ALTER TYPE builders_deleted OWNER TO pakfire;
-
 --
 -- Name: builders_disabled; Type: TYPE; Schema: public; Owner: pakfire
 --
@@ -135,19 +75,6 @@ CREATE TYPE builders_overload AS ENUM (
 
 ALTER TYPE builders_overload OWNER TO pakfire;
 
---
--- Name: builders_status; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE builders_status AS ENUM (
-    'enabled',
-    'disabled',
-    'deleted'
-);
-
-
-ALTER TYPE builders_status OWNER TO pakfire;
-
 --
 -- Name: builds_auto_move; Type: TYPE; Schema: public; Owner: pakfire
 --
@@ -160,18 +87,6 @@ CREATE TYPE builds_auto_move AS ENUM (
 
 ALTER TYPE builds_auto_move OWNER TO pakfire;
 
---
--- Name: builds_bugs_updates_error; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE builds_bugs_updates_error AS ENUM (
-    'N',
-    'Y'
-);
-
-
-ALTER TYPE builds_bugs_updates_error OWNER TO pakfire;
-
 --
 -- Name: builds_history_action; Type: TYPE; Schema: public; Owner: pakfire
 --
@@ -321,19 +236,6 @@ CREATE TYPE jobs_type AS ENUM (
 
 ALTER TYPE jobs_type OWNER TO pakfire;
 
---
--- Name: mirrors_check_status; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE mirrors_check_status AS ENUM (
-    'UNKNOWN',
-    'UP',
-    'DOWN'
-);
-
-
-ALTER TYPE mirrors_check_status OWNER TO pakfire;
-
 --
 -- Name: mirrors_history_action; Type: TYPE; Schema: public; Owner: pakfire
 --
@@ -348,19 +250,6 @@ CREATE TYPE mirrors_history_action AS ENUM (
 
 ALTER TYPE mirrors_history_action OWNER TO pakfire;
 
---
--- Name: mirrors_status; Type: TYPE; Schema: public; Owner: pakfire
---
-
-CREATE TYPE mirrors_status AS ENUM (
-    'enabled',
-    'disabled',
-    'deleted'
-);
-
-
-ALTER TYPE mirrors_status OWNER TO pakfire;
-
 --
 -- Name: packages_deps_type; Type: TYPE; Schema: public; Owner: pakfire
 --
@@ -625,10 +514,7 @@ SET default_with_oids = false;
 
 CREATE TABLE arches (
     id integer NOT NULL,
-    name text NOT NULL,
-    prio integer DEFAULT 0 NOT NULL,
-    "binary" arches_binary DEFAULT 'Y'::arches_binary NOT NULL,
-    platform text
+    name text NOT NULL
 );
 
 
@@ -639,13 +525,35 @@ ALTER TABLE arches OWNER TO pakfire;
 --
 
 CREATE TABLE arches_compat (
-    host_arch text NOT NULL,
-    build_arch text NOT NULL
+    native_arch text NOT NULL,
+    build_arch text NOT NULL,
+    CONSTRAINT arches_compat_unique CHECK ((native_arch <> build_arch))
 );
 
 
 ALTER TABLE arches_compat OWNER TO pakfire;
 
+--
+-- Name: arches_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
+--
+
+CREATE SEQUENCE arches_id_seq
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+ALTER TABLE arches_id_seq OWNER TO pakfire;
+
+--
+-- Name: arches_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pakfire
+--
+
+ALTER SEQUENCE arches_id_seq OWNED BY arches.id;
+
+
 --
 -- Name: builders; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -655,13 +563,10 @@ CREATE TABLE builders (
     name text NOT NULL,
     passphrase text,
     description text,
-    status builders_status DEFAULT 'disabled'::builders_status NOT NULL,
-    disabled builders_disabled DEFAULT 'Y'::builders_disabled NOT NULL,
+    enabled boolean DEFAULT false NOT NULL,
+    deleted boolean DEFAULT false NOT NULL,
     loadavg text DEFAULT '0'::character varying NOT NULL,
-    arches text,
-    build_release builders_build_release DEFAULT 'N'::builders_build_release NOT NULL,
-    build_scratch builders_build_scratch DEFAULT 'N'::builders_build_scratch NOT NULL,
-    build_test builders_build_test DEFAULT 'N'::builders_build_test NOT NULL,
+    testmode boolean DEFAULT true NOT NULL,
     max_jobs bigint DEFAULT 1::bigint NOT NULL,
     pakfire_version text,
     os_name text,
@@ -673,8 +578,7 @@ CREATE TABLE builders (
     overload builders_overload DEFAULT 'N'::builders_overload NOT NULL,
     free_space bigint DEFAULT 0 NOT NULL,
     host_key_id text,
-    deleted builders_deleted DEFAULT 'N'::builders_deleted NOT NULL,
-    time_created timestamp without time zone NOT NULL,
+    time_created timestamp without time zone DEFAULT now() NOT NULL,
     time_updated timestamp without time zone,
     time_keepalive timestamp without time zone,
     loadavg1 double precision,
@@ -690,75 +594,6 @@ CREATE TABLE builders (
 
 ALTER TABLE builders OWNER TO pakfire;
 
---
--- Name: arches_builders; Type: VIEW; Schema: public; Owner: pakfire
---
-
-CREATE VIEW arches_builders AS
- SELECT arches_compat.build_arch AS arch,
-    builders.id AS builder_id
-   FROM (arches_compat
-     LEFT JOIN builders ON ((arches_compat.host_arch = builders.cpu_arch)));
-
-
-ALTER TABLE arches_builders OWNER TO pakfire;
-
---
--- Name: arches_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
---
-
-CREATE SEQUENCE arches_id_seq
-    START WITH 1
-    INCREMENT BY 1
-    NO MINVALUE
-    NO MAXVALUE
-    CACHE 1;
-
-
-ALTER TABLE arches_id_seq OWNER TO pakfire;
-
---
--- Name: arches_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pakfire
---
-
-ALTER SEQUENCE arches_id_seq OWNED BY arches.id;
-
-
---
--- Name: builders_arches; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE TABLE builders_arches (
-    id integer NOT NULL,
-    builder_id integer NOT NULL,
-    arch_id integer NOT NULL,
-    enabled builders_arches_enabled DEFAULT 'Y'::builders_arches_enabled NOT NULL
-);
-
-
-ALTER TABLE builders_arches OWNER TO pakfire;
-
---
--- Name: builders_arches_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
---
-
-CREATE SEQUENCE builders_arches_id_seq
-    START WITH 1
-    INCREMENT BY 1
-    NO MINVALUE
-    NO MAXVALUE
-    CACHE 1;
-
-
-ALTER TABLE builders_arches_id_seq OWNER TO pakfire;
-
---
--- Name: builders_arches_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pakfire
---
-
-ALTER SEQUENCE builders_arches_id_seq OWNED BY builders_arches.id;
-
-
 --
 -- Name: builders_history; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -816,77 +651,6 @@ ALTER TABLE builders_id_seq OWNER TO pakfire;
 ALTER SEQUENCE builders_id_seq OWNED BY builders.id;
 
 
---
--- Name: jobs; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE TABLE jobs (
-    id integer NOT NULL,
-    uuid text NOT NULL,
-    type jobs_type DEFAULT 'build'::jobs_type NOT NULL,
-    build_id integer NOT NULL,
-    state jobs_state DEFAULT 'new'::jobs_state NOT NULL,
-    arch_id integer NOT NULL,
-    time_created timestamp without time zone NOT NULL,
-    time_started timestamp without time zone,
-    time_finished timestamp without time zone,
-    start_not_before timestamp without time zone,
-    builder_id integer,
-    tries integer DEFAULT 0 NOT NULL,
-    aborted_state integer DEFAULT 0 NOT NULL,
-    message text
-);
-
-
-ALTER TABLE jobs OWNER TO pakfire;
-
---
--- Name: jobs_active; Type: VIEW; Schema: public; Owner: pakfire
---
-
-CREATE VIEW jobs_active AS
- SELECT jobs.id,
-    jobs.uuid,
-    jobs.type,
-    jobs.build_id,
-    jobs.state,
-    jobs.arch_id,
-    jobs.time_created,
-    jobs.time_started,
-    jobs.time_finished,
-    jobs.start_not_before,
-    jobs.builder_id,
-    jobs.tries,
-    jobs.aborted_state,
-    jobs.message
-   FROM jobs
-  WHERE (jobs.state = ANY (ARRAY['dispatching'::jobs_state, 'running'::jobs_state, 'uploading'::jobs_state]))
-  ORDER BY jobs.time_started;
-
-
-ALTER TABLE jobs_active OWNER TO pakfire;
-
---
--- Name: builders_ready; Type: VIEW; Schema: public; Owner: pakfire
---
-
-CREATE VIEW builders_ready AS
- SELECT builders.id AS builder_id,
-    builders.cpu_arch AS builder_arch,
-    builders.build_release,
-    builders.build_scratch,
-    builders.build_test
-   FROM builders
-  WHERE (((builders.status = 'enabled'::builders_status) AND (builders.time_keepalive >= (now() - '00:05:00'::interval))) AND (builders.max_jobs > ( SELECT count(*) AS count
-           FROM jobs_active
-          WHERE (jobs_active.builder_id = builders.id))))
-  ORDER BY ( SELECT count(*) AS count
-           FROM jobs_active
-          WHERE (jobs_active.builder_id = builders.id)), builders.cpu_bogomips DESC;
-
-
-ALTER TABLE builders_ready OWNER TO pakfire;
-
 --
 -- Name: builds; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -896,10 +660,10 @@ CREATE TABLE builds (
     uuid text NOT NULL,
     pkg_id integer NOT NULL,
     type builds_type DEFAULT 'release'::builds_type NOT NULL,
-    state builds_state DEFAULT 'building'::builds_state NOT NULL,
+    state text DEFAULT 'building'::text NOT NULL,
     severity builds_severity,
     message text,
-    time_created timestamp with time zone NOT NULL,
+    time_created timestamp without time zone NOT NULL,
     update_year integer,
     update_num integer,
     depends_on integer,
@@ -958,7 +722,7 @@ CREATE TABLE builds_bugs_updates (
     resolution text,
     comment text,
     "time" timestamp without time zone NOT NULL,
-    error builds_bugs_updates_error DEFAULT 'N'::builds_bugs_updates_error NOT NULL,
+    error boolean DEFAULT false NOT NULL,
     error_msg text
 );
 
@@ -1083,75 +847,28 @@ ALTER SEQUENCE builds_id_seq OWNED BY builds.id;
 
 
 --
--- Name: packages; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
+-- Name: jobs; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-CREATE TABLE packages (
+CREATE TABLE jobs (
     id integer NOT NULL,
-    name text NOT NULL,
-    epoch integer NOT NULL,
-    version text NOT NULL,
-    release text NOT NULL,
-    type packages_type NOT NULL,
-    arch integer NOT NULL,
-    groups text NOT NULL,
-    maintainer text NOT NULL,
-    license text NOT NULL,
-    url text NOT NULL,
-    summary text NOT NULL,
-    description text NOT NULL,
-    size bigint NOT NULL,
-    supported_arches text,
     uuid text NOT NULL,
-    commit_id integer,
-    build_id text NOT NULL,
-    build_host text NOT NULL,
-    build_time timestamp without time zone NOT NULL,
-    path text NOT NULL,
-    filesize bigint NOT NULL,
-    hash_sha512 text NOT NULL
-);
-
-
-ALTER TABLE packages OWNER TO pakfire;
-
---
--- Name: repositories_builds; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE TABLE repositories_builds (
-    id integer NOT NULL,
-    repo_id integer NOT NULL,
-    build_id bigint NOT NULL,
-    time_added timestamp without time zone NOT NULL
+    type jobs_type DEFAULT 'build'::jobs_type NOT NULL,
+    build_id integer NOT NULL,
+    state jobs_state DEFAULT 'new'::jobs_state NOT NULL,
+    arch text NOT NULL,
+    time_created timestamp without time zone NOT NULL,
+    time_started timestamp without time zone,
+    time_finished timestamp without time zone,
+    start_not_before timestamp without time zone,
+    builder_id integer,
+    tries integer DEFAULT 0 NOT NULL,
+    aborted_state integer DEFAULT 0 NOT NULL,
+    message text
 );
 
 
-ALTER TABLE repositories_builds OWNER TO pakfire;
-
---
--- Name: builds_latest; Type: VIEW; Schema: public; Owner: pakfire
---
-
-CREATE VIEW builds_latest AS
- SELECT builds.id AS build_id,
-    builds.type AS build_type,
-    builds.state AS build_state,
-    packages.name AS package_name,
-    builds.public
-   FROM (builds
-     LEFT JOIN packages ON ((builds.pkg_id = packages.id)))
-  WHERE ((builds.id IN ( SELECT repositories_builds.build_id
-           FROM repositories_builds)) OR ((builds.time_created >= ( SELECT builds_1.time_created
-           FROM ((builds builds_1
-             LEFT JOIN repositories_builds ON ((builds_1.id = repositories_builds.build_id)))
-             LEFT JOIN packages p ON ((builds_1.pkg_id = p.id)))
-          WHERE (p.name = packages.name)
-          ORDER BY builds_1.time_created
-         LIMIT 1)) AND (builds.state <> ALL (ARRAY['obsolete'::builds_state, 'broken'::builds_state]))));
-
-
-ALTER TABLE builds_latest OWNER TO pakfire;
+ALTER TABLE jobs OWNER TO pakfire;
 
 --
 -- Name: builds_times; Type: VIEW; Schema: public; Owner: pakfire
@@ -1159,14 +876,11 @@ ALTER TABLE builds_latest OWNER TO pakfire;
 
 CREATE VIEW builds_times AS
  SELECT builds.id AS build_id,
-    arches.name AS arch,
-    arches.platform,
+    jobs.arch,
     jobs.type AS job_type,
     (jobs.time_finished - jobs.time_started) AS duration
-   FROM (((jobs
+   FROM (jobs
      LEFT JOIN builds ON ((jobs.build_id = builds.id)))
-     LEFT JOIN packages ON ((builds.pkg_id = packages.id)))
-     LEFT JOIN arches ON ((jobs.arch_id = arches.id)))
   WHERE (jobs.state = 'finished'::jobs_state);
 
 
@@ -1218,12 +932,26 @@ CREATE TABLE distributions (
     description text,
     vendor text NOT NULL,
     contact text,
-    tag text NOT NULL
+    tag text NOT NULL,
+    deleted boolean DEFAULT false NOT NULL
 );
 
 
 ALTER TABLE distributions OWNER TO pakfire;
 
+--
+-- Name: distributions_arches; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+CREATE TABLE distributions_arches (
+    id integer NOT NULL,
+    distro_id integer NOT NULL,
+    arch text NOT NULL
+);
+
+
+ALTER TABLE distributions_arches OWNER TO pakfire;
+
 --
 -- Name: distributions_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
 --
@@ -1245,19 +973,6 @@ ALTER TABLE distributions_id_seq OWNER TO pakfire;
 ALTER SEQUENCE distributions_id_seq OWNED BY distributions.id;
 
 
---
--- Name: distro_arches; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE TABLE distro_arches (
-    id integer NOT NULL,
-    distro_id integer NOT NULL,
-    arch_id integer NOT NULL
-);
-
-
-ALTER TABLE distro_arches OWNER TO pakfire;
-
 --
 -- Name: distro_arches_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
 --
@@ -1276,7 +991,7 @@ ALTER TABLE distro_arches_id_seq OWNER TO pakfire;
 -- Name: distro_arches_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pakfire
 --
 
-ALTER SEQUENCE distro_arches_id_seq OWNED BY distro_arches.id;
+ALTER SEQUENCE distro_arches_id_seq OWNED BY distributions_arches.id;
 
 
 --
@@ -1293,7 +1008,7 @@ CREATE TABLE filelists (
     mode integer NOT NULL,
     "user" text NOT NULL,
     "group" text NOT NULL,
-    mtime timestamp with time zone NOT NULL,
+    mtime timestamp without time zone NOT NULL,
     capabilities text
 );
 
@@ -1333,6 +1048,32 @@ ALTER TABLE images_types_id_seq OWNER TO pakfire;
 ALTER SEQUENCE images_types_id_seq OWNED BY images_types.id;
 
 
+--
+-- Name: jobs_active; Type: VIEW; Schema: public; Owner: pakfire
+--
+
+CREATE VIEW jobs_active AS
+ SELECT jobs.id,
+    jobs.uuid,
+    jobs.type,
+    jobs.build_id,
+    jobs.state,
+    jobs.arch,
+    jobs.time_created,
+    jobs.time_started,
+    jobs.time_finished,
+    jobs.start_not_before,
+    jobs.builder_id,
+    jobs.tries,
+    jobs.aborted_state,
+    jobs.message
+   FROM jobs
+  WHERE (jobs.state = ANY (ARRAY['dispatching'::jobs_state, 'running'::jobs_state, 'uploading'::jobs_state]))
+  ORDER BY jobs.time_started;
+
+
+ALTER TABLE jobs_active OWNER TO pakfire;
+
 --
 -- Name: jobs_buildroots; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -1424,30 +1165,16 @@ ALTER SEQUENCE jobs_packages_id_seq OWNED BY jobs_packages.id;
 --
 
 CREATE VIEW jobs_queue AS
- SELECT jobs.id,
-    arches.name AS arch,
-    ( SELECT builders_ready.builder_id
-           FROM builders_ready
-          WHERE (builders_ready.builder_id IN ( SELECT arches_builders.builder_id
-                   FROM arches_builders
-                  WHERE ((arches_builders.arch = arches.name) AND
-                        CASE
-                            WHEN ((builds.type = 'release'::builds_type) AND (jobs.type = 'build'::jobs_type)) THEN (builders_ready.build_release = 'Y'::builders_build_release)
-                            WHEN ((builds.type = 'scratch'::builds_type) AND (jobs.type = 'build'::jobs_type)) THEN (builders_ready.build_scratch = 'Y'::builders_build_scratch)
-                            WHEN (jobs.type = 'test'::jobs_type) THEN (builders_ready.build_test = 'Y'::builders_build_test)
-                            ELSE NULL::boolean
-                        END)))
-         LIMIT 1) AS designated_builder_id
-   FROM ((jobs
-     LEFT JOIN arches ON ((jobs.arch_id = arches.id)))
-     LEFT JOIN builds ON ((jobs.build_id = builds.id)))
-  WHERE ((jobs.state = ANY (ARRAY['pending'::jobs_state, 'new'::jobs_state])) AND ((jobs.start_not_before IS NULL) OR (jobs.start_not_before <= now())))
-  ORDER BY
-        CASE
-            WHEN (jobs.type = 'build'::jobs_type) THEN 0
-            WHEN (jobs.type = 'test'::jobs_type) THEN 1
-            ELSE NULL::integer
-        END, builds.priority DESC, jobs.tries, jobs.time_created;
+ WITH queue AS (
+         SELECT jobs.id,
+            rank() OVER (ORDER BY jobs.type, builds.priority DESC, jobs.tries, jobs.time_created) AS rank
+           FROM (jobs
+             LEFT JOIN builds ON ((jobs.build_id = builds.id)))
+          WHERE (jobs.state = 'pending'::jobs_state)
+        )
+ SELECT queue.id AS job_id,
+    queue.rank
+   FROM queue;
 
 
 ALTER TABLE jobs_queue OWNER TO pakfire;
@@ -1464,26 +1191,6 @@ CREATE TABLE jobs_repos (
 
 ALTER TABLE jobs_repos OWNER TO pakfire;
 
---
--- Name: jobs_waiting; Type: VIEW; Schema: public; Owner: pakfire
---
-
-CREATE VIEW jobs_waiting AS
- SELECT jobs_queue.id,
-    (now() - (jobs.time_created)::timestamp with time zone) AS time_waiting
-   FROM (jobs_queue
-     LEFT JOIN jobs ON ((jobs_queue.id = jobs.id)))
-  WHERE (jobs.start_not_before IS NULL)
-UNION
- SELECT jobs_queue.id,
-    (now() - (jobs.start_not_before)::timestamp with time zone) AS time_waiting
-   FROM (jobs_queue
-     LEFT JOIN jobs ON ((jobs_queue.id = jobs.id)))
-  WHERE (jobs.start_not_before IS NOT NULL);
-
-
-ALTER TABLE jobs_waiting OWNER TO pakfire;
-
 --
 -- Name: keys; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -1602,14 +1309,50 @@ CREATE TABLE mirrors (
     path text NOT NULL,
     owner text,
     contact text,
-    status mirrors_status DEFAULT 'disabled'::mirrors_status NOT NULL,
-    check_status mirrors_check_status DEFAULT 'UNKNOWN'::mirrors_check_status NOT NULL,
-    last_check timestamp without time zone
+    deleted boolean DEFAULT false NOT NULL
 );
 
 
 ALTER TABLE mirrors OWNER TO pakfire;
 
+--
+-- Name: mirrors_checks; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+CREATE TABLE mirrors_checks (
+    id integer NOT NULL,
+    mirror_id integer NOT NULL,
+    "timestamp" timestamp without time zone DEFAULT now() NOT NULL,
+    response_time double precision,
+    http_status integer,
+    last_sync_at timestamp without time zone,
+    status text DEFAULT 'OK'::text NOT NULL
+);
+
+
+ALTER TABLE mirrors_checks OWNER TO pakfire;
+
+--
+-- Name: mirrors_checks_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
+--
+
+CREATE SEQUENCE mirrors_checks_id_seq
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+ALTER TABLE mirrors_checks_id_seq OWNER TO pakfire;
+
+--
+-- Name: mirrors_checks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pakfire
+--
+
+ALTER SEQUENCE mirrors_checks_id_seq OWNED BY mirrors_checks.id;
+
+
 --
 -- Name: mirrors_history; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -1667,6 +1410,39 @@ ALTER TABLE mirrors_id_seq OWNER TO pakfire;
 ALTER SEQUENCE mirrors_id_seq OWNED BY mirrors.id;
 
 
+--
+-- Name: packages; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+CREATE TABLE packages (
+    id integer NOT NULL,
+    name text NOT NULL,
+    epoch integer NOT NULL,
+    version text NOT NULL,
+    release text NOT NULL,
+    type packages_type NOT NULL,
+    arch text NOT NULL,
+    groups text NOT NULL,
+    maintainer text NOT NULL,
+    license text NOT NULL,
+    url text NOT NULL,
+    summary text NOT NULL,
+    description text NOT NULL,
+    size bigint NOT NULL,
+    supported_arches text,
+    uuid text NOT NULL,
+    commit_id integer,
+    build_id text NOT NULL,
+    build_host text NOT NULL,
+    build_time timestamp without time zone NOT NULL,
+    path text NOT NULL,
+    filesize bigint NOT NULL,
+    hash_sha512 text NOT NULL
+);
+
+
+ALTER TABLE packages OWNER TO pakfire;
+
 --
 -- Name: packages_deps; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -1769,6 +1545,21 @@ ALTER TABLE queue_delete_id_seq OWNER TO pakfire;
 ALTER SEQUENCE queue_delete_id_seq OWNED BY queue_delete.id;
 
 
+--
+-- Name: relation_sizes; Type: VIEW; Schema: public; Owner: pakfire
+--
+
+CREATE VIEW relation_sizes AS
+ SELECT c.relname AS relation,
+    pg_size_pretty(pg_relation_size((c.oid)::regclass)) AS size
+   FROM (pg_class c
+     LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
+  WHERE (n.nspname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name]))
+  ORDER BY pg_relation_size((c.oid)::regclass) DESC;
+
+
+ALTER TABLE relation_sizes OWNER TO pakfire;
+
 --
 -- Name: repositories; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -1781,14 +1572,15 @@ CREATE TABLE repositories (
     distro_id integer NOT NULL,
     parent_id integer,
     key_id integer,
-    mirrored repositories_mirrored DEFAULT 'N'::repositories_mirrored NOT NULL,
-    enabled_for_builds repositories_enabled_for_builds DEFAULT 'N'::repositories_enabled_for_builds NOT NULL,
+    mirrored boolean DEFAULT false NOT NULL,
+    enabled_for_builds boolean DEFAULT false NOT NULL,
     score_needed integer DEFAULT 0 NOT NULL,
     last_update timestamp without time zone,
     time_min integer DEFAULT 0 NOT NULL,
     time_max integer DEFAULT 0 NOT NULL,
     update_started timestamp without time zone,
-    update_ended timestamp without time zone
+    update_ended timestamp without time zone,
+    deleted boolean DEFAULT false NOT NULL
 );
 
 
@@ -1831,6 +1623,20 @@ ALTER TABLE repositories_aux_id_seq OWNER TO pakfire;
 ALTER SEQUENCE repositories_aux_id_seq OWNED BY repositories_aux.id;
 
 
+--
+-- Name: repositories_builds; Type: TABLE; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+CREATE TABLE repositories_builds (
+    id integer NOT NULL,
+    repo_id integer NOT NULL,
+    build_id bigint NOT NULL,
+    time_added timestamp without time zone NOT NULL
+);
+
+
+ALTER TABLE repositories_builds OWNER TO pakfire;
+
 --
 -- Name: repositories_builds_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
 --
@@ -2006,7 +1812,8 @@ CREATE TABLE sources_commits (
     subject text NOT NULL,
     body text NOT NULL,
     date timestamp without time zone NOT NULL,
-    state sources_commits_state DEFAULT 'pending'::sources_commits_state NOT NULL
+    state sources_commits_state DEFAULT 'pending'::sources_commits_state NOT NULL,
+    imported_at timestamp without time zone DEFAULT now() NOT NULL
 );
 
 
@@ -2262,13 +2069,6 @@ ALTER TABLE ONLY arches ALTER COLUMN id SET DEFAULT nextval('arches_id_seq'::reg
 ALTER TABLE ONLY builders ALTER COLUMN id SET DEFAULT nextval('builders_id_seq'::regclass);
 
 
---
--- Name: id; Type: DEFAULT; Schema: public; Owner: pakfire
---
-
-ALTER TABLE ONLY builders_arches ALTER COLUMN id SET DEFAULT nextval('builders_arches_id_seq'::regclass);
-
-
 --
 -- Name: id; Type: DEFAULT; Schema: public; Owner: pakfire
 --
@@ -2329,7 +2129,7 @@ ALTER TABLE ONLY distributions ALTER COLUMN id SET DEFAULT nextval('distribution
 -- Name: id; Type: DEFAULT; Schema: public; Owner: pakfire
 --
 
-ALTER TABLE ONLY distro_arches ALTER COLUMN id SET DEFAULT nextval('distro_arches_id_seq'::regclass);
+ALTER TABLE ONLY distributions_arches ALTER COLUMN id SET DEFAULT nextval('distro_arches_id_seq'::regclass);
 
 
 --
@@ -2381,6 +2181,13 @@ ALTER TABLE ONLY logfiles ALTER COLUMN id SET DEFAULT nextval('logfiles_id_seq':
 ALTER TABLE ONLY mirrors ALTER COLUMN id SET DEFAULT nextval('mirrors_id_seq'::regclass);
 
 
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY mirrors_checks ALTER COLUMN id SET DEFAULT nextval('mirrors_checks_id_seq'::regclass);
+
+
 --
 -- Name: id; Type: DEFAULT; Schema: public; Owner: pakfire
 --
@@ -2494,27 +2301,35 @@ ALTER TABLE ONLY users_permissions ALTER COLUMN id SET DEFAULT nextval('users_pe
 
 
 --
--- Name: idx_2197943_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
+-- Name: arches_compat_unique; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+ALTER TABLE ONLY arches_compat
+    ADD CONSTRAINT arches_compat_unique UNIQUE (native_arch, build_arch);
+
+
+--
+-- Name: arches_name; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
 --
 
 ALTER TABLE ONLY arches
-    ADD CONSTRAINT idx_2197943_primary PRIMARY KEY (id);
+    ADD CONSTRAINT arches_name UNIQUE (name);
 
 
 --
--- Name: idx_2197954_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
+-- Name: idx_2197943_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-ALTER TABLE ONLY builders
-    ADD CONSTRAINT idx_2197954_primary PRIMARY KEY (id);
+ALTER TABLE ONLY arches
+    ADD CONSTRAINT idx_2197943_primary PRIMARY KEY (id);
 
 
 --
--- Name: idx_2197975_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
+-- Name: idx_2197954_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-ALTER TABLE ONLY builders_arches
-    ADD CONSTRAINT idx_2197975_primary PRIMARY KEY (id);
+ALTER TABLE ONLY builders
+    ADD CONSTRAINT idx_2197954_primary PRIMARY KEY (id);
 
 
 --
@@ -2585,7 +2400,7 @@ ALTER TABLE ONLY distributions
 -- Name: idx_2198048_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-ALTER TABLE ONLY distro_arches
+ALTER TABLE ONLY distributions_arches
     ADD CONSTRAINT idx_2198048_primary PRIMARY KEY (id);
 
 
@@ -2773,6 +2588,14 @@ ALTER TABLE ONLY jobs_packages
     ADD CONSTRAINT jobs_packages_unique UNIQUE (job_id, pkg_id);
 
 
+--
+-- Name: mirrors_checks_pkey; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+ALTER TABLE ONLY mirrors_checks
+    ADD CONSTRAINT mirrors_checks_pkey PRIMARY KEY (id);
+
+
 --
 -- Name: sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -2790,10 +2613,17 @@ ALTER TABLE ONLY sessions
 
 
 --
--- Name: builders_arches_builder_id; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
+-- Name: arches_compat_native_arch; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-CREATE INDEX builders_arches_builder_id ON builders_arches USING btree (builder_id);
+CREATE INDEX arches_compat_native_arch ON arches_compat USING btree (native_arch);
+
+
+--
+-- Name: builders_name; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+CREATE UNIQUE INDEX builders_name ON builders USING btree (name) WHERE (deleted IS FALSE);
 
 
 --
@@ -2804,17 +2634,24 @@ CREATE INDEX builds_watchers_build_id ON builds_watchers USING btree (build_id);
 
 
 --
--- Name: filelists_name; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
+-- Name: distributions_arches_distro_id; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-CREATE INDEX filelists_name ON filelists USING btree (name);
+CREATE INDEX distributions_arches_distro_id ON distributions_arches USING btree (distro_id);
+
+
+--
+-- Name: distributions_sname; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+CREATE UNIQUE INDEX distributions_sname ON distributions USING btree (sname) WHERE (deleted IS FALSE);
 
 
 --
--- Name: idx_2197949_host_arch; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
+-- Name: filelists_name; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-CREATE INDEX idx_2197949_host_arch ON arches_compat USING btree (host_arch);
+CREATE INDEX filelists_name ON filelists USING btree (name);
 
 
 --
@@ -2880,13 +2717,6 @@ CREATE INDEX idx_2198018_user_id ON builds_comments USING btree (user_id);
 CREATE INDEX idx_2198052_pkg_id ON filelists USING btree (pkg_id);
 
 
---
--- Name: idx_2198063_arch_id; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE INDEX idx_2198063_arch_id ON jobs USING btree (arch_id);
-
-
 --
 -- Name: idx_2198063_build_id; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -2950,13 +2780,6 @@ CREATE UNIQUE INDEX idx_2198089_job_id ON jobs_repos USING btree (job_id, repo_i
 CREATE UNIQUE INDEX idx_2198094_fingerprint ON keys USING btree (fingerprint);
 
 
---
--- Name: idx_2198132_epoch; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE INDEX idx_2198132_epoch ON packages USING btree (epoch);
-
-
 --
 -- Name: idx_2198132_name; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -2964,13 +2787,6 @@ CREATE INDEX idx_2198132_epoch ON packages USING btree (epoch);
 CREATE INDEX idx_2198132_name ON packages USING btree (name);
 
 
---
--- Name: idx_2198132_release; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE INDEX idx_2198132_release ON packages USING btree (release);
-
-
 --
 -- Name: idx_2198132_type; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -2985,13 +2801,6 @@ CREATE INDEX idx_2198132_type ON packages USING btree (type);
 CREATE INDEX idx_2198132_uuid ON packages USING btree (uuid);
 
 
---
--- Name: idx_2198132_version; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
---
-
-CREATE INDEX idx_2198132_version ON packages USING btree (version);
-
-
 --
 -- Name: idx_2198139_pkg_id; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -3069,6 +2878,13 @@ CREATE UNIQUE INDEX idx_2198256_email ON users_emails USING btree (email);
 CREATE INDEX idx_2198256_user_id ON users_emails USING btree (user_id);
 
 
+--
+-- Name: jobs_arch; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
+--
+
+CREATE INDEX jobs_arch ON jobs USING btree (arch);
+
+
 --
 -- Name: jobs_buildroots_pkg_uuid; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
@@ -3077,26 +2893,34 @@ CREATE INDEX jobs_buildroots_pkg_uuid ON jobs_buildroots USING btree (pkg_uuid);
 
 
 --
--- Name: on_update_current_timestamp; Type: TRIGGER; Schema: public; Owner: pakfire
+-- Name: mirrors_checks_sort; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON sources FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_sources();
+CREATE INDEX mirrors_checks_sort ON mirrors_checks USING btree (mirror_id, "timestamp");
+
+ALTER TABLE mirrors_checks CLUSTER ON mirrors_checks_sort;
 
 
 --
--- Name: builders_arches_arch_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+-- Name: repositories_builds_repo_id; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: 
 --
 
-ALTER TABLE ONLY builders_arches
-    ADD CONSTRAINT builders_arches_arch_id FOREIGN KEY (arch_id) REFERENCES arches(id);
+CREATE INDEX repositories_builds_repo_id ON repositories_builds USING btree (repo_id);
 
 
 --
--- Name: builders_arches_builder_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+-- Name: on_update_current_timestamp; Type: TRIGGER; Schema: public; Owner: pakfire
 --
 
-ALTER TABLE ONLY builders_arches
-    ADD CONSTRAINT builders_arches_builder_id FOREIGN KEY (builder_id) REFERENCES builders(id);
+CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON sources FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_sources();
+
+
+--
+-- Name: arches_compat_build_arch; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY arches_compat
+    ADD CONSTRAINT arches_compat_build_arch FOREIGN KEY (build_arch) REFERENCES arches(name);
 
 
 --
@@ -3204,18 +3028,18 @@ ALTER TABLE ONLY builds_watchers
 
 
 --
--- Name: distro_arches_arch_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+-- Name: distributions_arches_arch; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
 --
 
-ALTER TABLE ONLY distro_arches
-    ADD CONSTRAINT distro_arches_arch_id FOREIGN KEY (arch_id) REFERENCES arches(id);
+ALTER TABLE ONLY distributions_arches
+    ADD CONSTRAINT distributions_arches_arch FOREIGN KEY (arch) REFERENCES arches(name);
 
 
 --
 -- Name: distro_arches_distro_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
 --
 
-ALTER TABLE ONLY distro_arches
+ALTER TABLE ONLY distributions_arches
     ADD CONSTRAINT distro_arches_distro_id FOREIGN KEY (distro_id) REFERENCES distributions(id);
 
 
@@ -3228,11 +3052,11 @@ ALTER TABLE ONLY filelists
 
 
 --
--- Name: jobs_arch_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+-- Name: jobs_arch; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
 --
 
 ALTER TABLE ONLY jobs
-    ADD CONSTRAINT jobs_arch_id FOREIGN KEY (arch_id) REFERENCES arches(id);
+    ADD CONSTRAINT jobs_arch FOREIGN KEY (arch) REFERENCES arches(name);
 
 
 --
@@ -3339,6 +3163,14 @@ ALTER TABLE ONLY logfiles
     ADD CONSTRAINT logfiles_job_id FOREIGN KEY (job_id) REFERENCES jobs(id);
 
 
+--
+-- Name: mirrors_checks_mirror_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+--
+
+ALTER TABLE ONLY mirrors_checks
+    ADD CONSTRAINT mirrors_checks_mirror_id FOREIGN KEY (mirror_id) REFERENCES mirrors(id);
+
+
 --
 -- Name: mirrors_history_mirror_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
 --
@@ -3360,7 +3192,7 @@ ALTER TABLE ONLY mirrors_history
 --
 
 ALTER TABLE ONLY packages
-    ADD CONSTRAINT packages_arch FOREIGN KEY (arch) REFERENCES arches(id);
+    ADD CONSTRAINT packages_arch FOREIGN KEY (arch) REFERENCES arches(name);
 
 
 --