Merge remote-tracking branch 'origin/api_tablewidgets' into dev
This commit is contained in:
commit
fca016cbb9
6 changed files with 57 additions and 32 deletions
|
|
@ -85,9 +85,10 @@ def create(project_id, user_id, data: schemas.CreateCustomMetricsSchema):
|
|||
data.series = None
|
||||
params = {"user_id": user_id, "project_id": project_id, **data.dict(), **_data}
|
||||
query = cur.mogrify(f"""\
|
||||
WITH m AS (INSERT INTO metrics (project_id, user_id, name, is_public, view_type, metric_type, metric_of, metric_value)
|
||||
WITH m AS (INSERT INTO metrics (project_id, user_id, name, is_public,
|
||||
view_type, metric_type, metric_of, metric_value, metric_format)
|
||||
VALUES (%(project_id)s, %(user_id)s, %(name)s, %(is_public)s,
|
||||
%(view_type)s, %(metric_type)s, %(metric_of)s, %(metric_value)s)
|
||||
%(view_type)s, %(metric_type)s, %(metric_of)s, %(metric_value)s, %(metric_format)s)
|
||||
RETURNING *)
|
||||
INSERT
|
||||
INTO metric_series(metric_id, index, name, filter)
|
||||
|
|
@ -113,7 +114,8 @@ def update(metric_id, user_id, project_id, data: schemas.UpdateCustomMetricsSche
|
|||
u_series_ids = []
|
||||
params = {"metric_id": metric_id, "is_public": data.is_public, "name": data.name,
|
||||
"user_id": user_id, "project_id": project_id, "view_type": data.view_type,
|
||||
"metric_type": data.metric_type, "metric_of": data.metric_of, "metric_value": data.metric_value}
|
||||
"metric_type": data.metric_type, "metric_of": data.metric_of,
|
||||
"metric_value": data.metric_value, "metric_format": data.metric_format}
|
||||
for i, s in enumerate(data.series):
|
||||
prefix = "u_"
|
||||
if s.series_id is None or s.series_id not in series_ids:
|
||||
|
|
@ -160,7 +162,8 @@ def update(metric_id, user_id, project_id, data: schemas.UpdateCustomMetricsSche
|
|||
UPDATE metrics
|
||||
SET name = %(name)s, is_public= %(is_public)s,
|
||||
view_type= %(view_type)s, metric_type= %(metric_type)s,
|
||||
metric_of= %(metric_of)s, metric_value= %(metric_value)s
|
||||
metric_of= %(metric_of)s, metric_value= %(metric_value)s,
|
||||
metric_format= %(metric_format)s
|
||||
WHERE metric_id = %(metric_id)s
|
||||
AND project_id = %(project_id)s
|
||||
AND (user_id = %(user_id)s OR is_public)
|
||||
|
|
|
|||
|
|
@ -775,8 +775,18 @@ class CreateCustomMetricsSchema(CustomMetricChartPayloadSchema):
|
|||
metric_type: MetricType = Field(MetricType.timeseries)
|
||||
metric_of: Union[TableMetricOfType, TimeseriesMetricOfType] = Field(TableMetricOfType.user_id)
|
||||
metric_value: List[IssueType] = Field([])
|
||||
metric_format: Optional[str] = Field(None)
|
||||
|
||||
# metricFraction: float = Field(None, gt=0, lt=1)
|
||||
# This is used to handle wrong values sent by the UI
|
||||
@root_validator(pre=True)
|
||||
def remove_metric_value(cls, values):
|
||||
if values.get("metric_type") == MetricType.timeseries \
|
||||
or values.get("metric_type") == MetricType.table \
|
||||
and values.get("metric_of") != TableMetricOfType.issues:
|
||||
values["metric_of"] = []
|
||||
return values
|
||||
|
||||
@root_validator
|
||||
def validator(cls, values):
|
||||
if values.get("metric_type") == MetricType.table:
|
||||
|
|
|
|||
|
|
@ -41,10 +41,14 @@ LANGUAGE plpgsql;
|
|||
|
||||
ALTER TABLE metrics
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount';
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount',
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_value text[] NOT NULL DEFAULT '{}'::text[],
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_format text;
|
||||
|
||||
COMMIT;
|
||||
|
|
@ -774,17 +774,19 @@ $$
|
|||
CREATE TYPE metric_view_type AS ENUM ('lineChart','progress','table','pieChart');
|
||||
CREATE TABLE IF NOT EXISTS metrics
|
||||
(
|
||||
metric_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
|
||||
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,
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount'
|
||||
metric_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
|
||||
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,
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount',
|
||||
metric_value text[] NOT NULL DEFAULT '{}'::text[],
|
||||
metric_format text
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS metrics_user_id_is_public_idx ON public.metrics (user_id, is_public);
|
||||
CREATE TABLE IF NOT EXISTS metric_series
|
||||
|
|
|
|||
|
|
@ -40,10 +40,14 @@ LANGUAGE plpgsql;
|
|||
|
||||
ALTER TABLE metrics
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount';
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount',
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_value text[] NOT NULL DEFAULT '{}'::text[],
|
||||
ADD COLUMN IF NOT EXISTS
|
||||
metric_format text;
|
||||
|
||||
COMMIT;
|
||||
|
|
@ -904,17 +904,19 @@ $$
|
|||
CREATE TYPE metric_view_type AS ENUM ('lineChart','progress','table','pieChart');
|
||||
CREATE TABLE metrics
|
||||
(
|
||||
metric_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
|
||||
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,
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount'
|
||||
metric_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
|
||||
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,
|
||||
metric_type metric_type NOT NULL DEFAULT 'timeseries',
|
||||
view_type metric_view_type NOT NULL DEFAULT 'lineChart',
|
||||
metric_of text NOT NULL DEFAULT 'sessionCount',
|
||||
metric_value text[] NOT NULL DEFAULT '{}'::text[],
|
||||
metric_format text
|
||||
);
|
||||
CREATE INDEX metrics_user_id_is_public_idx ON public.metrics (user_id, is_public);
|
||||
CREATE TABLE metric_series
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue