aboutsummaryrefslogtreecommitdiff
path: root/libbrep/package.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-10-28 01:01:53 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-10-30 16:20:21 +0300
commit873987793b05fc0d6e9908f5030b2bca145c4e6d (patch)
tree6641e447d892e5b364ae7471e7a0a71581c85e91 /libbrep/package.hxx
parent018603c5529117b993066f4f3a0f45f48f92e801 (diff)
Add tenant object
Diffstat (limited to 'libbrep/package.hxx')
-rw-r--r--libbrep/package.hxx52
1 files changed, 51 insertions, 1 deletions
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
{