diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-10-28 01:01:53 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-10-30 16:20:21 +0300 |
commit | 873987793b05fc0d6e9908f5030b2bca145c4e6d (patch) | |
tree | 6641e447d892e5b364ae7471e7a0a71581c85e91 /libbrep | |
parent | 018603c5529117b993066f4f3a0f45f48f92e801 (diff) |
Add tenant object
Diffstat (limited to 'libbrep')
-rw-r--r-- | libbrep/build-extra.sql | 10 | ||||
-rw-r--r-- | libbrep/build-package.hxx | 82 | ||||
-rw-r--r-- | libbrep/build.hxx | 14 | ||||
-rw-r--r-- | libbrep/build.xml | 2 | ||||
-rw-r--r-- | libbrep/package.cxx | 9 | ||||
-rw-r--r-- | libbrep/package.hxx | 52 | ||||
-rw-r--r-- | libbrep/package.xml | 145 |
7 files changed, 279 insertions, 35 deletions
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<string> 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<brep::build> 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 @@ <changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" schema-name="build" version="1"> + <changeset version="5"/> + <model version="4"> <table name="build" kind="object"> <column name="package_tenant" type="TEXT" null="false"/> 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 @@ <changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="pgsql" schema-name="package" version="1"> + <changeset version="9"> + <add-table name="tenant" kind="object"> + <column name="id" type="TEXT" null="false"/> + <column name="creation_timestamp" type="BIGINT" null="false"/> + <column name="archived" type="BOOLEAN" null="false"/> + <primary-key> + <column name="id"/> + </primary-key> + </add-table> + <alter-table name="repository"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="repository_complements"> + <add-foreign-key name="repository_tenant_fk" deferrable="DEFERRED"> + <column name="repository_tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + <add-foreign-key name="complement_tenant_fk" deferrable="DEFERRED"> + <column name="complement_tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="repository_prerequisites"> + <add-foreign-key name="repository_tenant_fk" deferrable="DEFERRED"> + <column name="repository_tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + <add-foreign-key name="prerequisite_tenant_fk" deferrable="DEFERRED"> + <column name="prerequisite_tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + <add-foreign-key name="internal_repository_tenant_fk" deferrable="DEFERRED"> + <column name="internal_repository_tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_license_alternatives"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_licenses"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_tags"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_dependencies"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_dependency_alternatives"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + <add-foreign-key name="dep_package_tenant_fk" deferrable="DEFERRED"> + <column name="dep_package_tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_requirements"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_requirement_alternatives"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_build_constraints"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + <alter-table name="package_other_repositories"> + <add-foreign-key name="tenant_fk" deferrable="DEFERRED"> + <column name="tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + <add-foreign-key name="repository_tenant_fk" deferrable="DEFERRED"> + <column name="repository_tenant"/> + <references table="tenant"> + <column name="id"/> + </references> + </add-foreign-key> + </alter-table> + </changeset> + <changeset version="8"/> <model version="7"> |