From 1367aa09951e0aa7491bc2a5bf7209b0b47be65e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 13 Sep 2018 19:27:00 +0300 Subject: Add support for packages and builds global views --- libbrep/package-extra.sql | 21 +++++++++--------- libbrep/package.cxx | 54 ++++++++++++++++++++++++----------------------- libbrep/package.hxx | 4 +++- 3 files changed, 42 insertions(+), 37 deletions(-) (limited to 'libbrep') diff --git a/libbrep/package-extra.sql b/libbrep/package-extra.sql index d9930aa..93c61d8 100644 --- a/libbrep/package-extra.sql +++ b/libbrep/package-extra.sql @@ -30,7 +30,8 @@ DROP FUNCTION IF EXISTS latest_packages(IN tenant TEXT); DROP TYPE IF EXISTS weighted_text CASCADE; CREATE TYPE weighted_text AS (a TEXT, b TEXT, c TEXT, d TEXT); --- Return the latest versions of internal packages as a set of package rows. +-- Return the latest versions of matching a tenant internal packages as a set +-- of package rows. If tenant is NULL, then match all tenants. -- CREATE FUNCTION latest_packages(IN tenant TEXT) @@ -49,7 +50,7 @@ RETURNS SETOF package AS $$ p1.version_canonical_release = p2.version_canonical_release AND p1.version_revision < p2.version_revision)))) WHERE - p1.tenant = latest_packages.tenant AND + (latest_packages.tenant IS NULL OR p1.tenant = latest_packages.tenant) AND p1.internal_repository_canonical_name IS NOT NULL AND p2.name IS NULL; $$ LANGUAGE SQL STABLE; @@ -72,10 +73,10 @@ RETURNS SETOF record AS $$ WHERE name = latest_package.name; $$ LANGUAGE SQL STABLE; --- Search for the latest version of an internal packages matching the specified --- search query. Return a set of rows containing the package id and search --- rank. If query is NULL, then match all packages and return 0 rank for --- all rows. +-- Search for the latest version of an internal packages matching the +-- specified search query and tenant. Return a set of rows containing the +-- package id and search rank. If query is NULL, then match all packages and +-- return 0 rank for all rows. If tenant is NULL, then match all tenants. -- CREATE FUNCTION search_latest_packages(IN query tsquery, @@ -98,10 +99,10 @@ RETURNS SETOF record AS $$ WHERE query IS NULL OR search_index @@ query; $$ LANGUAGE SQL STABLE; --- Search for packages matching the search query and having the specified --- tenant and name. Return a set of rows containing the package id and search +-- Search for packages matching the search query and tenant and having the +-- specified name. Return a set of rows containing the package id and search -- rank. If query is NULL, then match all packages and return 0 rank for all --- rows. +-- rows. If tenant is NULL, then match all tenants. -- CREATE FUNCTION search_packages(IN query tsquery, @@ -122,7 +123,7 @@ RETURNS SETOF record AS $$ END AS rank FROM package WHERE - tenant = search_packages.tenant AND + (search_packages.tenant IS NULL OR tenant = search_packages.tenant) AND name = search_packages.name AND internal_repository_canonical_name IS NOT NULL AND (query IS NULL OR search_index @@ query); diff --git a/libbrep/package.cxx b/libbrep/package.cxx index 41dd4e2..e3921fe 100644 --- a/libbrep/package.cxx +++ b/libbrep/package.cxx @@ -64,32 +64,33 @@ namespace brep optional fr, optional sh, shared_ptr rp) - : id (rp->tenant, move (nm), vr), - name (id.name), - version (move (vr)), - project (move (pn)), - priority (move (pr)), - summary (move (sm)), - license_alternatives (move (la)), - tags (move (tg)), - description (move (ds)), - changes (move (ch)), - url (move (ur)), - doc_url (move (du)), - src_url (move (su)), - package_url (move (pu)), - email (move (em)), - package_email (move (pe)), - build_email (move (be)), - dependencies (move (dp)), - requirements (move (rq)), - build_constraints (version.compare (wildcard_version, true) != 0 - ? move (bc) - : build_constraints_type ()), - internal_repository (move (rp)), - location (move (lc)), - fragment (move (fr)), - sha256sum (move (sh)) + : id (rp->tenant, move (nm), vr), + tenant (id.tenant), + name (id.name), + version (move (vr)), + project (move (pn)), + priority (move (pr)), + summary (move (sm)), + license_alternatives (move (la)), + tags (move (tg)), + description (move (ds)), + changes (move (ch)), + url (move (ur)), + doc_url (move (du)), + src_url (move (su)), + package_url (move (pu)), + email (move (em)), + package_email (move (pe)), + build_email (move (be)), + dependencies (move (dp)), + requirements (move (rq)), + build_constraints (version.compare (wildcard_version, true) != 0 + ? move (bc) + : build_constraints_type ()), + internal_repository (move (rp)), + location (move (lc)), + fragment (move (fr)), + sha256sum (move (sh)) { assert (internal_repository->internal); } @@ -99,6 +100,7 @@ namespace brep version_type vr, shared_ptr rp) : id (rp->tenant, move (nm), vr), + tenant (id.tenant), name (id.name), version (move (vr)) { diff --git a/libbrep/package.hxx b/libbrep/package.hxx index 6e372b3..fbe6f60 100644 --- a/libbrep/package.hxx +++ b/libbrep/package.hxx @@ -346,6 +346,7 @@ namespace brep // package_id id; + const string& tenant; // Tracks id.tenant. const package_name& name; // Tracks id.name. upstream_version version; @@ -395,6 +396,7 @@ namespace brep // Database mapping. // #pragma db member(id) id column("") + #pragma db member(tenant) transient #pragma db member(name) transient #pragma db member(version) set(this.version.init (this.id.version, (?))) @@ -476,7 +478,7 @@ namespace brep private: friend class odb::access; - package (): name (id.name) {} + package (): tenant (id.tenant), name (id.name) {} // Save keywords, summary, description, and changes to weighted_text // a, b, c, d members, respectively. So a word found in keywords will -- cgit v1.1