-
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 #264 from Northeastern-Electric-Racing/charybdis-2…
….0-setup Charybdis Setup
- Loading branch information
Showing
29 changed files
with
1,203 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
# Keep environment variables out of version control | ||
.env | ||
|
||
cloud-prisma/cloud-prisma-client/* | ||
local-prisma/local-prisma-client/* |
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,19 @@ | ||
# Charybdis | ||
|
||
make sure you [install yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable) if you don't have it already. | ||
|
||
and install prisma globally... it's just easier that way(if you have trouble just follow this: [prisma install instructions](https://www.prisma.io/docs/orm/tools/prisma-cli)). | ||
|
||
To initialize the databases run `yarn database:setup` (if this command fails, you should run `yarn database:teardown` before running again.) | ||
|
||
You can also individually teardown and bringup the databases by running `yarn database:cloud:setup` or `yarn database:local:setup` and `yarn database:cloud:teardown` or `yarn database:local:teardown`. | ||
|
||
To teardown all the databases run `yarn database:teardown` | ||
|
||
When updating the local database schema, _Delete the existing migrations files in local-prisma_ and then run `yarn prisma:local:migrate:dev`. Ensure to name the file `init`. This will create the migration file, then run a script to enforce NOT NULL constraints that prisma gurantees put refuses to support in migration sql, copy it to scylla and rerun the diesel migration onto the database to ensure consistency between the two projects, it will also update the diesel schema.rs file according to the new migration (this should be checked to ensure it is based on the expected types, made in your prisma schema). | ||
|
||
IMPORTANT: the above will fail if you have more than the two expect migration folder in /scylla-server/migrations : _00000000000000_diesel_initial_setup_, and the working migration folder: _2024-11-10-031516_create_all_ <--- this will we be where the diesel migration file that is getting updated. | ||
|
||
When updating the cloud schema, only run `yarn prisma:migrate:cloud:dev` and name it appropriately to whatever changes were made. Ensure that when deploying migrations to the cloud you only run `yarn prisma:migrate:cloud`. You will also have to change the cloud database url in your .env file to point to the cloud database | ||
|
||
To access the prisma client for each respective database ensure that you use the proper prisma client from the cloud-prisma and local-prisma prisma files respectively. AKA to access the cloud prisma ensure you are importing `prisma` from `cloud-prisma/prisma.ts`. To access local prisma ensure you are importing `prisma` from `local-prisma/prisma.ts`. |
53 changes: 53 additions & 0 deletions
53
charybdis/cloud-prisma/migrations/20250114193742_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,53 @@ | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'timescaledb') THEN | ||
CREATE EXTENSION timescaledb; | ||
END IF; | ||
END $$; | ||
|
||
-- CreateTable | ||
CREATE TABLE "run" ( | ||
"id" TEXT NOT NULL, | ||
"runId" SERIAL NOT NULL, | ||
"driverName" TEXT NOT NULL, | ||
"notes" TEXT NOT NULL, | ||
"time" TIMESTAMPTZ NOT NULL, | ||
|
||
CONSTRAINT "run_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "data" ( | ||
"values" DOUBLE PRECISION[], | ||
"time" TIMESTAMPTZ NOT NULL, | ||
"dataTypeName" TEXT NOT NULL, | ||
"runId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "data_pkey" PRIMARY KEY ("time","dataTypeName") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "data_type" ( | ||
"name" TEXT NOT NULL, | ||
"unit" TEXT NOT NULL, | ||
"nodeName" TEXT NOT NULL, | ||
|
||
CONSTRAINT "data_type_pkey" PRIMARY KEY ("name") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "data" ADD CONSTRAINT "data_dataTypeName_fkey" FOREIGN KEY ("dataTypeName") REFERENCES "data_type"("name") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "data" ADD CONSTRAINT "data_runId_fkey" FOREIGN KEY ("runId") REFERENCES "run"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
SELECT * FROM create_hypertable('data', by_range('time')); | ||
SELECT * FROM add_dimension('data', by_hash('dataTypeName', 4)); | ||
|
||
ALTER TABLE "data" SET (timescaledb.compress, | ||
timescaledb.compress_orderby = 'time DESC', | ||
timescaledb.compress_segmentby = '"runId", "dataTypeName"', | ||
timescaledb.compress_chunk_time_interval='24 hours' | ||
); | ||
|
||
SELECT add_compression_policy('data', compress_after => INTERVAL '1d'); |
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 (e.g., Git) | ||
provider = "postgresql" |
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 @@ | ||
import { PrismaClient } from "./cloud-prisma-client"; | ||
|
||
export const prisma = new PrismaClient(); |
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,42 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
output = "cloud-prisma-client" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("CLOUD_DATABASE_URL") | ||
} | ||
|
||
model run { | ||
id String @id @default(uuid()) | ||
runId Int @default(autoincrement()) | ||
driverName String | ||
notes String | ||
time DateTime @db.Timestamptz() | ||
data data[] | ||
} | ||
|
||
model data { | ||
values Float[] | ||
time DateTime @db.Timestamptz() | ||
dataTypeName String | ||
dataType data_type @relation(fields: [dataTypeName], references: [name]) | ||
runId String | ||
run run @relation(fields: [runId], references: [id]) | ||
@@id([time, dataTypeName]) | ||
} | ||
|
||
model data_type { | ||
name String @id | ||
unit String | ||
nodeName String | ||
data data[] | ||
} |
35 changes: 35 additions & 0 deletions
35
charybdis/local-prisma/migrations/20250114210137_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,35 @@ | ||
-- CreateTable | ||
CREATE TABLE "run" ( | ||
"runId" SERIAL NOT NULL, | ||
"driverName" TEXT NOT NULL DEFAULT '', | ||
"locationName" TEXT NOT NULL DEFAULT '', | ||
"notes" TEXT NOT NULL DEFAULT '', | ||
"time" TIMESTAMPTZ NOT NULL, | ||
|
||
CONSTRAINT "run_pkey" PRIMARY KEY ("runId") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "data" ( | ||
"values" REAL[] NOT NULL, | ||
"time" TIMESTAMPTZ NOT NULL, | ||
"dataTypeName" TEXT NOT NULL, | ||
"runId" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "data_pkey" PRIMARY KEY ("time","dataTypeName") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "data_type" ( | ||
"name" TEXT NOT NULL, | ||
"unit" TEXT NOT NULL, | ||
"nodeName" TEXT NOT NULL, | ||
|
||
CONSTRAINT "data_type_pkey" PRIMARY KEY ("name") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "data" ADD CONSTRAINT "data_dataTypeName_fkey" FOREIGN KEY ("dataTypeName") REFERENCES "data_type"("name") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "data" ADD CONSTRAINT "data_runId_fkey" FOREIGN KEY ("runId") REFERENCES "run"("runId") ON DELETE RESTRICT ON UPDATE CASCADE; |
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 (e.g., Git) | ||
provider = "postgresql" |
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 @@ | ||
import { PrismaClient } from "./local-prisma-client"; | ||
|
||
export const prisma = new PrismaClient(); |
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,45 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? | ||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
output = "local-prisma-client" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("LOCAL_DATABASE_URL") | ||
} | ||
|
||
model run { | ||
runId Int @id @default(autoincrement()) | ||
driverName String @default("") | ||
locationName String @default("") | ||
notes String @default("") | ||
time DateTime @db.Timestamptz() | ||
data data[] | ||
} | ||
|
||
model data { | ||
values Float[] @db.Real | ||
time DateTime @db.Timestamptz() | ||
dataTypeName String | ||
dataType data_type @relation(fields: [dataTypeName], references: [name]) | ||
runId Int | ||
run run @relation(fields: [runId], references: [runId]) | ||
@@id([time, dataTypeName]) | ||
} | ||
|
||
model data_type { | ||
name String @id | ||
unit String | ||
nodeName String | ||
data data[] | ||
} |
Oops, something went wrong.