mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat(analytics): add Projection type and use typed projections in models and table creation
This commit is contained in:
@@ -3,6 +3,7 @@ import Route from "../../../Types/API/Route";
|
||||
import AnalyticsTableEngine from "../../../Types/AnalyticsDatabase/AnalyticsTableEngine";
|
||||
import AnalyticsTableColumn from "../../../Types/AnalyticsDatabase/TableColumn";
|
||||
import TableColumnType from "../../../Types/AnalyticsDatabase/TableColumnType";
|
||||
import Projection from "../../../Types/AnalyticsDatabase/Projection";
|
||||
import {
|
||||
ColumnAccessControl,
|
||||
TableAccessControl,
|
||||
@@ -40,7 +41,7 @@ export default class AnalyticsBaseModel extends CommonModel {
|
||||
enableWorkflowOn?: EnableWorkflowOn | undefined;
|
||||
enableRealtimeEventsOn?: EnableRealtimeEventsOn | undefined;
|
||||
partitionKey: string;
|
||||
projections: Array<string> | undefined;
|
||||
projections?: Array<Projection> | undefined;
|
||||
}) {
|
||||
super({
|
||||
tableColumns: data.tableColumns,
|
||||
@@ -252,11 +253,11 @@ export default class AnalyticsBaseModel extends CommonModel {
|
||||
this._crudApiPath = v;
|
||||
}
|
||||
|
||||
private _projections: Array<string> = [];
|
||||
public get projections(): Array<string> {
|
||||
private _projections: Array<Projection> = [];
|
||||
public get projections(): Array<Projection> {
|
||||
return this._projections;
|
||||
}
|
||||
public set projections(v: Array<string>) {
|
||||
public set projections(v: Array<Projection>) {
|
||||
this._projections = v;
|
||||
}
|
||||
|
||||
|
||||
4
Common/Types/AnalyticsDatabase/Projection.ts
Normal file
4
Common/Types/AnalyticsDatabase/Projection.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export default interface Projection {
|
||||
name: string;
|
||||
query: string;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AnalyticsServices } from "Common/Server/Services/Index";
|
||||
import Projection from "Common/Types/AnalyticsDatabase/Projection";
|
||||
|
||||
export default class AnalyticsTableManagement {
|
||||
public static async createTables(): Promise<void> {
|
||||
@@ -8,14 +9,14 @@ export default class AnalyticsTableManagement {
|
||||
service.statementGenerator.toTableCreateStatement(),
|
||||
);
|
||||
|
||||
const projections: Array<string> = service.model.projections;
|
||||
const projections: Array<Projection> = service.model.projections;
|
||||
|
||||
for (const projection of projections) {
|
||||
if (!projection || projection.trim().length === 0) {
|
||||
if (!projection.query || projection.query.trim().length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await service.execute(projection);
|
||||
await service.execute(projection.query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user