mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Merge pull request #1415 from umami-software/brian/um-31-migration-bug
align index names if error
This commit is contained in:
commit
3414cb6a87
@ -49,14 +49,42 @@ CREATE TABLE `event_data` (
|
||||
-- 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`;
|
||||
-- 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
|
||||
|
||||
SET @tableName = i_table_name;
|
||||
SET @currentIndexName = i_current_index_name;
|
||||
SET @newIndexName = i_new_index_name;
|
||||
SET @indexExists = 0;
|
||||
|
||||
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 `session` RENAME INDEX `session_uuid` TO `session_session_uuid_key`;
|
||||
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');
|
||||
|
||||
-- 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`;
|
||||
-- Drop CreateProcedureRenameIndex
|
||||
drop procedure `UmamiRenameIndexIfExists`;
|
@ -54,13 +54,13 @@ CREATE UNIQUE INDEX "event_data_event_id_key" ON "event_data"("event_id");
|
||||
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 INDEX "account.username_unique" RENAME TO "account_username_key";
|
||||
ALTER INDEX IF EXISTS "account.username_unique" RENAME TO "account_username_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "session.session_uuid_unique" RENAME TO "session_session_uuid_key";
|
||||
ALTER INDEX IF EXISTS "session.session_uuid_unique" RENAME TO "session_session_uuid_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "website.share_id_unique" RENAME TO "website_share_id_key";
|
||||
ALTER INDEX IF EXISTS "website.share_id_unique" RENAME TO "website_share_id_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "website.website_uuid_unique" RENAME TO "website_website_uuid_key";
|
||||
ALTER INDEX IF EXISTS "website.website_uuid_unique" RENAME TO "website_website_uuid_key";
|
Loading…
Reference in New Issue
Block a user