mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 09:45:04 +01:00
create mysql migration
This commit is contained in:
parent
6fbd566b29
commit
3e2c098c05
49
db/mysql/migrations/02_add_event_data/migration.sql
Normal file
49
db/mysql/migrations/02_add_event_data/migration.sql
Normal file
@ -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`;
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user