Skip to content

Commit f8b9296

Browse files
committed
feat(api): added certification_authority_on_certification_authority_structure table and data migration
1 parent da4f50f commit f8b9296

File tree

2 files changed

+76
-2
lines changed
  • packages/reva-api/prisma
    • migrations/20241202140942_add_many_to_many_relashionship_between_certification_authority_and_certification_authority_structure

2 files changed

+76
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
-- CreateTable
2+
CREATE TABLE
3+
"certification_authority_on_certification_authority_structure" (
4+
"id" UUID NOT NULL DEFAULT uuid_generate_v4 (),
5+
"certification_authority_id" UUID NOT NULL,
6+
"certification_authority_structure_id" UUID NOT NULL,
7+
"created_at" TIMESTAMPTZ (6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"updated_at" TIMESTAMPTZ (6),
9+
CONSTRAINT "certification_authority_on_certification_authority_structu_pkey" PRIMARY KEY ("id")
10+
);
11+
12+
-- CreateIndex
13+
CREATE UNIQUE INDEX "certification_authority_on_certification_authority_structur_key" ON "certification_authority_on_certification_authority_structure" (
14+
"certification_authority_id",
15+
"certification_authority_structure_id"
16+
);
17+
18+
-- AddForeignKey
19+
ALTER TABLE "certification_authority_on_certification_authority_structure" ADD CONSTRAINT "ca_on_cas_ca" FOREIGN KEY ("certification_authority_id") REFERENCES "certification_authority" ("id") ON DELETE CASCADE ON UPDATE CASCADE;
20+
21+
-- AddForeignKey
22+
ALTER TABLE "certification_authority_on_certification_authority_structure" ADD CONSTRAINT "ca_on_cas_cas" FOREIGN KEY ("certification_authority_structure_id") REFERENCES "certification_authority_structure" ("id") ON DELETE CASCADE ON UPDATE CASCADE;
23+
24+
-- Migrate all existing certification_authority to certification_authority_on_certification_authority_structure relatuionships
25+
INSERT INTO
26+
"certification_authority_on_certification_authority_structure" (
27+
"certification_authority_id",
28+
"certification_authority_structure_id"
29+
)
30+
SELECT
31+
"id",
32+
"certification_authority_structure_id"
33+
FROM
34+
"certification_authority";
35+
36+
-- Add certification_authority certification_authority_structure relationships based on certification_authorities certifications
37+
INSERT INTO
38+
"certification_authority_on_certification_authority_structure" (
39+
"certification_authority_id",
40+
"certification_authority_structure_id"
41+
)
42+
SELECT DISTINCT
43+
"certification_authority"."id",
44+
"certification"."certification_authority_structure_id"
45+
FROM
46+
"certification_authority"
47+
JOIN "certification_authority_on_certification" ON "certification_authority_on_certification"."certification_authority_id" = "certification_authority"."id"
48+
JOIN "certification" ON "certification"."id" = "certification_authority_on_certification"."certification_id"
49+
WHERE
50+
(
51+
"certification_authority"."id",
52+
"certification"."certification_authority_structure_id"
53+
) NOT IN (
54+
SELECT
55+
"certification_authority_id",
56+
"certification_authority_structure_id"
57+
FROM
58+
"certification_authority_on_certification_authority_structure"
59+
);

packages/reva-api/prisma/schema.prisma

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,8 @@ model CertificationAuthorityStructure {
915915
certifications Certification[]
916916
oldCertificationAuthorities CertificationAuthority[] @relation("old_certification_authority_on_certification_authority_structure")
917917
918-
certificationRegistryManager CertificationRegistryManager?
918+
certificationRegistryManager CertificationRegistryManager?
919+
certificationAuthorityStructureOnCertificationAuthorityStructure CertificationAuthorityOnCertificationAuthorityStructure[]
919920
920921
@@map("certification_authority_structure")
921922
}
@@ -937,11 +938,25 @@ model CertificationAuthority {
937938
oldCertificationAuthorityStructure CertificationAuthorityStructure @relation(fields: [oldCertificationAuthorityStructureId], references: [id], onDelete: Restrict, name: "old_certification_authority_on_certification_authority_structure")
938939
oldCertificationAuthorityStructureId String @map("certification_authority_structure_id") @db.Uuid
939940
940-
showLocalAccountsContactInfo Boolean @default(true) @map("show_local_accounts_contact_info")
941+
showLocalAccountsContactInfo Boolean @default(true) @map("show_local_accounts_contact_info")
942+
certificationAuthorityOnCertificationAuthorityStructure CertificationAuthorityOnCertificationAuthorityStructure[]
941943
942944
@@map("certification_authority")
943945
}
944946

947+
model CertificationAuthorityOnCertificationAuthorityStructure {
948+
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
949+
certificationAuthority CertificationAuthority @relation(map: "ca_on_cas_ca", fields: [certificationAuthorityId], references: [id], onDelete: Cascade)
950+
certificationAuthorityId String @map("certification_authority_id") @db.Uuid
951+
certificationAuthorityStructure CertificationAuthorityStructure @relation(map: "ca_on_cas_cas", fields: [certificationAuthorityStructureId], references: [id], onDelete: Cascade)
952+
certificationAuthorityStructureId String @map("certification_authority_structure_id") @db.Uuid
953+
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
954+
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
955+
956+
@@unique([certificationAuthorityId, certificationAuthorityStructureId])
957+
@@map("certification_authority_on_certification_authority_structure")
958+
}
959+
945960
model CertificationRegistryManager {
946961
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
947962
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)

0 commit comments

Comments
 (0)