diff --git a/db/mysql/migrations/04_account_uuid/migration.sql b/db/mysql/migrations/04_account_uuid/migration.sql deleted file mode 100644 index 7b7b5dea..00000000 --- a/db/mysql/migrations/04_account_uuid/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ --- AlterTable -ALTER TABLE `account` ADD COLUMN `account_uuid` VARCHAR(36); - --- Backfill UUID -UPDATE `account` SET account_uuid=(SELECT uuid()); - --- AlterTable -ALTER TABLE `account` MODIFY `account_uuid` VARCHAR(36) NOT NULL; - --- CreateIndex -CREATE UNIQUE INDEX `account_account_uuid_key` ON `account`(`account_uuid`); diff --git a/db/mysql/migrations/04_add_uuid/migration.sql b/db/mysql/migrations/04_add_uuid/migration.sql new file mode 100644 index 00000000..137ee2e3 --- /dev/null +++ b/db/mysql/migrations/04_add_uuid/migration.sql @@ -0,0 +1,35 @@ +-- AlterTable +ALTER TABLE `account` ADD COLUMN `account_uuid` VARCHAR(36); + +-- Backfill UUID +UPDATE `account` SET account_uuid=(SELECT uuid()); + +-- AlterTable +ALTER TABLE `account` MODIFY `account_uuid` VARCHAR(36) NOT NULL; + +-- CreateIndex +CREATE UNIQUE INDEX `account_account_uuid_key` ON `account`(`account_uuid`); + +-- AlterTable +ALTER TABLE `event` ADD COLUMN `event_uuid` VARCHAR(36); + +-- Backfill UUID +UPDATE `event` SET event_uuid=(SELECT uuid()); + +-- AlterTable +ALTER TABLE `event` MODIFY `event_uuid` VARCHAR(36) NOT NULL; + +-- CreateIndex +CREATE UNIQUE INDEX `event_event_uuid_key` ON `event`(`event_uuid`); + +-- CreateIndex +CREATE INDEX `account_account_uuid_idx` ON `account`(`account_uuid`); + +-- CreateIndex +CREATE INDEX `session_session_uuid_idx` ON `session`(`session_uuid`); + +-- CreateIndex +CREATE INDEX `website_website_uuid_idx` ON `website`(`website_uuid`); + +-- CreateIndex +CREATE INDEX `event_event_uuid_idx` ON `event`(`event_uuid`); \ No newline at end of file diff --git a/db/mysql/schema.prisma b/db/mysql/schema.prisma index 6c740bfb..bdfafd43 100644 --- a/db/mysql/schema.prisma +++ b/db/mysql/schema.prisma @@ -16,6 +16,8 @@ model account { updatedAt DateTime? @default(now()) @map("updated_at") @db.Timestamp(0) accountUuid String @unique() @map("account_uuid") @db.VarChar(36) website website[] + + @@index([accountUuid]) } model event { @@ -25,6 +27,7 @@ model event { createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0) url String @db.VarChar(500) eventName String @map("event_name") @db.VarChar(50) + eventUuid String @unique() @map("event_uuid") @db.VarChar(36) session session @relation(fields: [sessionId], references: [id]) website website @relation(fields: [websiteId], references: [id]) eventData eventData? @@ -32,6 +35,7 @@ model event { @@index([createdAt]) @@index([sessionId]) @@index([websiteId]) + @@index([eventUuid]) } model eventData { @@ -78,6 +82,7 @@ model session { @@index([createdAt]) @@index([websiteId]) + @@index([sessionUuid]) } model website { @@ -94,4 +99,5 @@ model website { session session[] @@index([userId]) + @@index([websiteUuid]) } diff --git a/db/postgresql/migrations/04_account_uuid/migration.sql b/db/postgresql/migrations/04_add_uuid/migration.sql similarity index 59% rename from db/postgresql/migrations/04_account_uuid/migration.sql rename to db/postgresql/migrations/04_add_uuid/migration.sql index b6929f64..21d4cf07 100644 --- a/db/postgresql/migrations/04_account_uuid/migration.sql +++ b/db/postgresql/migrations/04_add_uuid/migration.sql @@ -11,6 +11,18 @@ ALTER TABLE "account" ALTER COLUMN "account_uuid" SET NOT NULL; -- CreateIndex CREATE UNIQUE INDEX "account_account_uuid_key" ON "account"("account_uuid"); +-- AlterTable +ALTER TABLE "event" ADD COLUMN "event_uuid" UUID NULL; + +-- Backfill UUID +UPDATE "event" SET event_uuid = gen_random_uuid(); + +-- AlterTable +ALTER TABLE "event" ALTER COLUMN "event_uuid" SET NOT NULL; + +-- CreateIndex +CREATE UNIQUE INDEX "event_event_uuid_key" ON "event"("event_uuid"); + -- CreateIndex CREATE INDEX "account_account_uuid_idx" ON "account"("account_uuid"); @@ -18,4 +30,7 @@ CREATE INDEX "account_account_uuid_idx" ON "account"("account_uuid"); CREATE INDEX "session_session_uuid_idx" ON "session"("session_uuid"); -- CreateIndex -CREATE INDEX "website_website_uuid_idx" ON "website"("website_uuid"); \ No newline at end of file +CREATE INDEX "website_website_uuid_idx" ON "website"("website_uuid"); + +-- CreateIndex +CREATE INDEX "event_event_uuid_idx" ON "event"("event_uuid"); \ No newline at end of file diff --git a/db/postgresql/schema.prisma b/db/postgresql/schema.prisma index 920a6f78..ad1c7595 100644 --- a/db/postgresql/schema.prisma +++ b/db/postgresql/schema.prisma @@ -16,6 +16,8 @@ model account { updatedAt DateTime? @default(now()) @map("updated_at") @db.Timestamptz(6) accountUuid String @unique @map("account_uuid") @db.Uuid website website[] + + @@index([accountUuid]) } model event { @@ -25,6 +27,7 @@ model event { createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6) url String @db.VarChar(500) eventName String @map("event_name") @db.VarChar(50) + eventUuid String @unique @map("event_uuid") @db.Uuid session session @relation(fields: [sessionId], references: [id]) website website @relation(fields: [websiteId], references: [id]) eventData eventData? @@ -32,6 +35,7 @@ model event { @@index([createdAt]) @@index([sessionId]) @@index([websiteId]) + @@index([eventUuid]) } model eventData { @@ -78,6 +82,7 @@ model session { @@index([createdAt]) @@index([websiteId]) + @@index([sessionUuid]) } model website { @@ -94,4 +99,5 @@ model website { session session[] @@index([userId]) + @@index([websiteUuid]) }