From b415892b7db7b900f50314b40242c4e3f4df6244 Mon Sep 17 00:00:00 2001 From: Brian Cao Date: Wed, 27 Jul 2022 12:03:12 -0700 Subject: [PATCH] restart migration. refresh schema --- .../02_prisma_4_upgrade/migration.sql | 47 ------------------- db/postgresql/schema.prisma | 26 +++++----- 2 files changed, 13 insertions(+), 60 deletions(-) delete mode 100644 db/postgresql/migrations/02_prisma_4_upgrade/migration.sql diff --git a/db/postgresql/migrations/02_prisma_4_upgrade/migration.sql b/db/postgresql/migrations/02_prisma_4_upgrade/migration.sql deleted file mode 100644 index b5a5767e..00000000 --- a/db/postgresql/migrations/02_prisma_4_upgrade/migration.sql +++ /dev/null @@ -1,47 +0,0 @@ --- DropForeignKey -ALTER TABLE "event" DROP CONSTRAINT "event_session_id_fkey"; - --- DropForeignKey -ALTER TABLE "event" DROP CONSTRAINT "event_website_id_fkey"; - --- DropForeignKey -ALTER TABLE "pageview" DROP CONSTRAINT "pageview_session_id_fkey"; - --- DropForeignKey -ALTER TABLE "pageview" DROP CONSTRAINT "pageview_website_id_fkey"; - --- DropForeignKey -ALTER TABLE "session" DROP CONSTRAINT "session_website_id_fkey"; - --- DropForeignKey -ALTER TABLE "website" DROP CONSTRAINT "website_user_id_fkey"; - --- AddForeignKey -ALTER TABLE "event" ADD CONSTRAINT "event_session_id_fkey" FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE NO ACTION; - --- AddForeignKey -ALTER TABLE "event" ADD CONSTRAINT "event_website_id_fkey" FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE NO ACTION; - --- AddForeignKey -ALTER TABLE "pageview" ADD CONSTRAINT "pageview_session_id_fkey" FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE NO ACTION; - --- AddForeignKey -ALTER TABLE "pageview" ADD CONSTRAINT "pageview_website_id_fkey" FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE NO ACTION; - --- AddForeignKey -ALTER TABLE "session" ADD CONSTRAINT "session_website_id_fkey" FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE NO ACTION; - --- AddForeignKey -ALTER TABLE "website" ADD CONSTRAINT "website_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "account"("user_id") ON DELETE NO ACTION ON UPDATE NO ACTION; - --- RenameIndex -ALTER INDEX "account.username_unique" RENAME TO "account_username_key"; - --- RenameIndex -ALTER INDEX "session.session_uuid_unique" RENAME TO "session_session_uuid_key"; - --- RenameIndex -ALTER INDEX "website.share_id_unique" RENAME TO "website_share_id_idx"; - --- RenameIndex -ALTER INDEX "website.website_uuid_unique" RENAME TO "website_website_uuid_key"; diff --git a/db/postgresql/schema.prisma b/db/postgresql/schema.prisma index 6e974de8..e425475f 100644 --- a/db/postgresql/schema.prisma +++ b/db/postgresql/schema.prisma @@ -9,7 +9,7 @@ datasource db { model account { user_id Int @id @default(autoincrement()) - username String @unique @db.VarChar(255) + username String @unique(map: "account.username_unique") @db.VarChar(255) password String @db.VarChar(60) is_admin Boolean @default(false) created_at DateTime? @default(now()) @db.Timestamptz(6) @@ -25,8 +25,8 @@ model event { url String @db.VarChar(500) event_type String @db.VarChar(50) event_value String @db.VarChar(50) - session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade, onUpdate: NoAction) - website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade, onUpdate: NoAction) + session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade) + website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade) @@index([created_at]) @@index([session_id]) @@ -40,8 +40,8 @@ model pageview { created_at DateTime? @default(now()) @db.Timestamptz(6) url String @db.VarChar(500) referrer String? @db.VarChar(500) - session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade, onUpdate: NoAction) - website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade, onUpdate: NoAction) + session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade) + website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade) @@index([created_at]) @@index([session_id]) @@ -52,17 +52,17 @@ model pageview { model session { session_id Int @id @default(autoincrement()) - session_uuid String @unique @db.Uuid + session_uuid String @unique(map: "session.session_uuid_unique") @db.Uuid website_id Int created_at DateTime? @default(now()) @db.Timestamptz(6) hostname String? @db.VarChar(100) browser String? @db.VarChar(20) os String? @db.VarChar(20) + device String? @db.VarChar(20) screen String? @db.VarChar(11) language String? @db.VarChar(35) country String? @db.Char(2) - device String? @db.VarChar(20) - website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade, onUpdate: NoAction) + website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade) event event[] pageview pageview[] @@ -72,13 +72,13 @@ model session { model website { website_id Int @id @default(autoincrement()) - website_uuid String @unique @db.Uuid - name String @db.VarChar(100) - created_at DateTime? @default(now()) @db.Timestamptz(6) + website_uuid String @unique(map: "website.website_uuid_unique") @db.Uuid user_id Int + name String @db.VarChar(100) domain String? @db.VarChar(500) - share_id String? @unique(map: "website_share_id_idx") @db.VarChar(64) - account account @relation(fields: [user_id], references: [user_id], onDelete: NoAction, onUpdate: NoAction) + share_id String? @unique(map: "website.share_id_unique") @db.VarChar(64) + created_at DateTime? @default(now()) @db.Timestamptz(6) + account account @relation(fields: [user_id], references: [user_id], onDelete: Cascade) event event[] pageview pageview[] session session[]