Skip to content

Commit

Permalink
Merge pull request #56 from ResidenciaTICBrisa/anaju
Browse files Browse the repository at this point in the history
feat: prisma
  • Loading branch information
anajbsouza authored Apr 15, 2024
2 parents 4aa80c2 + cad157d commit 4ec18dd
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
80 changes: 80 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
"@types/node": "^20.11.25",
"dotenv": "^16.4.5",
"nodemon": "^3.1.0",
"prisma": "^5.12.1",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.2",
"typescript-transform-paths": "^3.4.7"
},
"dependencies": {
"@prisma/client": "^5.12.1",
"@types/bcrypt": "^5.0.2",
"@types/cors": "^2.8.17",
"@types/jsonwebtoken": "^9.0.6",
Expand Down
59 changes: 59 additions & 0 deletions backend/prisma/migrations/20240415134546_gloria/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- CreateTable
CREATE TABLE "Occurrence" (
"id_occurrence" BIGSERIAL NOT NULL,
"id_user" TEXT NOT NULL,
"datetime_submission" TIMESTAMPTZ(6) NOT NULL,
"date_violence" DATE NOT NULL,
"timewindow_violence" TEXT NOT NULL,
"agegroup" TEXT NOT NULL,
"latitude" DOUBLE PRECISION NOT NULL,
"longitude" DOUBLE PRECISION NOT NULL,
"violencesoptions" TEXT NOT NULL,
"violencetype" TEXT,

CONSTRAINT "Occurrence_pkey" PRIMARY KEY ("id_occurrence")
);

-- CreateTable
CREATE TABLE "TypesOfViolence" (
"id_violencetype" TEXT NOT NULL,
"Description" TEXT NOT NULL,

CONSTRAINT "TypesOfViolence_pkey" PRIMARY KEY ("id_violencetype")
);

-- CreateTable
CREATE TABLE "User" (
"id_user" TEXT NOT NULL,

CONSTRAINT "User_pkey" PRIMARY KEY ("id_user")
);

-- CreateTable
CREATE TABLE "UserOccurrences" (
"id_occurrence" BIGINT NOT NULL,
"id_user" TEXT NOT NULL,
"date_violence" DATE NOT NULL,

CONSTRAINT "UserOccurrences_pkey" PRIMARY KEY ("id_occurrence")
);

-- CreateTable
CREATE TABLE "ViolenceSituations" (
"id_violenceoption" TEXT NOT NULL,
"Description" TEXT NOT NULL,

CONSTRAINT "ViolenceSituations_pkey" PRIMARY KEY ("id_violenceoption")
);

-- AddForeignKey
ALTER TABLE "Occurrence" ADD CONSTRAINT "Occurrence_fk1" FOREIGN KEY ("id_user") REFERENCES "User"("id_user") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "Occurrence" ADD CONSTRAINT "Occurrence_fk9" FOREIGN KEY ("violencetype") REFERENCES "TypesOfViolence"("id_violencetype") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "UserOccurrences" ADD CONSTRAINT "UserOccurrences_fk0" FOREIGN KEY ("id_occurrence") REFERENCES "Occurrence"("id_occurrence") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- AddForeignKey
ALTER TABLE "UserOccurrences" ADD CONSTRAINT "UserOccurrences_fk1" FOREIGN KEY ("id_user") REFERENCES "User"("id_user") ON DELETE NO ACTION ON UPDATE NO ACTION;
3 changes: 3 additions & 0 deletions backend/prisma/migrations/migration_lock.toml
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 = "postgresql"
49 changes: 49 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Occurrence {
id_occurrence BigInt @id @default(autoincrement())
id_user String
datetime_submission DateTime @db.Timestamptz(6)
date_violence DateTime @db.Date
timewindow_violence String
agegroup String
latitude Float
longitude Float
violencesoptions String
violencetype String?
User User @relation(fields: [id_user], references: [id_user], onDelete: NoAction, onUpdate: NoAction, map: "Occurrence_fk1")
TypesOfViolence TypesOfViolence? @relation(fields: [violencetype], references: [id_violencetype], onDelete: NoAction, onUpdate: NoAction, map: "Occurrence_fk9")
UserOccurrences UserOccurrences?
}

model TypesOfViolence {
id_violencetype String @id
Description String
Occurrence Occurrence[]
}

model User {
id_user String @id
Occurrence Occurrence[]
UserOccurrences UserOccurrences[]
}

model UserOccurrences {
id_occurrence BigInt @id
id_user String
date_violence DateTime @db.Date
Occurrence Occurrence @relation(fields: [id_occurrence], references: [id_occurrence], onDelete: NoAction, onUpdate: NoAction, map: "UserOccurrences_fk0")
User User @relation(fields: [id_user], references: [id_user], onDelete: NoAction, onUpdate: NoAction, map: "UserOccurrences_fk1")
}

model ViolenceSituations {
id_violenceoption String @id
Description String
}
4 changes: 4 additions & 0 deletions backend/src/database.ts
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;

0 comments on commit 4ec18dd

Please sign in to comment.