change relation

This commit is contained in:
Thomas Ruoff
2022-10-12 22:44:58 +02:00
parent a9ca3439d2
commit 0e4f3a5c90
2 changed files with 35 additions and 4 deletions

View File

@@ -0,0 +1,31 @@
/*
Warnings:
- The primary key for the `Booking` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `billId` on the `Booking` table. All the data in the column will be lost.
- The `id` column on the `Booking` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- A unique constraint covering the columns `[bookingId]` on the table `Bill` will be added. If there are existing duplicate values, this will fail.
- Added the required column `bookingId` to the `Bill` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "Booking" DROP CONSTRAINT "Booking_billId_fkey";
-- DropIndex
DROP INDEX "Booking_billId_key";
-- AlterTable
ALTER TABLE "Bill" ADD COLUMN "bookingId" INTEGER NOT NULL;
-- AlterTable
ALTER TABLE "Booking" DROP CONSTRAINT "Booking_pkey",
DROP COLUMN "billId",
DROP COLUMN "id",
ADD COLUMN "id" SERIAL NOT NULL,
ADD CONSTRAINT "Booking_pkey" PRIMARY KEY ("id");
-- CreateIndex
CREATE UNIQUE INDEX "Bill_bookingId_key" ON "Bill"("bookingId");
-- AddForeignKey
ALTER TABLE "Bill" ADD CONSTRAINT "Bill_bookingId_fkey" FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -29,7 +29,8 @@ model Bill {
status BillStatus @default(UNINVOICED)
tarif Decimal
additionalCosts AdditionalCosts[]
booking Booking?
booking Booking @relation(fields: [bookingId], references: [id])
bookingId Int @unique
}
enum BookingStatus {
@@ -40,12 +41,11 @@ enum BookingStatus {
}
model Booking {
id String @id @default(uuid())
id Int @id @default(autoincrement())
uuid String @unique @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
bill Bill? @relation(fields: [billId], references: [id], onDelete: Cascade)
billId Int? @unique
bill Bill?
calendarEventId String?
city String
destination String