-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Northeastern-Electric-Racing/Reverting-Pr…
…isma-Changes Revert Odyssey Base Change
- Loading branch information
Showing
14 changed files
with
338 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule odyssey-base
updated
12 files
74 changes: 74 additions & 0 deletions
74
scylla-server/src/prisma/migrations/20230912210925_init/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
-- CreateTable | ||
CREATE TABLE "Run" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"locationName" TEXT NOT NULL, | ||
"driverId" TEXT, | ||
"systemId" TEXT, | ||
"time" DATETIME NOT NULL, | ||
CONSTRAINT "Run_locationName_fkey" FOREIGN KEY ("locationName") REFERENCES "Location" ("name") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "Run_driverId_fkey" FOREIGN KEY ("driverId") REFERENCES "Driver" ("username") ON DELETE SET NULL ON UPDATE CASCADE, | ||
CONSTRAINT "Run_systemId_fkey" FOREIGN KEY ("systemId") REFERENCES "System" ("name") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Location" ( | ||
"name" TEXT NOT NULL PRIMARY KEY, | ||
"latitude" REAL NOT NULL, | ||
"longitude" REAL NOT NULL, | ||
"radius" REAL NOT NULL | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Driver" ( | ||
"username" TEXT NOT NULL PRIMARY KEY | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "System" ( | ||
"name" TEXT NOT NULL PRIMARY KEY | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Data" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"value" INTEGER NOT NULL, | ||
"dataTypeName" TEXT NOT NULL, | ||
"time" INTEGER NOT NULL, | ||
"runId" INTEGER NOT NULL, | ||
CONSTRAINT "Data_dataTypeName_fkey" FOREIGN KEY ("dataTypeName") REFERENCES "DataType" ("name") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "Data_runId_fkey" FOREIGN KEY ("runId") REFERENCES "Run" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "DataType" ( | ||
"name" TEXT NOT NULL PRIMARY KEY, | ||
"unit" TEXT NOT NULL, | ||
"nodeName" TEXT NOT NULL, | ||
CONSTRAINT "DataType_nodeName_fkey" FOREIGN KEY ("nodeName") REFERENCES "Node" ("name") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Node" ( | ||
"name" TEXT NOT NULL PRIMARY KEY | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Run_id_key" ON "Run"("id"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Location_name_key" ON "Location"("name"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Driver_username_key" ON "Driver"("username"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "System_name_key" ON "System"("name"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Data_id_key" ON "Data"("id"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "DataType_name_key" ON "DataType"("name"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Node_name_key" ON "Node"("name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "sqlite" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
const prisma = new PrismaClient(); | ||
export default prisma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
binaryTargets = ["native", "debian-openssl-1.1.x", "linux-arm64-openssl-1.1.x"] | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = "file:./mydatabase.db" | ||
} | ||
|
||
model Run { | ||
id Int @id @unique @default(autoincrement()) | ||
locationName String | ||
location Location @relation(fields: [locationName], references: [name]) | ||
driverId String? | ||
driver Driver? @relation(fields: [driverId], references: [username]) | ||
systemId String? | ||
system System? @relation(fields: [systemId], references: [name]) | ||
data Data[] | ||
time DateTime | ||
} | ||
|
||
model Location { | ||
name String @id @unique | ||
latitude Float | ||
longitude Float | ||
radius Float | ||
runs Run[] | ||
} | ||
|
||
model Driver { | ||
username String @id @unique | ||
runs Run[] | ||
} | ||
|
||
model System { | ||
name String @id @unique | ||
runs Run[] | ||
} | ||
|
||
model Data { | ||
id Int @id @unique @default(autoincrement()) | ||
value Int | ||
dataTypeName String | ||
dataType DataType @relation(fields: [dataTypeName], references: [name]) | ||
time Int | ||
runId Int | ||
run Run @relation(fields: [runId], references: [id]) | ||
} | ||
|
||
model DataType { | ||
name String @id @unique | ||
unit String | ||
data Data[] | ||
node Node @relation(fields: [nodeName], references: [name]) | ||
nodeName String | ||
} | ||
|
||
model Node { | ||
name String @id @unique | ||
dataTypes DataType[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import prisma from '../prisma/prisma-client'; | ||
import { ResponseFunction } from '../utils/message-maps.utils'; | ||
|
||
/** | ||
* CRUD operation to get all dataTypes | ||
* @returns string containing all the dataTypes | ||
*/ | ||
export const getAllDataTypes: ResponseFunction = async () => { | ||
const data = await prisma.dataType.findMany(); | ||
return JSON.stringify(data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import prisma from '../prisma/prisma-client'; | ||
import { ResponseFunction } from '../utils/message-maps.utils'; | ||
|
||
/** | ||
* CRUD operation to get all dataTypes | ||
* @returns string containing all the dataTypes | ||
*/ | ||
export const getAllDrivers: ResponseFunction = async () => { | ||
const data = await prisma.driver.findMany(); | ||
return JSON.stringify(data); | ||
}; | ||
|
||
/** | ||
* CRUD operation to create a driver in the database if it doesn't already exist, does nothing otherwise. | ||
* | ||
*/ | ||
export const upsertDriver = async (driverName: string) => { | ||
await prisma.driver.upsert({ | ||
where: { | ||
username: driverName | ||
}, | ||
update: {}, | ||
create: { | ||
username: driverName | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import prisma from '../prisma/prisma-client'; | ||
import { ResponseFunction } from '../utils/message-maps.utils'; | ||
|
||
/** | ||
* CRUD operation to get all systems with ResponseFunction type | ||
* @returns Promise<string> contianing all the systems in the db | ||
*/ | ||
export const getAllSystems: ResponseFunction = async () => { | ||
const data = await prisma.system.findMany(); | ||
return JSON.stringify(data); | ||
}; | ||
|
||
/** | ||
* CRUD opertation that creates system if it doesn't exist, otherwise does nothing. | ||
* Currently designated private so not hooked up to server. | ||
* @param systemName name of the system as string | ||
* @returns Promise<void> | ||
*/ | ||
export const upsertSystem = async (systemName: string) => { | ||
await prisma.system.upsert({ | ||
where: { | ||
name: systemName | ||
}, | ||
update: {}, | ||
create: { | ||
name: systemName | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
import { getAllDataTypes } from '../src/services/dataTypes.services'; | ||
|
||
describe('Data Type', () => { | ||
test('Get All Data Types Works', async () => { | ||
const expected = []; | ||
const result = await getAllDataTypes(); | ||
|
||
// Parse result to a JavaScript object from the JSON string | ||
const parsedResult = JSON.parse(result); | ||
|
||
// Use toEqual to compare parsedResult with the expected array | ||
expect(parsedResult).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { describe, test, expect, afterEach } from 'vitest'; | ||
import { getAllDrivers, upsertDriver } from '../src/services/driver.services'; | ||
import prisma from '../src/prisma/prisma-client'; | ||
|
||
/** | ||
* Tests for CRUD Service functions | ||
*/ | ||
describe('CRUD Driver', () => { | ||
afterEach(async () => { | ||
try { | ||
await prisma.driver.delete({ | ||
where: { | ||
username: 'test' | ||
} | ||
}); | ||
} catch (err) {} | ||
}); | ||
|
||
/** | ||
* unit test for get all drivers | ||
*/ | ||
test('Get All Data Types Works', async () => { | ||
const expected = []; | ||
const result = await getAllDrivers(); | ||
|
||
// Parse result to a JavaScript object from the JSON string | ||
const parsedResult = JSON.parse(result); | ||
|
||
// Use toEqual to compare parsedResult with the expected array | ||
expect(parsedResult).toEqual(expected); | ||
}); | ||
|
||
/** | ||
* Unit testing for upsert driver | ||
* test driver creation if the name doesn't already exist | ||
* */ | ||
test('Upsert Driver Creates', async () => { | ||
const expected = [{ username: 'test' }]; | ||
await upsertDriver('test'); | ||
const result = JSON.parse(await getAllDrivers()); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, test, expect, afterEach } from 'vitest'; | ||
import { getAllSystems, upsertSystem } from '../src/services/systems.services'; | ||
|
||
import prisma from '../src/prisma/prisma-client'; | ||
|
||
/** | ||
* Tests for CRUD Service functions | ||
*/ | ||
describe('CRUD Systems', () => { | ||
//cleaning up | ||
afterEach(async () => { | ||
try { | ||
await prisma.system.delete({ | ||
where: { | ||
name: 'test' | ||
} | ||
}); | ||
} catch (err) {} | ||
}); | ||
/** | ||
* unit test for upsert system | ||
* testing creating system if doesn't exist | ||
*/ | ||
test('Upsert System Creates', async () => { | ||
const expected = [{ name: 'test' }]; | ||
await upsertSystem('test'); | ||
const result = JSON.parse(await getAllSystems()); | ||
|
||
// Use toEqual to compare parsedResult with the expected array | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
/** | ||
* updated unit test for get all systems | ||
*/ | ||
test('Get All Systems Works', async () => { | ||
await upsertSystem('test'); | ||
const expected = [{ name: 'test' }]; | ||
const result = await getAllSystems(); | ||
|
||
// Parse result to a JavaScript object from the JSON string | ||
const parsedResult = JSON.parse(result); | ||
|
||
// Use toEqual to compare parsedResult with the expected array | ||
expect(parsedResult).toEqual(expected); | ||
}); | ||
|
||
/** | ||
* unit test for upsert system | ||
* testing does nothing if system does exist | ||
*/ | ||
test('Upsert System Does Nothing', async () => { | ||
const expected = [{ name: 'test' }]; | ||
await upsertSystem('test'); | ||
const result = JSON.parse(await getAllSystems()); | ||
|
||
// Use toEqual to compare result with the expected array | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |