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.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
add logic to mysql migration
Brian Caoe269ace88f33
diff --git a/db/mysql/migrations/02_add_event_data/migration.sql b/db/mysql/migrations/02_add_event_data/migration.sqlindex c210895d3..b781984cd 100644--- a/db/mysql/migrations/02_add_event_data/migration.sql+++ b/db/mysql/migrations/02_add_event_data/migration.sql@@ -49,14 +49,42 @@ CREATE TABLE `event_data` (-- AddForeignKeyALTER 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`;+-- CreateProcedureRenameIndex+CREATE PROCEDURE `UmamiRenameIndexIfExists`(+ IN i_table_name VARCHAR(128),+ IN i_current_index_name VARCHAR(128),+ IN i_new_index_name VARCHAR(128)+ )+ BEGIN--- RenameIndex-ALTER TABLE `session` RENAME INDEX `session_uuid` TO `session_session_uuid_key`;+ SET @tableName = i_table_name;+ SET @currentIndexName = i_current_index_name;+ SET @newIndexName = i_new_index_name;+ SET @indexExists = 0;--- RenameIndex-ALTER TABLE `website` RENAME INDEX `share_id` TO `website_share_id_key`;+ SELECT+ 1+ INTO @indexExists FROM+ INFORMATION_SCHEMA.STATISTICS+ WHERE+ TABLE_NAME = @tableName+ AND INDEX_NAME = @currentIndexName;++ SET @query = CONCAT(+ 'ALTER TABLE `', @tableName, '` RENAME INDEX `', @currentIndexName, '` TO `', @newIndexName, '`;'+ );+ IF @indexExists THEN+ PREPARE stmt FROM @query;+ EXECUTE stmt;+ DEALLOCATE PREPARE stmt;+ END IF;+END;-- RenameIndex-ALTER TABLE `website` RENAME INDEX `website_uuid` TO `website_website_uuid_key`;\ No newline at end of file+CALL UmamiRenameIndexIfExists('account', 'username', 'account_username_key');+CALL UmamiRenameIndexIfExists('session', 'session_uuid', 'session_session_uuid_key');+CALL UmamiRenameIndexIfExists('website', 'share_id', 'website_share_id_key');+CALL UmamiRenameIndexIfExists('website', 'website_uuid', 'website_website_uuid_key');++-- Drop CreateProcedureRenameIndex+drop procedure `UmamiRenameIndexIfExists`;\ No newline at end of file