From 11528090a53f287276119ba7576ee6e40b3c998a Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Tue, 18 Feb 2025 15:17:47 +1100 Subject: [PATCH] fix: prepare auth migration (#1648) Add schema session migration in preparation for auth migration. --- .../migration.sql | 18 ++++++++++++++++++ packages/prisma/schema.prisma | 17 ++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 packages/prisma/migrations/20250217120859_add_session_fields/migration.sql diff --git a/packages/prisma/migrations/20250217120859_add_session_fields/migration.sql b/packages/prisma/migrations/20250217120859_add_session_fields/migration.sql new file mode 100644 index 000000000..5af838335 --- /dev/null +++ b/packages/prisma/migrations/20250217120859_add_session_fields/migration.sql @@ -0,0 +1,18 @@ +/* + Warnings: + + - You are about to drop the column `expires` on the `Session` table. All the data in the column will be lost. + - Added the required column `expiresAt` to the `Session` table without a default value. This is not possible if the table is not empty. + - Added the required column `updatedAt` to the `Session` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "Account" ADD COLUMN "password" TEXT; + +-- AlterTable +ALTER TABLE "Session" DROP COLUMN "expires", +ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "expiresAt" TIMESTAMP(3) NOT NULL, +ADD COLUMN "ipAddress" TEXT, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL, +ADD COLUMN "userAgent" TEXT; diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma index 0cdb1521e..e612921dc 100644 --- a/packages/prisma/schema.prisma +++ b/packages/prisma/schema.prisma @@ -270,18 +270,25 @@ model Account { scope String? id_token String? @db.Text session_state String? + password String? - user User? @relation(fields: [userId], references: [id], onDelete: Cascade) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@unique([provider, providerAccountId]) } model Session { - id String @id @default(cuid()) - sessionToken String @unique + id String @id @default(cuid()) + sessionToken String @unique userId Int - expires DateTime - user User? @relation(fields: [userId], references: [id], onDelete: Cascade) + + ipAddress String? + userAgent String? + expiresAt DateTime + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + user User? @relation(fields: [userId], references: [id], onDelete: Cascade) } enum DocumentStatus {