# Migration `20200929195439-fix-segment-folder`

This migration has been generated by Thierry at 9/29/2020, 7:54:39 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql
CREATE TABLE "walter$localhost"."_SegmentsOfFolder" (
"A" text  NOT NULL ,"B" text  NOT NULL )

ALTER TABLE "walter$localhost"."Segment" DROP CONSTRAINT IF EXiSTS "Segment_folderId_fkey",
DROP COLUMN "folderId";

CREATE UNIQUE INDEX "_SegmentsOfFolder_AB_unique" ON "walter$localhost"."_SegmentsOfFolder"("A","B")

CREATE  INDEX "_SegmentsOfFolder_B_index" ON "walter$localhost"."_SegmentsOfFolder"("B")

ALTER TABLE "walter$localhost"."_SegmentsOfFolder" ADD FOREIGN KEY ("A")REFERENCES "walter$localhost"."Folder"("id") ON DELETE CASCADE  ON UPDATE CASCADE

ALTER TABLE "walter$localhost"."_SegmentsOfFolder" ADD FOREIGN KEY ("B")REFERENCES "walter$localhost"."Segment"("id") ON DELETE CASCADE  ON UPDATE CASCADE
```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration 20200923201320-changed-notification-data-to-json..20200929195439-fix-segment-folder
--- datamodel.dml
+++ datamodel.dml
@@ -3,9 +3,9 @@
 }
 datasource postgresql {
   provider = "postgresql"
-  url = "***"
+  url = "***"
 }
 enum RECURRING_TYPE {
   DAILY
@@ -842,9 +842,9 @@
   folderParent        Folder?   @relation("FolderToFolder_folderParent", fields: [folderParentId], references: [id])
   project             Project?  @relation(fields: [projectId], references: [id])
   other_Folder        Folder[]  @relation("FolderToFolder_folderParent")
   files               File[]    @relation("FilesOfFolder")
-  segments            Segment[]
+  segments            Segment[] @relation("SegmentsOfFolder")
 }
 model Invoice {
   id             String   @default(cuid()) @id
@@ -1987,10 +1987,9 @@
   description           String?
   projectId             String?
   isDeleted             Boolean? @default(false)
   project               Project?                @relation(fields: [projectId], references: [id])
-  folderId              String?
-  folder                Folder?                 @relation(fields: [folderId], references: [id])
+  folders               Folder[]                @relation("SegmentsOfFolder")
   amenityBookingOptions AmenityBookingOption[]
   conditions            Condition[]
   events                Event[]
   lockers               Locker[]
@@ -2473,5 +2472,5 @@
   goingEvents                              Event[]                          @relation("UsersGoingToEvent")
   projects                                 Project[]                        @relation("UsersInProject")
   interestedEvents                         Event[]                          @relation("UsersInterestedToEvent")
   packagesSeen                             Package[]                        @relation("UsersThatSeenPackage")
-}
+} 
```


