mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Merge pull request #2108 from umami-software/feat/um-366-event-data-migration
Feat/um 366 event data migration
This commit is contained in:
commit
1b0cef08cf
@ -33,6 +33,7 @@ export function TestConsole() {
|
|||||||
booleanError: 'true',
|
booleanError: 'true',
|
||||||
time: new Date(),
|
time: new Date(),
|
||||||
number: 1,
|
number: 1,
|
||||||
|
number2: Math.random() * 100,
|
||||||
time2: new Date().toISOString(),
|
time2: new Date().toISOString(),
|
||||||
nested: {
|
nested: {
|
||||||
test: 'test-data',
|
test: 'test-data',
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
-- CreateTable
|
|
||||||
CREATE TABLE `report` (
|
|
||||||
`report_id` VARCHAR(36) NOT NULL,
|
|
||||||
`user_id` VARCHAR(36) NOT NULL,
|
|
||||||
`website_id` VARCHAR(36) NOT NULL,
|
|
||||||
`type` VARCHAR(200) NOT NULL,
|
|
||||||
`name` VARCHAR(200) NOT NULL,
|
|
||||||
`description` VARCHAR(500) NOT NULL,
|
|
||||||
`parameters` VARCHAR(6000) NOT NULL,
|
|
||||||
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
|
||||||
`updated_at` TIMESTAMP(0) NULL,
|
|
||||||
|
|
||||||
UNIQUE INDEX `report_report_id_key`(`report_id`),
|
|
||||||
INDEX `report_user_id_idx`(`user_id`),
|
|
||||||
INDEX `report_website_id_idx`(`website_id`),
|
|
||||||
INDEX `report_type_idx`(`type`),
|
|
||||||
INDEX `report_name_idx`(`name`),
|
|
||||||
PRIMARY KEY (`report_id`)
|
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
@ -1,16 +1,3 @@
|
|||||||
/*
|
|
||||||
Warnings:
|
|
||||||
|
|
||||||
- The primary key for the `event_data` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
|
||||||
- You are about to drop the column `event_data_type` on the `event_data` table. All the data in the column will be lost.
|
|
||||||
- You are about to drop the column `event_date_value` on the `event_data` table. All the data in the column will be lost.
|
|
||||||
- You are about to drop the column `event_id` on the `event_data` table. All the data in the column will be lost.
|
|
||||||
- You are about to drop the column `event_numeric_value` on the `event_data` table. All the data in the column will be lost.
|
|
||||||
- You are about to drop the column `event_string_value` on the `event_data` table. All the data in the column will be lost.
|
|
||||||
- Added the required column `data_type` to the `event_data` table without a default value. This is not possible if the table is not empty.
|
|
||||||
- Added the required column `event_data_id` to the `event_data` table without a default value. This is not possible if the table is not empty.
|
|
||||||
|
|
||||||
*/
|
|
||||||
-- AlterTable
|
-- AlterTable
|
||||||
ALTER TABLE `event_data` RENAME COLUMN `event_data_type` TO `data_type`;
|
ALTER TABLE `event_data` RENAME COLUMN `event_data_type` TO `data_type`;
|
||||||
ALTER TABLE `event_data` RENAME COLUMN `event_date_value` TO `date_value`;
|
ALTER TABLE `event_data` RENAME COLUMN `event_date_value` TO `date_value`;
|
||||||
@ -35,3 +22,32 @@ CREATE TABLE `session_data` (
|
|||||||
INDEX `session_data_session_id_idx`(`session_id`),
|
INDEX `session_data_session_id_idx`(`session_id`),
|
||||||
PRIMARY KEY (`session_data_id`)
|
PRIMARY KEY (`session_data_id`)
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `report` (
|
||||||
|
`report_id` VARCHAR(36) NOT NULL,
|
||||||
|
`user_id` VARCHAR(36) NOT NULL,
|
||||||
|
`website_id` VARCHAR(36) NOT NULL,
|
||||||
|
`type` VARCHAR(200) NOT NULL,
|
||||||
|
`name` VARCHAR(200) NOT NULL,
|
||||||
|
`description` VARCHAR(500) NOT NULL,
|
||||||
|
`parameters` VARCHAR(6000) NOT NULL,
|
||||||
|
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||||
|
`updated_at` TIMESTAMP(0) NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `report_report_id_key`(`report_id`),
|
||||||
|
INDEX `report_user_id_idx`(`user_id`),
|
||||||
|
INDEX `report_website_id_idx`(`website_id`),
|
||||||
|
INDEX `report_type_idx`(`type`),
|
||||||
|
INDEX `report_name_idx`(`name`),
|
||||||
|
PRIMARY KEY (`report_id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- EventData migration
|
||||||
|
UPDATE event_data
|
||||||
|
SET string_value = number_value
|
||||||
|
WHERE data_type = 2;
|
||||||
|
|
||||||
|
UPDATE event_data
|
||||||
|
SET string_value = CONCAT(REPLACE(DATE_FORMAT(date_value, '%Y-%m-%d %T'), ' ', 'T'), 'Z')
|
||||||
|
WHERE data_type = 4;
|
@ -1,29 +0,0 @@
|
|||||||
-- CreateTable
|
|
||||||
CREATE TABLE "report" (
|
|
||||||
"report_id" UUID NOT NULL,
|
|
||||||
"user_id" UUID NOT NULL,
|
|
||||||
"website_id" UUID NOT NULL,
|
|
||||||
"type" VARCHAR(200) NOT NULL,
|
|
||||||
"name" VARCHAR(200) NOT NULL,
|
|
||||||
"description" VARCHAR(500) NOT NULL,
|
|
||||||
"parameters" VARCHAR(6000) NOT NULL,
|
|
||||||
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
"updated_at" TIMESTAMPTZ(6),
|
|
||||||
|
|
||||||
CONSTRAINT "report_pkey" PRIMARY KEY ("report_id")
|
|
||||||
);
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE UNIQUE INDEX "report_report_id_key" ON "report"("report_id");
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE INDEX "report_user_id_idx" ON "report"("user_id");
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE INDEX "report_website_id_idx" ON "report"("website_id");
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE INDEX "report_type_idx" ON "report"("type");
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE INDEX "report_name_idx" ON "report"("name");
|
|
@ -21,6 +21,21 @@ CREATE TABLE "session_data" (
|
|||||||
CONSTRAINT "session_data_pkey" PRIMARY KEY ("session_data_id")
|
CONSTRAINT "session_data_pkey" PRIMARY KEY ("session_data_id")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "report" (
|
||||||
|
"report_id" UUID NOT NULL,
|
||||||
|
"user_id" UUID NOT NULL,
|
||||||
|
"website_id" UUID NOT NULL,
|
||||||
|
"type" VARCHAR(200) NOT NULL,
|
||||||
|
"name" VARCHAR(200) NOT NULL,
|
||||||
|
"description" VARCHAR(500) NOT NULL,
|
||||||
|
"parameters" VARCHAR(6000) NOT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMPTZ(6),
|
||||||
|
|
||||||
|
CONSTRAINT "report_pkey" PRIMARY KEY ("report_id")
|
||||||
|
);
|
||||||
|
|
||||||
-- CreateIndex
|
-- CreateIndex
|
||||||
CREATE INDEX "session_data_created_at_idx" ON "session_data"("created_at");
|
CREATE INDEX "session_data_created_at_idx" ON "session_data"("created_at");
|
||||||
|
|
||||||
@ -29,3 +44,27 @@ CREATE INDEX "session_data_website_id_idx" ON "session_data"("website_id");
|
|||||||
|
|
||||||
-- CreateIndex
|
-- CreateIndex
|
||||||
CREATE INDEX "session_data_session_id_idx" ON "session_data"("session_id");
|
CREATE INDEX "session_data_session_id_idx" ON "session_data"("session_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "report_report_id_key" ON "report"("report_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "report_user_id_idx" ON "report"("user_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "report_website_id_idx" ON "report"("website_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "report_type_idx" ON "report"("type");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "report_name_idx" ON "report"("name");
|
||||||
|
|
||||||
|
-- EventData migration
|
||||||
|
UPDATE "event_data"
|
||||||
|
SET string_value = number_value
|
||||||
|
WHERE data_type = 2;
|
||||||
|
|
||||||
|
UPDATE "event_data"
|
||||||
|
SET string_value = CONCAT(REPLACE(TO_CHAR(date_value, 'YYYY-MM-DD HH24:MI:SS'), ' ', 'T'), 'Z')
|
||||||
|
WHERE data_type = 4;
|
@ -37,8 +37,13 @@ async function relationalQuery(data: {
|
|||||||
websiteEventId: eventId,
|
websiteEventId: eventId,
|
||||||
websiteId,
|
websiteId,
|
||||||
eventKey: a.key,
|
eventKey: a.key,
|
||||||
stringValue: a.value.toString(),
|
stringValue:
|
||||||
numericValue: a.dynamicDataType === DATA_TYPE.number ? a.value : null,
|
a.dynamicDataType === DATA_TYPE.number
|
||||||
|
? parseFloat(a.value).toFixed(4)
|
||||||
|
: a.dynamicDataType === DATA_TYPE.date
|
||||||
|
? a.value.split('.')[0] + 'Z'
|
||||||
|
: a.value.toString(),
|
||||||
|
numberValue: a.dynamicDataType === DATA_TYPE.number ? a.value : null,
|
||||||
dateValue: a.dynamicDataType === DATA_TYPE.date ? new Date(a.value) : null,
|
dateValue: a.dynamicDataType === DATA_TYPE.date ? new Date(a.value) : null,
|
||||||
dataType: a.dynamicDataType,
|
dataType: a.dynamicDataType,
|
||||||
}));
|
}));
|
||||||
|
@ -20,12 +20,12 @@ export async function saveSessionData(data: {
|
|||||||
sessionId,
|
sessionId,
|
||||||
key: a.key,
|
key: a.key,
|
||||||
stringValue:
|
stringValue:
|
||||||
a.dynamicDataType === DATA_TYPE.string ||
|
a.dynamicDataType === DATA_TYPE.number
|
||||||
a.dynamicDataType === DATA_TYPE.boolean ||
|
? parseFloat(a.value).toFixed(4)
|
||||||
a.dynamicDataType === DATA_TYPE.array
|
: a.dynamicDataType === DATA_TYPE.date
|
||||||
? a.value
|
? a.value.split('.')[0] + 'Z'
|
||||||
: null,
|
: a.value.toString(),
|
||||||
numericValue: a.dynamicDataType === DATA_TYPE.number ? a.value : null,
|
numberValue: a.dynamicDataType === DATA_TYPE.number ? a.value : null,
|
||||||
dateValue: a.dynamicDataType === DATA_TYPE.date ? new Date(a.value) : null,
|
dateValue: a.dynamicDataType === DATA_TYPE.date ? new Date(a.value) : null,
|
||||||
dataType: a.dynamicDataType,
|
dataType: a.dynamicDataType,
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user