diff --git a/prisma/migrations/20221012204442_change_relation/migration.sql b/prisma/migrations/20221012204442_change_relation/migration.sql new file mode 100644 index 0000000..dc048b6 --- /dev/null +++ b/prisma/migrations/20221012204442_change_relation/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 526f0e9..321b5e7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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