mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-01-02 17:02:41 +00:00
WIP handle unique constraint exception
This commit is contained in:
@@ -14,7 +14,7 @@ CREATE TABLE "auth" (
|
||||
-- CreateTable
|
||||
CREATE TABLE "username" (
|
||||
"username" TEXT NOT NULL,
|
||||
"uuid" UUID NOT NULL,
|
||||
"authUuid" UUID NOT NULL,
|
||||
"type" "Type" NOT NULL DEFAULT 'EMAIL',
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
@@ -23,4 +23,7 @@ CREATE TABLE "username" (
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "username_uuid_type_key" ON "username"("uuid", "type");
|
||||
CREATE UNIQUE INDEX "username_authUuid_type_key" ON "username"("authUuid", "type");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "username" ADD CONSTRAINT "username_authUuid_fkey" FOREIGN KEY ("authUuid") REFERENCES "auth"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -11,22 +11,24 @@ datasource db {
|
||||
}
|
||||
|
||||
model Auth {
|
||||
uuid String @id @db.Uuid
|
||||
uuid String @id @default(uuid()) @db.Uuid
|
||||
password String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
usernames Username[]
|
||||
|
||||
@@map("auth")
|
||||
}
|
||||
|
||||
model Username {
|
||||
username String @id
|
||||
uuid String @db.Uuid
|
||||
authUuid String @db.Uuid
|
||||
type Type @default(EMAIL) // type is needed in case of username update
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
Auth Auth @relation(fields: [authUuid], references: [uuid], onDelete: Cascade)
|
||||
|
||||
@@unique([uuid, type])
|
||||
@@unique([authUuid, type])
|
||||
@@map("username")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user