File tree 2 files changed +43
-2
lines changed
migrations/20250116233531_add_orgs_table
2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change
1
+ -- CreateTable
2
+ CREATE TABLE "Org " (
3
+ " id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
4
+ " name" TEXT NOT NULL ,
5
+ " createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
6
+ " updatedAt" DATETIME NOT NULL
7
+ );
8
+
9
+ -- CreateTable
10
+ CREATE TABLE "UserToOrg " (
11
+ " joinedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
12
+ " orgId" INTEGER NOT NULL ,
13
+ " userId" TEXT NOT NULL ,
14
+
15
+ PRIMARY KEY (" orgId" , " userId" ),
16
+ CONSTRAINT " UserToOrg_orgId_fkey" FOREIGN KEY (" orgId" ) REFERENCES " Org" (" id" ) ON DELETE CASCADE ON UPDATE CASCADE,
17
+ CONSTRAINT " UserToOrg_userId_fkey" FOREIGN KEY (" userId" ) REFERENCES " User" (" id" ) ON DELETE CASCADE ON UPDATE CASCADE
18
+ );
Original file line number Diff line number Diff line change @@ -42,14 +42,37 @@ model Repo {
42
42
@@unique ([external_id , external_codeHostUrl ] )
43
43
}
44
44
45
+ model Org {
46
+ id Int @id @default (autoincrement () )
47
+ name String
48
+ createdAt DateTime @default (now () )
49
+ updatedAt DateTime @updatedAt
50
+ members UserToOrg []
51
+ }
52
+
53
+ model UserToOrg {
54
+ joinedAt DateTime @default (now () )
55
+
56
+ /// The linked organization
57
+ org Org @relation (fields : [orgId ] , references : [id ] , onDelete : Cascade )
58
+ orgId Int
59
+
60
+ /// The linked user
61
+ user User @relation (fields : [userId ] , references : [id ] , onDelete : Cascade )
62
+ userId String
63
+
64
+ @@id ([orgId , userId ] )
65
+ }
66
+
45
67
// @see : https://authjs.dev/concepts/database-models#user
46
68
model User {
47
- id String @id @default (cuid () )
69
+ id String @id @default (cuid () )
48
70
name String ?
49
- email String ? @unique
71
+ email String ? @unique
50
72
emailVerified DateTime ?
51
73
image String ?
52
74
accounts Account []
75
+ orgs UserToOrg []
53
76
54
77
createdAt DateTime @default (now () )
55
78
updatedAt DateTime @updatedAt
You can’t perform that action at this time.
0 commit comments