Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

create mysql migration

Brian Cao3e2c098c05c6
diff --git a/db/mysql/migrations/02_add_event_data/migration.sql b/db/mysql/migrations/02_add_event_data/migration.sql
new file mode 100644
index 000000000..80ff8e269
--- /dev/null
+++ b/db/mysql/migrations/02_add_event_data/migration.sql
@@ -0,0 +1,49 @@
+-- AlterTable
+ALTER TABLE `event` ADD COLUMN `event_name` VARCHAR(50) NULL;
+
+-- CreateTable
+CREATE TABLE `event_data` (
+ `event_data_id` INTEGER NOT NULL AUTO_INCREMENT,
+ `event_id` INTEGER UNSIGNED NOT NULL,
+ `event_data` JSON NOT NULL,
+
+ UNIQUE INDEX `event_data_event_id_key`(`event_id`),
+ PRIMARY KEY (`event_data_id`)
+) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+
+-- AddForeignKey
+ALTER TABLE `event_data` ADD CONSTRAINT `event_data_event_id_fkey` FOREIGN KEY (`event_id`) REFERENCES `event`(`event_id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- RenameIndex
+ALTER TABLE `account` RENAME INDEX `username` TO `account_username_key`;
+
+-- RenameIndex
+ALTER TABLE `session` RENAME INDEX `session_uuid` TO `session_session_uuid_key`;
+
+-- RenameIndex
+ALTER TABLE `website` RENAME INDEX `share_id` TO `website_share_id_key`;
+
+-- RenameIndex
+ALTER TABLE `website` RENAME INDEX `website_uuid` TO `website_website_uuid_key`;
+
+
+/*
+ Warnings:
+
+ - You are about to drop the column `event_type` on the `event` table. All the data in the column will be lost.
+ - You are about to drop the column `event_value` on the `event` table. All the data in the column will be lost.
+
+*/
+-- Populate event_name
+update `event`
+set event_name = concat(event_value, "-", event_type)
+where 1 = 1;
+
+-- Set event_name not null
+ALTER TABLE `event`
+MODIFY `event_name` VARCHAR(50) NOT NULL;
+
+-- Drop old columns
+ALTER TABLE `event`
+DROP COLUMN `event_type`,
+DROP COLUMN `event_value`;
\ No newline at end of file
diff --git a/db/postgresql/migrations/02_add_event_data/migration.sql b/db/postgresql/migrations/02_add_event_data/migration.sql
index c4d9862d2..703bca38d 100644
--- a/db/postgresql/migrations/02_add_event_data/migration.sql
+++ b/db/postgresql/migrations/02_add_event_data/migration.sql
@@ -39,7 +39,7 @@ ALTER INDEX "website.website_uuid_unique" RENAME TO "website_website_uuid_key";
update event
set "event_name" = event.event_value || '-' || event.event_type;
---Set event_name not null
+-- Set event_name not null
ALTER TABLE "event" ALTER COLUMN "event_name" SET NOT NULL;
-- Drop old columns