Skip to content

Commit

Permalink
feat: Make preAggregationsSchema an option of CubejsServerCore
Browse files Browse the repository at this point in the history
Fixes #96
  • Loading branch information
paveltiunov committed Aug 18, 2019
1 parent 134fc3e commit 3b1b082
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/Cube.js-Backend/@cubejs-backend-server-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ CubejsServerCore.create({
});
```

### preAggregationSchema

Schema name to use for storing pre-aggregations.
Either `String` or `Function` could be passed.
Providing a `Function` allows to dynamically set the pre-aggregation schema name depending on the user's context.

```javascript
CubejsServerCore.create({
preAggregationSchema: ({ authInfo }) => `pre_aggregations_${authInfo.tenantId}`
});
```

It is usually used in [Multitenancy Setup](multitenancy-setup).

### telemetry

Cube.js collects high-level anonymous usage statistics for servers started in development mode. It doesn't track any credentials, schema contents or queries issued. This statistics is used solely for the purpose of constant cube.js improvement.
Expand Down
4 changes: 3 additions & 1 deletion packages/cubejs-server-core/core/CompilerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CompilerApi {
this.options = options || {};
this.allowNodeRequire = options.allowNodeRequire == null ? true : options.allowNodeRequire;
this.logger = this.options.logger;
this.preAggregationsSchema = this.options.preAggregationsSchema;
}

async getCompilers() {
Expand Down Expand Up @@ -37,7 +38,8 @@ class CompilerApi {
await this.getCompilers(),
this.dbType, {
...query,
externalDbType: this.options.externalDbType
externalDbType: this.options.externalDbType,
preAggregationsSchema: this.preAggregationsSchema
}
);
return (await this.getCompilers()).compiler.withQuery(sqlGenerator, () => ({
Expand Down
5 changes: 4 additions & 1 deletion packages/cubejs-server-core/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class CubejsServerCore {
this.contextToExternalDbType = typeof options.externalDbType === 'function' ?
options.externalDbType :
() => options.externalDbType;
this.preAggregationsSchema =
typeof options.preAggregationsSchema === 'function' ? options.preAggregationsSchema : () => options.preAggregationsSchema;
this.appIdToCompilerApi = {};
this.appIdToOrchestratorApi = {};
this.contextToAppId = options.contextToAppId || (() => process.env.CUBEJS_APP || 'STANDALONE');
Expand Down Expand Up @@ -207,7 +209,8 @@ class CubejsServerCore {
this.repositoryFactory(context), {
dbType: this.contextToDbType(context),
externalDbType: this.contextToExternalDbType(context),
schemaVersion: this.options.schemaVersion && (() => this.options.schemaVersion(context))
schemaVersion: this.options.schemaVersion && (() => this.options.schemaVersion(context)),
preAggregationsSchema: this.preAggregationsSchema(context)
}
);
}
Expand Down

0 comments on commit 3b1b082

Please sign in to comment.