Skip to content

Commit d69ad34

Browse files
committed
Update migration.sql
1 parent 81e27fc commit d69ad34

File tree

1 file changed

+0
-70
lines changed

1 file changed

+0
-70
lines changed
Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
-- AlterTable
2-
ALTER TABLE "report" ALTER COLUMN "type" SET DATA TYPE VARCHAR(50);
3-
4-
-- AlterTable
5-
ALTER TABLE "revenue" ALTER COLUMN "currency" SET DATA TYPE VARCHAR(10);
6-
7-
-- AlterTable
8-
ALTER TABLE "segment" ALTER COLUMN "type" SET DATA TYPE VARCHAR(50);
9-
10-
-- CreateTable
11-
CREATE TABLE "link" (
12-
"link_id" UUID NOT NULL,
13-
"name" VARCHAR(100) NOT NULL,
14-
"url" VARCHAR(500) NOT NULL,
15-
"slug" VARCHAR(100) NOT NULL,
16-
"user_id" UUID,
17-
"team_id" UUID,
18-
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
19-
"updated_at" TIMESTAMPTZ(6),
20-
"deleted_at" TIMESTAMPTZ(6),
21-
22-
CONSTRAINT "link_pkey" PRIMARY KEY ("link_id")
23-
);
24-
251
-- CreateTable
262
CREATE TABLE "pixel" (
273
"pixel_id" UUID NOT NULL,
@@ -71,49 +47,3 @@ CREATE INDEX "pixel_team_id_idx" ON "pixel"("team_id");
7147

7248
-- CreateIndex
7349
CREATE INDEX "pixel_created_at_idx" ON "pixel"("created_at");
74-
75-
-- DataMigration Funnel
76-
DELETE FROM "report" WHERE type = 'funnel' and jsonb_array_length(parameters->'steps') = 1;
77-
UPDATE "report" SET parameters = parameters - 'websiteId' - 'dateRange' - 'urls' WHERE type = 'funnel';
78-
79-
UPDATE "report"
80-
SET parameters = jsonb_set(
81-
parameters,
82-
'{steps}',
83-
(
84-
SELECT jsonb_agg(
85-
CASE
86-
WHEN step->>'type' = 'url'
87-
THEN jsonb_set(step, '{type}', '"path"')
88-
ELSE step
89-
END
90-
)
91-
FROM jsonb_array_elements(parameters->'steps') step
92-
)
93-
)
94-
WHERE type = 'funnel'
95-
and parameters @> '{"steps":[{"type":"url"}]}';
96-
97-
-- DataMigration Goals
98-
UPDATE "report" SET type = 'goal' WHERE type = 'goals';
99-
100-
INSERT INTO "report" (report_id, user_id, website_id, type, name, description, parameters, created_at, updated_at)
101-
SELECT gen_random_uuid(),
102-
user_id,
103-
website_id,
104-
'goal',
105-
concat(name, ' - ', elem ->> 'value'),
106-
description,
107-
jsonb_build_object(
108-
'type', CASE WHEN elem ->> 'type' = 'url' THEN 'path'
109-
ELSE elem ->> 'type' END,
110-
'value', elem ->> 'value'
111-
) AS parameters,
112-
created_at,
113-
updated_at
114-
FROM "report"
115-
CROSS JOIN LATERAL jsonb_array_elements(parameters -> 'goals') elem
116-
WHERE type = 'goal'
117-
and elem ->> 'type' IN ('event', 'url');
118-
119-
DELETE FROM "report" WHERE type = 'goal' and parameters ? 'goals';

0 commit comments

Comments
 (0)