From 873987793b05fc0d6e9908f5030b2bca145c4e6d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sun, 28 Oct 2018 01:01:53 +0300 Subject: Add tenant object --- libbrep/build-extra.sql | 10 ++++ libbrep/build-package.hxx | 82 ++++++++++++++++---------- libbrep/build.hxx | 14 +++-- libbrep/build.xml | 2 + libbrep/package.cxx | 9 +++ libbrep/package.hxx | 52 ++++++++++++++++- libbrep/package.xml | 145 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 279 insertions(+), 35 deletions(-) (limited to 'libbrep') diff --git a/libbrep/build-extra.sql b/libbrep/build-extra.sql index 35ba361..6c0d6ef 100644 --- a/libbrep/build-extra.sql +++ b/libbrep/build-extra.sql @@ -12,6 +12,16 @@ DROP FOREIGN TABLE IF EXISTS build_package; DROP FOREIGN TABLE IF EXISTS build_repository; +DROP FOREIGN TABLE IF EXISTS build_tenant; + +-- The foreign table for build_tenant object. +-- +-- +CREATE FOREIGN TABLE build_tenant ( + id TEXT NOT NULL, + archived BOOLEAN NOT NULL) +SERVER package_server OPTIONS (table_name 'tenant'); + -- The foreign table for build_repository object. -- -- diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx index 0fed500..0d6b5bf 100644 --- a/libbrep/build-package.hxx +++ b/libbrep/build-package.hxx @@ -23,7 +23,26 @@ namespace brep // The mapping is established in build-extra.sql. We also explicitly mark // non-primary key foreign-mapped members in the source object. // - // Foreign object that is mapped to a subset of repository object. + // Foreign object that is mapped to a subset of the tenant object. + // + #pragma db object table("build_tenant") pointer(shared_ptr) readonly + class build_tenant + { + public: + string id; + + bool archived; + + // Database mapping. + // + #pragma db member(id) id + + private: + friend class odb::access; + build_tenant () = default; + }; + + // Foreign object that is mapped to a subset of the repository object. // #pragma db object table("build_repository") pointer(shared_ptr) readonly class build_repository @@ -61,7 +80,7 @@ namespace brep optional target; }; - // Foreign object that is mapped to a subset of package object. + // Foreign object that is mapped to a subset of the package object. // #pragma db object table("build_package") pointer(shared_ptr) readonly class build_package @@ -92,14 +111,15 @@ namespace brep // Note that ADL can't find the equal operator, so we use the function call // notation. // - #pragma db view \ - object(build_package) \ - object(build_repository inner: \ - brep::operator== (build_package::internal_repository, \ - build_repository::id) && \ - brep::compare_version_ne (build_package::id.version, \ - brep::wildcard_version, \ - false)) + #pragma db view \ + object(build_package) \ + object(build_repository inner: \ + brep::operator== (build_package::internal_repository, \ + build_repository::id) && \ + brep::compare_version_ne (build_package::id.version, \ + brep::wildcard_version, \ + false)) \ + object(build_tenant: build_package::id.tenant == build_tenant::id) struct buildable_package { package_id id; @@ -110,14 +130,15 @@ namespace brep #pragma db member(version) set(this.version.init (this.id.version, (?))) }; - #pragma db view \ - object(build_package) \ - object(build_repository inner: \ - brep::operator== (build_package::internal_repository, \ - build_repository::id) && \ - brep::compare_version_ne (build_package::id.version, \ - brep::wildcard_version, \ - false)) + #pragma db view \ + object(build_package) \ + object(build_repository inner: \ + brep::operator== (build_package::internal_repository, \ + build_repository::id) && \ + brep::compare_version_ne (build_package::id.version, \ + brep::wildcard_version, \ + false)) \ + object(build_tenant: build_package::id.tenant == build_tenant::id) struct buildable_package_count { size_t result; @@ -133,18 +154,19 @@ namespace brep // (internal and non-stub) packages can have such constraints, so there is // no need for additional checks. // - #pragma db view \ - table("build_package_constraints" = "c") \ - object(build_package = package inner: \ - "c.exclusion AND " \ - "c.tenant = " + package::id.tenant + "AND" + \ - "c.name = " + package::id.name + "AND" + \ - "c.version_epoch = " + package::id.version.epoch + "AND" + \ - "c.version_canonical_upstream = " + \ - package::id.version.canonical_upstream + "AND" + \ - "c.version_canonical_release = " + \ - package::id.version.canonical_release + "AND" + \ - "c.version_revision = " + package::id.version.revision) \ + #pragma db view \ + table("build_package_constraints" = "c") \ + object(build_package inner: \ + "c.exclusion AND " \ + "c.tenant = " + build_package::id.tenant + "AND" + \ + "c.name = " + build_package::id.name + "AND" + \ + "c.version_epoch = " + build_package::id.version.epoch + "AND" + \ + "c.version_canonical_upstream = " + \ + build_package::id.version.canonical_upstream + "AND" + \ + "c.version_canonical_release = " + \ + build_package::id.version.canonical_release + "AND" + \ + "c.version_revision = " + build_package::id.version.revision) \ + object(build_tenant: build_package::id.tenant == build_tenant::id) \ query(distinct) struct build_constrained_package { diff --git a/libbrep/build.hxx b/libbrep/build.hxx index fc314eb..279c1d7 100644 --- a/libbrep/build.hxx +++ b/libbrep/build.hxx @@ -26,7 +26,7 @@ // #define LIBBREP_BUILD_SCHEMA_VERSION_BASE 4 -#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 4, closed) +#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 5, 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 @@ -251,7 +251,11 @@ namespace brep } }; - #pragma db view object(build) query(distinct) + #pragma db view object(build) \ + object(build_package inner: \ + brep::operator== (build::id.package, build_package::id) && \ + build_package::internal_repository.canonical_name.is_not_null ()) \ + query(distinct) struct toolchain { string name; @@ -297,7 +301,8 @@ namespace brep object(build) \ object(build_package inner: \ brep::operator== (build::id.package, build_package::id) && \ - build_package::internal_repository.canonical_name.is_not_null ()) + build_package::internal_repository.canonical_name.is_not_null ()) \ + object(build_tenant: build_package::id.tenant == build_tenant::id) struct package_build { shared_ptr build; @@ -307,7 +312,8 @@ namespace brep object(build) \ object(build_package inner: \ brep::operator== (build::id.package, build_package::id) && \ - build_package::internal_repository.canonical_name.is_not_null ()) + build_package::internal_repository.canonical_name.is_not_null ()) \ + object(build_tenant: build_package::id.tenant == build_tenant::id) struct package_build_count { size_t result; diff --git a/libbrep/build.xml b/libbrep/build.xml index 0116374..13b47a6 100644 --- a/libbrep/build.xml +++ b/libbrep/build.xml @@ -1,4 +1,6 @@ + + diff --git a/libbrep/package.cxx b/libbrep/package.cxx index e3921fe..d10186c 100644 --- a/libbrep/package.cxx +++ b/libbrep/package.cxx @@ -38,6 +38,15 @@ namespace brep return !(x == y); } + // tenant + // + tenant:: + tenant (string i) + : id (move (i)), + creation_timestamp (timestamp::clock::now ()) + { + } + // package // package:: diff --git a/libbrep/package.hxx b/libbrep/package.hxx index af4581c..fb44bf3 100644 --- a/libbrep/package.hxx +++ b/libbrep/package.hxx @@ -21,7 +21,7 @@ // #define LIBBREP_PACKAGE_SCHEMA_VERSION_BASE 7 -#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 8, open) +#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 9, open) namespace brep { @@ -185,6 +185,42 @@ namespace brep }; #pragma db object pointer(shared_ptr) session + class tenant + { + public: + // Create the tenant object with the timestamp set to now and the archived + // flag set to false. + // + explicit + tenant (string id); + + string id; + + timestamp creation_timestamp; + bool archived = false; // Note: foreign-mapped in build. + + // Database mapping. + // + #pragma db member(id) id + + private: + friend class odb::access; + tenant () = default; + }; + + #pragma db view object(tenant) + struct tenant_id + { + #pragma db column("id") + string value; + }; + + // Tweak repository_id mapping to include a constraint (this only affects + // the database schema). + // + #pragma db member(repository_id::tenant) points_to(tenant) + + #pragma db object pointer(shared_ptr) session class repository { public: @@ -269,6 +305,15 @@ namespace brep repository (): tenant (id.tenant), canonical_name (id.canonical_name) {} }; + // Used for data migration (see migrate/migrate.cxx for details). + // + #pragma db view object(repository) query(distinct) + struct repository_tenant + { + #pragma db column("tenant") + string id; + }; + // The 'to' expression calls the PostgreSQL to_tsvector(weighted_text) // function overload (package-extra.sql). Since we are only interested // in "write-only" members of this type, make the 'from' expression @@ -289,6 +334,11 @@ namespace brep string d; }; + // Tweak package_id mapping to include a constraint (this only affects the + // database schema). + // + #pragma db member(package_id::tenant) points_to(tenant) + #pragma db object pointer(shared_ptr) session class package { diff --git a/libbrep/package.xml b/libbrep/package.xml index 07c1be7..2b9ebab 100644 --- a/libbrep/package.xml +++ b/libbrep/package.xml @@ -1,4 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.1