Skip to content

Commit e09d11b

Browse files
committed
feat(deploy): split cluster changes into keyspace and access changes
1 parent d1d8bb3 commit e09d11b

2 files changed

Lines changed: 34 additions & 18 deletions

File tree

packages/deploy/src/clusterChanges/getCouchbaseClusterChanges.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,15 @@ import {
2929
} from './types.js';
3030

3131
/**
32-
* Return the changes required to meet the nextConfig, given the currentConfig.
33-
* All changes are given in the order they should be applied, in order to minimize operational risks.
34-
*
35-
* @param currentConfig
36-
* @param nextConfig
32+
* Return the keyspace changes (buckets, scopes, collections, indexes) required
33+
* to meet the nextConfig, given the currentConfig.
3734
*/
38-
export function getCouchbaseClusterChanges(
35+
export function getCouchbaseKeyspaceChanges(
3936
currentConfig: Partial<CouchbaseClusterConfig>,
4037
nextConfig: Partial<CouchbaseClusterConfig>
4138
): CouchbaseClusterChange[] {
4239
const changes: CouchbaseClusterChange[] = [];
4340

44-
///////////////
45-
// KEYSPACES //
46-
///////////////
4741
const currentKeyspaceConfig = currentConfig.keyspaces ?? {};
4842
const nextKeyspaceConfig = nextConfig.keyspaces ?? {};
4943

@@ -147,19 +141,42 @@ export function getCouchbaseClusterChanges(
147141
);
148142
});
149143

150-
///////////
151-
// USERS //
152-
///////////
144+
return changes;
145+
}
146+
147+
/**
148+
* Return the access changes (users, and later roles) required
149+
* to meet the nextConfig, given the currentConfig.
150+
*/
151+
export function getCouchbaseAccessChanges(
152+
currentConfig: Partial<CouchbaseClusterConfig>,
153+
nextConfig: Partial<CouchbaseClusterConfig>
154+
): CouchbaseClusterChange[] {
153155
const currentUsersConfig = currentConfig.users ?? [];
154156
const nextUsersConfig = nextConfig.users ?? [];
155157

156158
const newUsers = getNewUsers(currentUsersConfig, nextUsersConfig);
157159
const updatedUsers = getUpdatedUsers(currentUsersConfig, nextUsersConfig);
158160
const obsoleteUsers = getObsoleteUsers(currentUsersConfig, nextUsersConfig);
159161

160-
changes.push(...newUsers, ...updatedUsers, ...obsoleteUsers);
162+
return [...newUsers, ...updatedUsers, ...obsoleteUsers];
163+
}
161164

162-
return changes;
165+
/**
166+
* Return all changes required to meet the nextConfig, given the currentConfig.
167+
* All changes are given in the order they should be applied, in order to minimize operational risks.
168+
*
169+
* @param currentConfig
170+
* @param nextConfig
171+
*/
172+
export function getCouchbaseClusterChanges(
173+
currentConfig: Partial<CouchbaseClusterConfig>,
174+
nextConfig: Partial<CouchbaseClusterConfig>
175+
): CouchbaseClusterChange[] {
176+
return [
177+
...getCouchbaseKeyspaceChanges(currentConfig, nextConfig),
178+
...getCouchbaseAccessChanges(currentConfig, nextConfig),
179+
];
163180
}
164181

165182
/**

packages/deploy/src/clusterChanges/types.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
IBucketSettings,
3-
ICreateBucketSettings, ISearchIndex,
3+
ICreateBucketSettings,
4+
ISearchIndex,
45
IUser,
56
UpdateBucketSettings,
67
} from '@cbjsdev/cbjs';
7-
import { ApiSearchIndexDefinition } from '@cbjsdev/http-client';
88

99
export type CouchbaseClusterChange =
1010
| CouchbaseClusterChangeCreateBucket
@@ -27,8 +27,7 @@ export type CouchbaseClusterChange =
2727
| CouchbaseClusterChangeDropUser
2828
| CouchbaseClusterChangeCreateSearchIndex
2929
| CouchbaseClusterChangeUpdateSearchIndex
30-
| CouchbaseClusterChangeDropSearchIndex
31-
;
30+
| CouchbaseClusterChangeDropSearchIndex;
3231

3332
export type CouchbaseClusterChangeCreateBucket = {
3433
type: 'createBucket';

0 commit comments

Comments
 (0)