-
Notifications
You must be signed in to change notification settings - Fork 3
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 #56 from ResidenciaTICBrisa/anaju
feat: prisma
- Loading branch information
Showing
6 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
backend/prisma/migrations/20240415134546_gloria/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,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; |
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 = "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,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 | ||
} |
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; |