feat(api): custom metrics status
feat(db): custom metrics active column
This commit is contained in:
parent
62e4ea3af7
commit
3bf9ff2232
7 changed files with 35 additions and 0 deletions
|
|
@ -267,3 +267,16 @@ def get_series_for_alert(project_id, user_id):
|
|||
)
|
||||
rows = cur.fetchall()
|
||||
return helper.list_to_camel_case(rows)
|
||||
|
||||
|
||||
def change_state(project_id, metric_id, user_id, status):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(
|
||||
cur.mogrify("""\
|
||||
UPDATE public.metrics
|
||||
SET active = %(status)s
|
||||
WHERE metric_id = %(metric_id)s
|
||||
AND (user_id = %(user_id)s OR is_public);""",
|
||||
{"metric_id": metric_id, "status": status, "user_id": user_id})
|
||||
)
|
||||
return get(metric_id=metric_id, project_id=project_id, user_id=user_id)
|
||||
|
|
|
|||
|
|
@ -1140,6 +1140,16 @@ def update_custom_metric(projectId: int, metric_id: int, data: schemas.UpdateCus
|
|||
"data": custom_metrics.update(project_id=projectId, user_id=context.user_id, metric_id=metric_id, data=data)}
|
||||
|
||||
|
||||
@app.post('/{projectId}/custom_metrics/{metric_id}/status', tags=["customMetrics"])
|
||||
@app.put('/{projectId}/custom_metrics/{metric_id}/status', tags=["customMetrics"])
|
||||
def update_custom_metric_state(projectId: int, metric_id: int,
|
||||
data: schemas.UpdateCustomMetricsStatusSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {
|
||||
"data": custom_metrics.change_state(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
|
||||
status=data.active)}
|
||||
|
||||
|
||||
@app.delete('/{projectId}/custom_metrics/{metric_id}', tags=["customMetrics"])
|
||||
def delete_custom_metric(projectId: int, metric_id: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": custom_metrics.delete(project_id=projectId, user_id=context.user_id, metric_id=metric_id)}
|
||||
|
|
|
|||
|
|
@ -721,5 +721,9 @@ class UpdateCustomMetricsSchema(CreateCustomMetricsSchema):
|
|||
series: List[CustomMetricUpdateSeriesSchema] = Field(..., min_items=1)
|
||||
|
||||
|
||||
class UpdateCustomMetricsStatusSchema(BaseModel):
|
||||
active: bool = Field(...)
|
||||
|
||||
|
||||
class SavedSearchSchema(FunnelSchema):
|
||||
filter: FlatSessionsSearchPayloadSchema = Field([])
|
||||
|
|
|
|||
|
|
@ -6,4 +6,7 @@ SELECT 'v1.5.0-ee'
|
|||
$$ LANGUAGE sql IMMUTABLE;
|
||||
|
||||
ALTER TYPE public.error_source ADD VALUE IF NOT EXISTS 'elasticsearch';
|
||||
|
||||
ALTER TABLE public.metrics
|
||||
ADD COLUMN IF NOT EXISTS active boolean NOT NULL DEFAULT TRUE;
|
||||
COMMIT;
|
||||
|
|
@ -777,6 +777,7 @@ $$
|
|||
user_id integer REFERENCES users (user_id) ON DELETE SET NULL,
|
||||
name text NOT NULL,
|
||||
is_public boolean NOT NULL DEFAULT FALSE,
|
||||
active boolean NOT NULL DEFAULT TRUE,
|
||||
created_at timestamp default timezone('utc'::text, now()) not null,
|
||||
deleted_at timestamp
|
||||
);
|
||||
|
|
|
|||
|
|
@ -6,4 +6,7 @@ SELECT 'v1.5.0'
|
|||
$$ LANGUAGE sql IMMUTABLE;
|
||||
|
||||
ALTER TYPE public.error_source ADD VALUE IF NOT EXISTS 'elasticsearch';
|
||||
|
||||
ALTER TABLE public.metrics
|
||||
ADD COLUMN IF NOT EXISTS active boolean NOT NULL DEFAULT TRUE;
|
||||
COMMIT;
|
||||
|
|
@ -907,6 +907,7 @@ $$
|
|||
user_id integer REFERENCES users (user_id) ON DELETE SET NULL,
|
||||
name text NOT NULL,
|
||||
is_public boolean NOT NULL DEFAULT FALSE,
|
||||
active boolean NOT NULL DEFAULT TRUE,
|
||||
created_at timestamp default timezone('utc'::text, now()) not null,
|
||||
deleted_at timestamp
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue