Skip to content

Commit

Permalink
Merge pull request umami-software#1417 from umami-software/dev
Browse files Browse the repository at this point in the history
Script for fixing DB schema inconsistencies
  • Loading branch information
mikecao authored Aug 11, 2022
2 parents 2181ca4 + 3414cb6 commit 8f0e84f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
42 changes: 35 additions & 7 deletions db/mysql/migrations/02_add_event_data/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

-- 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`;
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`;
8 changes: 4 additions & 4 deletions db/postgresql/migrations/02_add_event_data/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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";
4 changes: 2 additions & 2 deletions lang/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"message.confirm-reset": "Sind Sie sicher, dass Sie die Statistiken von {target} zurücksetzen wollen?",
"message.copied": "In Zwischenablage kopiert!",
"message.delete-warning": "Alle zugehörigen Daten werden ebenfalls gelöscht.",
"message.edit-dashboard": "Edit dashboard",
"message.edit-dashboard": "Dashboard bearbeiten",
"message.failure": "Es ist ein Fehler aufgetreten.",
"message.get-share-url": "Freigabe-URL abrufen",
"message.get-tracking-code": "Erstelle Tracking Kennung",
Expand Down Expand Up @@ -103,7 +103,7 @@
"metrics.operating-systems": "Betriebssysteme",
"metrics.page-views": "Seitenaufrufe",
"metrics.pages": "Seiten",
"metrics.query-parameters": "Query parameters",
"metrics.query-parameters": "Abfrageparameter",
"metrics.referrers": "Referrer",
"metrics.screens": "Bildschirmauflösungen",
"metrics.unique-visitors": "Eindeutige Besucher",
Expand Down
2 changes: 1 addition & 1 deletion lang/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"message.confirm-reset": "Êtes-vous sûr de vouloir réinistialiser les statistiques de {target} ?",
"message.copied": "Copié !",
"message.delete-warning": "Toutes les données associées seront également supprimées.",
"message.edit-dashboard": "Edit dashboard",
"message.edit-dashboard": "Modifier l'ordre des sites",
"message.failure": "Un problème est survenu.",
"message.get-share-url": "Obtenir l'URL de partage",
"message.get-tracking-code": "Obtenir le code de suivi",
Expand Down

0 comments on commit 8f0e84f

Please sign in to comment.