Skip to content

Organization table #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- CreateTable
CREATE TABLE "Org" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);

-- CreateTable
CREATE TABLE "UserToOrg" (
"joinedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"orgId" INTEGER NOT NULL,
"userId" TEXT NOT NULL,

PRIMARY KEY ("orgId", "userId"),
CONSTRAINT "UserToOrg_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "Org" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "UserToOrg_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
27 changes: 25 additions & 2 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,37 @@ model Repo {
@@unique([external_id, external_codeHostUrl])
}

model Org {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
members UserToOrg[]
}

model UserToOrg {
joinedAt DateTime @default(now())

/// The linked organization
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
orgId Int

/// The linked user
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String

@@id([orgId, userId])
}

// @see : https://authjs.dev/concepts/database-models#user
model User {
id String @id @default(cuid())
id String @id @default(cuid())
name String?
email String? @unique
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
orgs UserToOrg[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down