diff --git a/server/prisma/migrations/20201120191035-fix-relations/README.md b/server/prisma/migrations/20201120191035-fix-relations/README.md new file mode 100644 index 0000000..a39fee7 --- /dev/null +++ b/server/prisma/migrations/20201120191035-fix-relations/README.md @@ -0,0 +1,44 @@ +# Migration `20201120191035-fix-relations` + +This migration has been generated by Douglas Barone at 11/20/2020, 3:10:35 PM. +You can check out the [state of the schema](./schema.prisma) after the migration. + +## Database Steps + +```sql + +``` + +## Changes + +```diff +diff --git schema.prisma schema.prisma +migration 20201119134248-add-controller-to-wifi-device..20201120191035-fix-relations +--- datamodel.dml ++++ datamodel.dml +@@ -3,9 +3,9 @@ + } + datasource db { + provider = "postgresql" +- url = "***" ++ url = "***" + } + model ResetToken { + id Int @id @default(autoincrement()) +@@ -65,11 +65,11 @@ + userAccountControl String? + userPrincipalName String? + whenChanged String? + whenCreated String? +- createdTokens ResetToken[] @relation("resettoken_to_user") +- tokens ResetToken[] @relation("resettoken_to_creator") +- WifiDevice WifiDevice[] @relation("wifidevice_to_user") ++ createdTokens ResetToken[] @relation("resettoken_to_creator") ++ tokens ResetToken[] @relation("resettoken_to_user") ++ wifiDevices WifiDevice[] @relation("wifidevice_to_user") + } + model WifiDevice { + id Int @id @default(autoincrement()) +``` + + diff --git a/server/prisma/migrations/20201120191035-fix-relations/schema.prisma b/server/prisma/migrations/20201120191035-fix-relations/schema.prisma new file mode 100644 index 0000000..a74610f --- /dev/null +++ b/server/prisma/migrations/20201120191035-fix-relations/schema.prisma @@ -0,0 +1,96 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = "***" +} + +model ResetToken { + id Int @id @default(autoincrement()) + token String @unique + expiration DateTime + usedAt DateTime? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + user User @relation(fields: [userId], references: [id], name: "resettoken_to_user") + userId Int + creator User @relation(fields: [creatorId], references: [id], name: "resettoken_to_creator") + creatorId Int +} + +model User { + id Int @id @default(autoincrement()) + lastLogin DateTime? + lastLoginPrior DateTime? + roles Json? + groups Json? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + accountExpires String? + badPasswordTime String? + badPwdCount String? + cn String? + department String? + description String? + displayName String? + distinguishedName String? + dn String? + extensionAttribute1 String? + extensionAttribute10 String? + extensionAttribute2 String? + extensionAttribute6 String? + extensionAttribute7 String? + givenName String? + homeDirectory String? + homeDrive String? + lastLogoff String? + lastLogon String? + lastLogonTimestamp String? + lockoutTime String? + logonCount String? + mail String? + name String? + objectCategory String? + objectGUID String? + objectSid String? + primaryGroupID String? + pwdLastSet DateTime? + sAMAccountName String @unique + sAMAccountType String? + sn String? + thumbnailPhoto String? + title String? + userAccountControl String? + userPrincipalName String? + whenChanged String? + whenCreated String? + createdTokens ResetToken[] @relation("resettoken_to_creator") + tokens ResetToken[] @relation("resettoken_to_user") + wifiDevices WifiDevice[] @relation("wifidevice_to_user") +} + +model WifiDevice { + id Int @id @default(autoincrement()) + mac String @unique + controller String @default("unknown") + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + oui String? + hostname String? + firstSeen DateTime? + lastSeen DateTime? + essid String? + ip String? + uptime String? + apName String? + status Status? + userId Int? + user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user") +} + +enum Status { + ONLINE + OFFLINE +} diff --git a/server/prisma/migrations/20201120191035-fix-relations/steps.json b/server/prisma/migrations/20201120191035-fix-relations/steps.json new file mode 100644 index 0000000..c4e3bbb --- /dev/null +++ b/server/prisma/migrations/20201120191035-fix-relations/steps.json @@ -0,0 +1,70 @@ +{ + "version": "0.3.14-fixed", + "steps": [ + { + "tag": "CreateField", + "model": "User", + "field": "wifiDevices", + "type": "WifiDevice", + "arity": "List" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "User", + "field": "wifiDevices" + }, + "directive": "relation" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "User", + "field": "wifiDevices" + }, + "directive": "relation" + }, + "argument": "", + "value": "\"wifidevice_to_user\"" + }, + { + "tag": "DeleteField", + "model": "User", + "field": "WifiDevice" + }, + { + "tag": "UpdateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "User", + "field": "createdTokens" + }, + "directive": "relation" + }, + "argument": "", + "newValue": "\"resettoken_to_creator\"" + }, + { + "tag": "UpdateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "User", + "field": "tokens" + }, + "directive": "relation" + }, + "argument": "", + "newValue": "\"resettoken_to_user\"" + } + ] +} \ No newline at end of file diff --git a/server/prisma/migrations/migrate.lock b/server/prisma/migrations/migrate.lock index bf70e8d..760ab79 100644 --- a/server/prisma/migrations/migrate.lock +++ b/server/prisma/migrations/migrate.lock @@ -1,4 +1,5 @@ # Prisma Migrate lockfile v1 20201110194349-init -20201119134248-add-controller-to-wifi-device \ No newline at end of file +20201119134248-add-controller-to-wifi-device +20201120191035-fix-relations \ No newline at end of file diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index 1a62181..be82567 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -66,9 +66,9 @@ model User { userPrincipalName String? whenChanged String? whenCreated String? - createdTokens ResetToken[] @relation("resettoken_to_user") - tokens ResetToken[] @relation("resettoken_to_creator") - WifiDevice WifiDevice[] @relation("wifidevice_to_user") + createdTokens ResetToken[] @relation("resettoken_to_creator") + tokens ResetToken[] @relation("resettoken_to_user") + wifiDevices WifiDevice[] @relation("wifidevice_to_user") } model WifiDevice { diff --git a/server/src/resolvers/Query.js b/server/src/resolvers/Query.js index 7c4074f..a6e5408 100755 --- a/server/src/resolvers/Query.js +++ b/server/src/resolvers/Query.js @@ -108,9 +108,9 @@ const Query = { const usersWithWifiDevices = await prisma.user.findMany({ where: { - WifiDevice: { some: { lastSeen: { not: null } } } + wifiDevices: { some: { lastSeen: { not: null } } } }, - include: { WifiDevice: { orderBy: [{ lastSeen: 'desc' }] } } + include: { wifiDevices: { orderBy: [{ lastSeen: 'desc' }] } } }) search = search.toLowerCase() @@ -120,7 +120,7 @@ const Query = { user => user.displayName.toLowerCase().includes(search) || user.sAMAccountName.toLowerCase().includes(search) || - user.WifiDevice.some(device => + user.wifiDevices.some(device => device.apName.toLowerCase().includes(search) ) ) @@ -130,7 +130,7 @@ const Query = { displayName: user.displayName, thumbnailPhoto: user.thumbnailPhoto }, - wifiDevices: user.WifiDevice + wifiDevices: user.wifiDevices })) const sortedUserPresences = userPresences.sort((a, b) => diff --git a/server/src/resolvers/User.js b/server/src/resolvers/User.js index 8dc1ec9..dd27072 100755 --- a/server/src/resolvers/User.js +++ b/server/src/resolvers/User.js @@ -44,7 +44,7 @@ const User = { sAMAccountName: _.sAMAccountName } }) - .WifiDevice() + .wifiDevices() } }