Ability to append mutliple attributes along with `_class` to each query [DATACOUCH-464]
UmairYasin opened DATACOUCH-464 and commented
I am using document based multi tenant approach where each document in couchbase db have tenant-ID field. Now for all the queries that are executing in my application, i want extend tenant-ID to it which is present in Session Context One solution is to manually add the tenant-id clause to every query but this solution is not very optimal as i want to enforce that no query in applicaion should be executed without tenant-id.
There should be a way to extend couchbase base configuration to add tenant-id like the same way it is adding _class attribute to every query
Affects: 3.1.9 (Lovelace SR9)
UmairYasin commented
David Nault - Can you please let me know if this is feasible to implement with spring data couchbase? If yes then let me know please so i can try and create a PR for this. Thanks
David Kelly commented
I'm thinking that this is a feature we could add, but in fact something that should cover this is coming. There was a recent blog post which mentioned the coming 'collections' feature. Though it is .net, it will be in java too. We will add the support for that in spring data as well. There may be other mentions of it, some with more detail, over in our blogs
UmairYasin commented
Kelly - Can you please let me know the expected release date of stable couchbase 6.5 and related SDK's? Thanks
Matt Ingenthron commented
As of this writing, expected to be toward the end of 2019. Spring support would follow after that, aligned to Spring's release
Michael Reiche commented
https://jira.spring.io/browse/DATACOUCH-525 will allow specifying a field other than _class, and a value other than the name of the class. (i.e. a mapper could replace _class = 'com.example.domain.Person' with t='Person'), but this request seems to be beyond that and will need additional work
Michael Reiche commented
The getTypeAlias(TypeInformation<?> info) method takes only a TypeInformation object - which does not contain any query data, so this mechanism cannot be used for partitioning multi-tenant data. Partitioning on Bucket or Collection are other options.
However - the id can be constructed from multiple prefixes, multiple attributes (or a generated UUID), and multiple suffixes - all of which are fields from the entity - for example this uses the value of the 'company' field as the prefix (for multi-tenant, possibly). Queries would need to include the predicate (meta().id like ( company || '.%')). (the period is the delimiter). When a field is used as a prefix/suffix of the id, it is not included in the content (attributes are included in the content).
@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
String id;
@IdPrefix
String company;
|Person : { id : Shuster.362e1bc3-e4c2-4f58-ac66-6c69d2f95fb4, firstname=Dwight, middlename : David, lastname='Smith', version : 1592605700734189568, },|
scope should be used to separate tenant data.
i want to enforce that no query in applicaion should be executed without tenant-id
That is not sufficient for compartmentalizing data. Data should be compartmentalized with authorization, not just a convention.