From 480524aafda6b5499d651b496281c999f3b83c59 Mon Sep 17 00:00:00 2001 From: Alexander Petkov Date: Tue, 24 Oct 2023 17:21:35 +0300 Subject: [PATCH] schema.prisma:Affiliate: Make companyId not null --- .../affiliate/entities/affiliate.entity.ts | 4 ++-- .../migration.sql | 14 ++++++++++++++ schema.prisma | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 migrations/20231024142056_affiliate_make_company_id_not_null/migration.sql diff --git a/apps/api/src/domain/generated/affiliate/entities/affiliate.entity.ts b/apps/api/src/domain/generated/affiliate/entities/affiliate.entity.ts index 3b9e70f74..98e2a43cd 100644 --- a/apps/api/src/domain/generated/affiliate/entities/affiliate.entity.ts +++ b/apps/api/src/domain/generated/affiliate/entities/affiliate.entity.ts @@ -6,7 +6,7 @@ export class Affiliate { id: string status: AffiliateStatus affiliateCode: string | null - companyId: string | null - company?: Company | null + companyId: string + company?: Company donations?: Donation[] } diff --git a/migrations/20231024142056_affiliate_make_company_id_not_null/migration.sql b/migrations/20231024142056_affiliate_make_company_id_not_null/migration.sql new file mode 100644 index 000000000..aec1f9ec3 --- /dev/null +++ b/migrations/20231024142056_affiliate_make_company_id_not_null/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - Made the column `company_id` on table `affiliates` required. This step will fail if there are existing NULL values in that column. + +*/ +-- DropForeignKey +ALTER TABLE "affiliates" DROP CONSTRAINT "affiliates_company_id_fkey"; + +-- AlterTable +ALTER TABLE "affiliates" ALTER COLUMN "company_id" SET NOT NULL; + +-- AddForeignKey +ALTER TABLE "affiliates" ADD CONSTRAINT "affiliates_company_id_fkey" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/schema.prisma b/schema.prisma index c84df7c0c..0d13801f9 100644 --- a/schema.prisma +++ b/schema.prisma @@ -102,8 +102,8 @@ model Affiliate { id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid status AffiliateStatus @default(pending) affiliateCode String? @unique @map("affiliate_code") - companyId String? @unique @map("company_id") @db.Uuid - company Company? @relation(fields: [companyId], references: [id]) + companyId String @unique @map("company_id") @db.Uuid + company Company @relation(fields: [companyId], references: [id]) donations Donation[] @@map("affiliates")