Skip to content

Commit 8caff77

Browse files
committed
Add missing functionality to update multi tenancy config
1 parent 196b074 commit 8caff77

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

src/collections/config/classes.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { WeaviateInvalidInputError } from '../../errors.js';
33
import {
44
WeaviateClass,
55
WeaviateInvertedIndexConfig,
6+
WeaviateMultiTenancyConfig,
67
WeaviateReplicationConfig,
78
WeaviateVectorIndexConfig,
89
WeaviateVectorsConfig,
910
} from '../../openapi/types.js';
1011
import { QuantizerGuards } from '../configure/parsing.js';
1112
import {
1213
InvertedIndexConfigUpdate,
14+
MultiTenancyConfigUpdate,
1315
ReplicationConfigUpdate,
1416
VectorConfigUpdate,
1517
VectorIndexConfigFlatUpdate,
@@ -67,6 +69,15 @@ export class MergeWithExisting {
6769
return merged;
6870
}
6971

72+
static multiTenancy(
73+
current: WeaviateMultiTenancyConfig,
74+
update?: MultiTenancyConfigUpdate
75+
): MultiTenancyConfigUpdate {
76+
if (current === undefined) throw Error('Multi-tenancy config is missing from the class schema.');
77+
if (update === undefined) return current;
78+
return { ...current, ...update };
79+
}
80+
7081
static replication(
7182
current: WeaviateReplicationConfig,
7283
update?: ReplicationConfigUpdate

src/collections/config/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './vectorizer.js';
55

66
import {
77
InvertedIndexConfigUpdate,
8+
MultiTenancyConfigUpdate,
89
ReplicationConfigUpdate,
910
VectorConfigUpdate,
1011
} from '../../configure/types/index.js';
@@ -103,6 +104,7 @@ export type CollectionConfig = {
103104
export type CollectionConfigUpdate = {
104105
description?: string;
105106
invertedIndex?: InvertedIndexConfigUpdate;
107+
multiTenancy?: MultiTenancyConfigUpdate;
106108
replication?: ReplicationConfigUpdate;
107109
vectorizers?:
108110
| VectorConfigUpdate<undefined, VectorIndexType>

src/collections/config/unit.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { WeaviateInvertedIndexConfig, WeaviateVectorsConfig } from '../../openapi/types';
1+
import {
2+
WeaviateInvertedIndexConfig,
3+
WeaviateMultiTenancyConfig,
4+
WeaviateVectorsConfig,
5+
} from '../../openapi/types';
26
import { MergeWithExisting } from './classes';
37

48
describe('Unit testing of the MergeWithExisting class', () => {
@@ -112,6 +116,12 @@ describe('Unit testing of the MergeWithExisting class', () => {
112116
},
113117
};
114118

119+
const multiTenancyConfig: WeaviateMultiTenancyConfig = {
120+
enabled: false,
121+
autoTenantActivation: false,
122+
autoTenantCreation: false,
123+
};
124+
115125
it('should merge a partial invertedIndexUpdate with existing schema', () => {
116126
const merged = MergeWithExisting.invertedIndex(JSON.parse(JSON.stringify(invertedIndex)), {
117127
bm25: {
@@ -341,4 +351,17 @@ describe('Unit testing of the MergeWithExisting class', () => {
341351
},
342352
});
343353
});
354+
355+
it('should merge full multi tenancy config with existing schema', () => {
356+
const merged = MergeWithExisting.multiTenancy(JSON.parse(JSON.stringify(multiTenancyConfig)), {
357+
enabled: true,
358+
autoTenantActivation: true,
359+
autoTenantCreation: true,
360+
});
361+
expect(merged).toEqual({
362+
enabled: true,
363+
autoTenantActivation: true,
364+
autoTenantCreation: true,
365+
});
366+
});
344367
});

src/collections/configure/types/base.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export type InvertedIndexConfigUpdate = {
3131

3232
export type MultiTenancyConfigCreate = RecursivePartial<MultiTenancyConfig>;
3333

34+
export type MultiTenancyConfigUpdate = {
35+
autoTenantActivation?: boolean;
36+
autoTenantCreation?: boolean;
37+
enabled?: boolean;
38+
};
39+
3440
export type NestedPropertyCreate<T = undefined> = T extends undefined
3541
? {
3642
name: string;

0 commit comments

Comments
 (0)