Skip to content

Commit

Permalink
have to use emulated fk
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Jul 21, 2023
1 parent a98b5f7 commit e4a5b6a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Atropos",
"autoincrement",
"bancho",
"banchopy",
"Beatmap",
"Beatmaps",
"beatmapset",
Expand Down
9 changes: 9 additions & 0 deletions migration/sql/constraints-user-relationshiop.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DELETE FROM banchopy.relationships r
WHERE r.user1 NOT IN (
SELECT u.id
FROM banchopy.users u
)
OR r.user2 NOT IN (
SELECT u.id
FROM banchopy.users u
)
25 changes: 20 additions & 5 deletions prisma/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ generator client {
}

datasource db {
provider = "mysql"
url = env("DB_DSN")
provider = "mysql"
url = env("DB_DSN")
relationMode = "prisma"
}

model User {
Expand All @@ -30,7 +31,7 @@ model User {
clanPriv Int @default(0) @map("clan_priv") @db.TinyInt
apiKey String? @unique(map: "users_api_key_uindex") @map("api_key") @db.Char(36)
clan Clan @relation("clan", fields: [clanId], references: [id])
clan Clan @relation("clan", fields: [clanId], references: [id], onUpdate: NoAction, onDelete: NoAction)
favourites Favourite[]
ingameLogins IngameLogin[]
receivedMessages Mail[] @relation("receivedMessages")
Expand All @@ -44,6 +45,7 @@ model User {
scores Score[]
userAchievement UserAchievement[]
@@index([clanId])
@@map("users")
}

Expand All @@ -59,6 +61,7 @@ model ClientHash {
user User @relation(fields: [userId], references: [id])
@@id([userId, osuPath, iFaces, uninstallId, diskSerial])
@@index([userId])
@@map("client_hashes")
}

Expand All @@ -73,6 +76,7 @@ model Comment {
user User @relation(fields: [userId], references: [id])
@@index([userId])
@@map("comments")
}

Expand All @@ -98,6 +102,7 @@ model Favourite {
// source Source @relation(fields: [setId], references: [id])
@@id([userId, setId])
@@index([userId])
@@map("favourites")
}

Expand All @@ -111,6 +116,7 @@ model IngameLogin {
user User @relation(fields: [userId], references: [id])
@@index([userId])
@@map("ingame_logins")
}

Expand All @@ -135,6 +141,8 @@ model Mail {
fromUser User @relation(name: "sentMessages", fields: [fromId], references: [id])
targetUser User @relation(name: "receivedMessages", fields: [targetId], references: [id])
@@index([fromId])
@@index([targetId])
@@map("mail")
}

Expand Down Expand Up @@ -179,6 +187,7 @@ model Map {
@@id([server, id])
@@index([filename], map: "filename")
@@index([setId, server])
@@map("maps")
}

Expand All @@ -191,6 +200,7 @@ model Source {
beatmaps Map[]
@@id([server, id])
@@unique([id, server])
@@map("mapsets")
}

Expand Down Expand Up @@ -233,6 +243,8 @@ model Relationship {
toUser User @relation(name: "to", fields: [toUserId], references: [id])
@@id([fromUserId, toUserId])
@@index([fromUserId])
@@index([toUserId])
@@map("relationships")
}

Expand Down Expand Up @@ -299,6 +311,7 @@ model Stat {
user User @relation(fields: [id], references: [id])
@@id([id, mode])
@@index([id])
@@map("stats")
}

Expand All @@ -308,7 +321,7 @@ model TourneyPool {
createdAt DateTime @map("created_at") @db.DateTime(0)
createdBy Int @map("created_by")
@@index([createdBy], map: "tourney_pools_users_id_fk")
@@index([createdBy], map: "tourney_pools_users_id_uindex")
@@map("tourney_pools")
}

Expand All @@ -320,6 +333,8 @@ model UserAchievement {
achievement Achievement @relation(fields: [achievementId], references: [id])
@@id([userId, achievementId])
@@index([userId])
@@index([achievementId])
@@map("user_achievements")
}

Expand Down Expand Up @@ -352,7 +367,7 @@ model TourneyPoolMap {
slot Int @db.TinyInt
@@id([map_id, pool_id])
@@index([pool_id], map: "tourney_pool_maps_tourney_pools_id_fk")
@@index([pool_id], map: "tourney_pool_maps_tourney_pools_id_uindex")
@@map("tourney_pool_maps")
}

Expand Down
27 changes: 20 additions & 7 deletions prisma/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ generator client {
}

datasource db {
provider = "mysql"
url = env("DB_DSN")
provider = "mysql"
url = env("DB_DSN")
relationMode = "prisma"
}

model User {
Expand All @@ -30,7 +31,7 @@ model User {
clanPriv Int @default(0) @map("clan_priv") @db.TinyInt
apiKey String? @unique(map: "users_api_key_uindex") @map("api_key") @db.Char(36)
clan Clan @relation("clan", fields: [clanId], references: [id])
clan Clan @relation("clan", fields: [clanId], references: [id], onUpdate: NoAction, onDelete: NoAction)
favourites Favourite[]
ingameLogins IngameLogin[]
receivedMessages Mail[] @relation("receivedMessages")
Expand All @@ -45,7 +46,7 @@ model User {
scores Score[]
userAchievement UserAchievement[]
@@index([clanId], map: "users_clan_id_fkey")
@@index([clanId], map: "users_clan_id_uindex")
@@map("users")
}

Expand All @@ -61,6 +62,7 @@ model ClientHash {
user User @relation(fields: [userId], references: [id])
@@id([userId, osuPath, iFaces, uninstallId, diskSerial])
@@index([userId])
@@map("client_hashes")
}

Expand All @@ -75,7 +77,7 @@ model Comment {
user User @relation(fields: [userId], references: [id])
@@index([userId], map: "comments_userid_fkey")
@@index([userId], map: "comments_userid_uindex")
@@map("comments")
}

Expand All @@ -101,6 +103,7 @@ model Favourite {
// source Source @relation(fields: [setId], references: [id])
@@id([userId, setId])
@@index([userId])
@@map("favourites")
}

Expand All @@ -114,6 +117,7 @@ model IngameLogin {
user User @relation(fields: [userId], references: [id])
@@index([userId])
@@map("ingame_logins")
}

Expand All @@ -138,6 +142,8 @@ model Mail {
fromUser User @relation(name: "sentMessages", fields: [fromId], references: [id])
targetUser User @relation(name: "receivedMessages", fields: [targetId], references: [id])
@@index([fromId])
@@index([targetId])
@@map("mail")
}

Expand Down Expand Up @@ -182,6 +188,7 @@ model Map {
@@id([server, id])
@@index([filename], map: "filename")
@@index([setId, server])
@@map("maps")
}

Expand All @@ -194,6 +201,7 @@ model Source {
beatmaps Map[]
@@id([server, id])
@@unique([id, server])
@@map("mapsets")
}

Expand Down Expand Up @@ -236,6 +244,8 @@ model Relationship {
toUser User @relation(name: "to", fields: [toUserId], references: [id])
@@id([fromUserId, toUserId])
@@index([fromUserId])
@@index([toUserId])
@@map("relationships")
}

Expand Down Expand Up @@ -302,6 +312,7 @@ model Stat {
user User @relation(fields: [id], references: [id])
@@id([id, mode])
@@index([id])
@@map("stats")
}

Expand All @@ -311,7 +322,7 @@ model TourneyPool {
createdAt DateTime @map("created_at") @db.DateTime(0)
createdBy Int @map("created_by")
@@index([createdBy], map: "tourney_pools_users_id_fk")
@@index([createdBy], map: "tourney_pools_users_id_uindex")
@@map("tourney_pools")
}

Expand All @@ -323,6 +334,8 @@ model UserAchievement {
achievement Achievement @relation(fields: [achievementId], references: [id])
@@id([userId, achievementId])
@@index([userId])
@@index([achievementId])
@@map("user_achievements")
}

Expand Down Expand Up @@ -362,7 +375,7 @@ model TourneyPoolMap {
slot Int @db.TinyInt
@@id([map_id, pool_id])
@@index([pool_id], map: "tourney_pool_maps_tourney_pools_id_fk")
@@index([pool_id], map: "tourney_pool_maps_tourney_pools_id_uindex")
@@map("tourney_pool_maps")
}

Expand Down

0 comments on commit e4a5b6a

Please sign in to comment.