Merge remote-tracking branch 'origin/dev' into dev
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run

This commit is contained in:
Mike Cao 2025-09-10 17:16:15 -07:00
commit 366c52d703
5 changed files with 52 additions and 6 deletions

View file

@ -71,3 +71,49 @@ CREATE INDEX "pixel_team_id_idx" ON "pixel"("team_id");
-- CreateIndex
CREATE INDEX "pixel_created_at_idx" ON "pixel"("created_at");
-- DataMigration Funnel
DELETE FROM "report" WHERE type = 'funnel' and jsonb_array_length(parameters->'steps') = 1;
UPDATE "report" SET parameters = parameters - 'websiteId' - 'dateRange' - 'urls' WHERE type = 'funnel';
UPDATE "report"
SET parameters = jsonb_set(
parameters,
'{steps}',
(
SELECT jsonb_agg(
CASE
WHEN step->>'type' = 'url'
THEN jsonb_set(step, '{type}', '"path"')
ELSE step
END
)
FROM jsonb_array_elements(parameters->'steps') step
)
)
WHERE type = 'funnel'
and parameters @> '{"steps":[{"type":"url"}]}';
-- DataMigration Goals
UPDATE "report" SET type = 'goal' WHERE type = 'goals';
INSERT INTO "report" (report_id, user_id, website_id, type, name, description, parameters, created_at, updated_at)
SELECT gen_random_uuid(),
user_id,
website_id,
'goal',
concat(name, ' - ', elem ->> 'value'),
description,
jsonb_build_object(
'type', CASE WHEN elem ->> 'type' = 'url' THEN 'path'
ELSE elem ->> 'type' END,
'value', elem ->> 'value'
) AS parameters,
created_at,
updated_at
FROM "report"
CROSS JOIN LATERAL jsonb_array_elements(parameters -> 'goals') elem
WHERE type = 'goal'
and elem ->> 'type' IN ('event', 'url');
DELETE FROM "report" WHERE type = 'goal' and parameters ? 'goals';