diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-24 00:25:45 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-24 17:11:47 +0300 |
commit | 6ce19c537bd9de8d3c9821841bc5ed680b762742 (patch) | |
tree | 2a487b1d5ec75b05e3001a461f149e14e5a859a8 /libbrep | |
parent | 3363e1239973a66722f681999771964e39a98332 (diff) |
Adapt to inventing package_name type
Diffstat (limited to 'libbrep')
-rw-r--r-- | libbrep/build-extra.sql | 4 | ||||
-rw-r--r-- | libbrep/build.cxx | 2 | ||||
-rw-r--r-- | libbrep/build.hxx | 11 | ||||
-rw-r--r-- | libbrep/build.xml | 6 | ||||
-rw-r--r-- | libbrep/common-traits.hxx | 65 | ||||
-rw-r--r-- | libbrep/common.hxx | 16 | ||||
-rwxr-xr-x | libbrep/odb.sh | 1 | ||||
-rw-r--r-- | libbrep/package-extra.sql | 10 | ||||
-rw-r--r-- | libbrep/package-traits.hxx | 8 | ||||
-rw-r--r-- | libbrep/package.cxx | 9 | ||||
-rw-r--r-- | libbrep/package.hxx | 12 | ||||
-rw-r--r-- | libbrep/package.xml | 24 |
12 files changed, 124 insertions, 44 deletions
diff --git a/libbrep/build-extra.sql b/libbrep/build-extra.sql index 4da75e5..96e355c 100644 --- a/libbrep/build-extra.sql +++ b/libbrep/build-extra.sql @@ -22,7 +22,7 @@ SERVER package_server OPTIONS (table_name 'repository'); -- -- CREATE FOREIGN TABLE build_package ( - name TEXT NOT NULL, + name CITEXT NOT NULL, version_epoch INTEGER NOT NULL, version_canonical_upstream TEXT NOT NULL, version_canonical_release TEXT NOT NULL COLLATE "C", @@ -37,7 +37,7 @@ SERVER package_server OPTIONS (table_name 'package'); -- -- CREATE FOREIGN TABLE build_package_constraints ( - name TEXT NOT NULL, + name CITEXT NOT NULL, version_epoch INTEGER NOT NULL, version_canonical_upstream TEXT NOT NULL, version_canonical_release TEXT NOT NULL COLLATE "C", diff --git a/libbrep/build.cxx b/libbrep/build.cxx index 9b379b7..6ed711c 100644 --- a/libbrep/build.cxx +++ b/libbrep/build.cxx @@ -55,7 +55,7 @@ namespace brep // build // build:: - build (string pnm, version pvr, + build (package_name_type pnm, version pvr, string cfg, string tnm, version tvr, optional<string> afp, optional<string> ach, diff --git a/libbrep/build.hxx b/libbrep/build.hxx index 81c3749..64eb10a 100644 --- a/libbrep/build.hxx +++ b/libbrep/build.hxx @@ -24,9 +24,9 @@ // Used by the data migration entries. // -#define LIBBREP_BUILD_SCHEMA_VERSION_BASE 2 +#define LIBBREP_BUILD_SCHEMA_VERSION_BASE 3 -#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 2, closed) +#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 3, open) // We have to keep these mappings at the global scope instead of inside // the brep namespace because they need to be also effective in the @@ -161,12 +161,13 @@ namespace brep class build { public: - using timestamp_type = brep::timestamp; + using timestamp_type = brep::timestamp; + using package_name_type = brep::package_name; // Create the build object with the building state, non-existent status, // the timestamp set to now and the force state set to unforced. // - build (string package_name, version package_version, + build (package_name_type, version, string configuration, string toolchain_name, version toolchain_version, optional<string> agent_fingerprint, @@ -176,7 +177,7 @@ namespace brep build_id id; - string& package_name; // Tracks id.package.name. + package_name_type& package_name; // Tracks id.package.name. upstream_version package_version; // Original of id.package.version. string& configuration; // Tracks id.configuration. string toolchain_name; diff --git a/libbrep/build.xml b/libbrep/build.xml index e765c00..04ffd78 100644 --- a/libbrep/build.xml +++ b/libbrep/build.xml @@ -1,7 +1,7 @@ <changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" schema-name="build" version="1"> - <model version="2"> + <model version="3"> <table name="build" kind="object"> - <column name="package_name" type="TEXT" null="false"/> + <column name="package_name" type="CITEXT" null="false"/> <column name="package_version_epoch" type="INTEGER" null="false"/> <column name="package_version_canonical_upstream" type="TEXT" null="false"/> <column name="package_version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -39,7 +39,7 @@ </primary-key> </table> <table name="build_results" kind="container"> - <column name="package_name" type="TEXT" null="false"/> + <column name="package_name" type="CITEXT" null="false"/> <column name="package_version_epoch" type="INTEGER" null="false"/> <column name="package_version_canonical_upstream" type="TEXT" null="false"/> <column name="package_version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> diff --git a/libbrep/common-traits.hxx b/libbrep/common-traits.hxx new file mode 100644 index 0000000..b3c562e --- /dev/null +++ b/libbrep/common-traits.hxx @@ -0,0 +1,65 @@ +// file : libbrep/common-traits.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBREP_COMMON_TRAITS_HXX +#define LIBBREP_COMMON_TRAITS_HXX + +#include <string> +#include <cstddef> // size_t +#include <utility> // move() + +#include <odb/pgsql/traits.hxx> + +#include <libbpkg/package-name.hxx> + +namespace odb +{ + namespace pgsql + { + template <> + class value_traits<bpkg::package_name, id_string>: + value_traits<std::string, id_string> + { + public: + using value_type = bpkg::package_name; + using query_type = bpkg::package_name; + using image_type = details::buffer; + + using base_type = value_traits<std::string, id_string>; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + std::string s; + base_type::set_value (s, b, n, is_null); + v = !s.empty () ? value_type (std::move (s)) : value_type (); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + base_type::set_image (b, n, is_null, v.string ()); + } + }; + + template <> + struct type_traits<bpkg::package_name> + { + static const database_type_id db_type_id = id_string; + + struct conversion + { + static const char* to () {return "(?)::CITEXT";} + }; + }; + } +} + +#endif // LIBBREP_COMMON_TRAITS_HXX diff --git a/libbrep/common.hxx b/libbrep/common.hxx index 0950e7f..7860876 100644 --- a/libbrep/common.hxx +++ b/libbrep/common.hxx @@ -9,6 +9,8 @@ #include <chrono> #include <type_traits> // static_assert +#include <libbpkg/package-name.hxx> + #include <libbrep/types.hxx> #include <libbrep/utility.hxx> @@ -188,14 +190,24 @@ namespace brep // extern const version wildcard_version; + // package_name + // + using bpkg::package_name; + + #pragma db value(package_name) type("CITEXT") + + #pragma db map type("CITEXT") as("TEXT") to("(?)::CITEXT") from("(?)::TEXT") + + // package_id + // #pragma db value struct package_id { - string name; + package_name name; canonical_version version; package_id () = default; - package_id (string n, const brep::version& v) + package_id (package_name n, const brep::version& v) : name (move (n)), version { v.epoch, v.canonical_upstream, v.canonical_release, v.revision} diff --git a/libbrep/odb.sh b/libbrep/odb.sh index 17a6ac4..3234899 100755 --- a/libbrep/odb.sh +++ b/libbrep/odb.sh @@ -12,6 +12,7 @@ lib="\ $odb $lib -d pgsql --std c++14 --generate-query \ --odb-epilogue '#include <libbrep/wrapper-traits.hxx>' \ --hxx-prologue '#include <libbrep/wrapper-traits.hxx>' \ + --hxx-prologue '#include <libbrep/common-traits.hxx>' \ -DLIBODB_BUILD2 -DLIBODB_PGSQL_BUILD2 \ -I .. -I ../../libbbot -I ../../libbpkg -I ../../libbutl \ --include-with-brackets --include-prefix libbrep \ diff --git a/libbrep/package-extra.sql b/libbrep/package-extra.sql index 5c18da2..bd5a27b 100644 --- a/libbrep/package-extra.sql +++ b/libbrep/package-extra.sql @@ -17,9 +17,9 @@ -- -- DROP FUNCTION IF EXISTS to_tsvector(IN document weighted_text); -- -DROP FUNCTION IF EXISTS search_packages(IN query tsquery, INOUT name TEXT); +DROP FUNCTION IF EXISTS search_packages(IN query tsquery, INOUT name CITEXT); DROP FUNCTION IF EXISTS search_latest_packages(IN query tsquery); -DROP FUNCTION IF EXISTS latest_package(INOUT name TEXT); +DROP FUNCTION IF EXISTS latest_package(INOUT name CITEXT); DROP FUNCTION IF EXISTS latest_packages(); DROP TYPE IF EXISTS weighted_text CASCADE; @@ -50,7 +50,7 @@ $$ LANGUAGE SQL STABLE; -- not found. -- CREATE FUNCTION -latest_package(INOUT name TEXT, +latest_package(INOUT name CITEXT, OUT version_epoch INTEGER, OUT version_canonical_upstream TEXT, OUT version_canonical_release TEXT, @@ -69,7 +69,7 @@ $$ LANGUAGE SQL STABLE; -- CREATE FUNCTION search_latest_packages(IN query tsquery, - OUT name TEXT, + OUT name CITEXT, OUT version_epoch INTEGER, OUT version_canonical_upstream TEXT, OUT version_canonical_release TEXT, @@ -93,7 +93,7 @@ $$ LANGUAGE SQL STABLE; -- CREATE FUNCTION search_packages(IN query tsquery, - INOUT name TEXT, + INOUT name CITEXT, OUT version_epoch INTEGER, OUT version_canonical_upstream TEXT, OUT version_canonical_release TEXT, diff --git a/libbrep/package-traits.hxx b/libbrep/package-traits.hxx index 56c8cec..6045633 100644 --- a/libbrep/package-traits.hxx +++ b/libbrep/package-traits.hxx @@ -1,9 +1,9 @@ -// file : brep/package-traits -*- C++ -*- +// file : libbrep/package-traits.hxx -*- C++ -*- // copyright : Copyright (c) 2014-2018 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef BREP_PACKAGE_TRAITS -#define BREP_PACKAGE_TRAITS +#ifndef LIBBREP_PACKAGE_TRAITS +#define LIBBREP_PACKAGE_TRAITS #include <cstddef> // size_t @@ -35,4 +35,4 @@ namespace odb } } -#endif // BREP_PACKAGE_TRAITS +#endif // LIBBREP_PACKAGE_TRAITS diff --git a/libbrep/package.cxx b/libbrep/package.cxx index 984f36b..7d94422 100644 --- a/libbrep/package.cxx +++ b/libbrep/package.cxx @@ -15,7 +15,7 @@ namespace brep { // dependency // - string dependency:: + package_name dependency:: name () const { return package.object_id ().name; @@ -47,7 +47,7 @@ namespace brep // package // package:: - package (string nm, + package (package_name nm, version_type vr, priority_type pr, string sm, @@ -97,7 +97,7 @@ namespace brep } package:: - package (string nm, + package (package_name nm, version_type vr, shared_ptr<repository_type> rp) : id (move (nm), vr), @@ -123,7 +123,8 @@ namespace brep // Probably drop-box would be better as also tells what are // the available internal repositories. // - string k (id.name + " " + version.string () + " " + version.string (true)); + string k (id.name.string () + " " + version.string () + " " + + version.string (true)); // Add tags to keywords. // diff --git a/libbrep/package.hxx b/libbrep/package.hxx index 98e8178..c6e1162 100644 --- a/libbrep/package.hxx +++ b/libbrep/package.hxx @@ -19,9 +19,9 @@ // Used by the data migration entries. // -#define LIBBREP_PACKAGE_SCHEMA_VERSION_BASE 5 +#define LIBBREP_PACKAGE_SCHEMA_VERSION_BASE 6 -#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 5, closed) +#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 6, open) namespace brep { @@ -125,7 +125,7 @@ namespace brep // Prerequisite package name. // - string + package_name name () const; // Database mapping. @@ -298,7 +298,7 @@ namespace brep // Create internal package object. Note that for stubs the build // constraints are meaningless, and so not saved. // - package (string name, + package (package_name name, version_type, priority_type, string summary, @@ -327,7 +327,7 @@ namespace brep // The only package information required to compose such a link is the // package name, version, and repository location. // - package (string name, version_type, shared_ptr<repository_type>); + package (package_name name, version_type, shared_ptr<repository_type>); bool internal () const noexcept {return internal_repository != nullptr;} @@ -492,7 +492,7 @@ namespace brep double rank; }; - #pragma db view query("/*CALL*/ SELECT count(*) FROM search_packages(?)") + #pragma db view query("/*CALL*/ SELECT count(*) FROM search_packages(?)") struct package_count { size_t result; diff --git a/libbrep/package.xml b/libbrep/package.xml index 1c85e49..9b83bb2 100644 --- a/libbrep/package.xml +++ b/libbrep/package.xml @@ -1,5 +1,5 @@ <changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" schema-name="package" version="1"> - <model version="5"> + <model version="6"> <table name="repository" kind="object"> <column name="name" type="TEXT" null="false"/> <column name="location" type="TEXT" null="false"/> @@ -70,7 +70,7 @@ </foreign-key> </table> <table name="package" kind="object"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -118,7 +118,7 @@ </index> </table> <table name="package_license_alternatives" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -151,7 +151,7 @@ </index> </table> <table name="package_licenses" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -182,7 +182,7 @@ </index> </table> <table name="package_tags" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -215,7 +215,7 @@ </index> </table> <table name="package_dependencies" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -250,14 +250,14 @@ </index> </table> <table name="package_dependency_alternatives" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> <column name="version_revision" type="INTEGER" null="false"/> <column name="dependency_index" type="BIGINT" null="false"/> <column name="index" type="BIGINT" null="false"/> - <column name="dep_name" type="TEXT" null="false"/> + <column name="dep_name" type="CITEXT" null="false"/> <column name="dep_version_epoch" type="INTEGER" null="false"/> <column name="dep_version_canonical_upstream" type="TEXT" null="false"/> <column name="dep_version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -313,7 +313,7 @@ </foreign-key> </table> <table name="package_requirements" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -348,7 +348,7 @@ </index> </table> <table name="package_requirement_alternatives" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -379,7 +379,7 @@ </index> </table> <table name="package_build_constraints" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> @@ -415,7 +415,7 @@ </index> </table> <table name="package_other_repositories" kind="container"> - <column name="name" type="TEXT" null="false"/> + <column name="name" type="CITEXT" null="false"/> <column name="version_epoch" type="INTEGER" null="false"/> <column name="version_canonical_upstream" type="TEXT" null="false"/> <column name="version_canonical_release" type="TEXT" null="false" options="COLLATE "C""/> |