Skip to content

Commit

Permalink
feat: modified schema to support contributing teams
Browse files Browse the repository at this point in the history
  - maintaining team
  • Loading branch information
madan-ideas2it committed Nov 6, 2023
1 parent 2feb310 commit 1d50379
Show file tree
Hide file tree
Showing 18 changed files with 607 additions and 528 deletions.
600 changes: 277 additions & 323 deletions .forestadmin-schema.json

Large diffs are not rendered by default.

29 changes: 25 additions & 4 deletions apps/web-api/prisma/fixtures/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { faker } from '@faker-js/faker';
import { Prisma, Project } from '@prisma/client';
import { Factory } from 'fishery';
import camelCase from 'lodash/camelCase';
import random from 'lodash/random';
import sample from 'lodash/sample';
import sampleSize from 'lodash/sampleSize';
import { prisma } from './../index';

const getUidsFrom = async (model, where = {}) => {
Expand All @@ -20,7 +22,7 @@ const ProjectFactory = Factory.define<Omit<Project, 'id'>>(
onCreate(async (project) => {
const teamUids = await (await getUidsFrom(Prisma.ModelName.Team))
.map((result) => result.uid);
project.teamUid = sample(teamUids) || '';
project.maintainingTeamUid = sample(teamUids) || '';
const memberUids = await (await getUidsFrom(Prisma.ModelName.Member))
.map((result) => result.uid);
project.createdBy = sample(memberUids) || '';
Expand All @@ -41,7 +43,7 @@ const ProjectFactory = Factory.define<Omit<Project, 'id'>>(
kpis: [{ key: faker.random.word(), value: faker.random.word()}],
readMe: faker.lorem.paragraph(),
createdBy: '',
teamUid: '',
maintainingTeamUid: '',
projectLinks: [{
name: faker.company.name(),
url: faker.internet.url()
Expand All @@ -51,9 +53,28 @@ const ProjectFactory = Factory.define<Omit<Project, 'id'>>(
url: faker.internet.url()
}],
createdAt: faker.date.past(),
updatedAt: faker.date.recent()
updatedAt: faker.date.recent(),
isDeleted: false
};
}
);

export const projects = async () => await ProjectFactory.createList(300);
export const projects = async () => await ProjectFactory.createList(25);

export const projectRelations = async (projects) => {
const teamUids = await getUidsFrom(Prisma.ModelName.Team);

return projects.map((project) => {
const randomTeams = sampleSize(teamUids, random(0, 5));
return {
where: {
uid: project.uid,
},
data: {
...(randomTeams.length && {
contributingTeams: { connect: randomTeams },
})
},
};
});
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Warnings:
- Added the required column `type` to the `Faq` table without a default value. This is not possible if the table is not empty.
- Added the required column `maintainingTeamUid` to the `Project` table without a default value. This is not possible if the table is not empty.
*/

-- DropForeignKey
ALTER TABLE "Project" DROP CONSTRAINT "Project_teamUid_fkey";

-- AlterTable
ALTER TABLE "Faq" ADD COLUMN "type" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "Project" DROP COLUMN "teamUid",
ADD COLUMN "isDeleted" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "maintainingTeamUid" TEXT NOT NULL;

-- CreateTable
CREATE TABLE "ProjectContribution" (
"id" SERIAL NOT NULL,
"uid" TEXT NOT NULL,
"role" TEXT,
"description" TEXT,
"currentProject" BOOLEAN NOT NULL DEFAULT false,
"startDate" TIMESTAMP(3) NOT NULL,
"endDate" TIMESTAMP(3),
"memberUid" TEXT NOT NULL,
"projectUid" TEXT NOT NULL,

CONSTRAINT "ProjectContribution_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "_contributingTeams" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "ProjectContribution_uid_key" ON "ProjectContribution"("uid");

-- CreateIndex
CREATE UNIQUE INDEX "_contributingTeams_AB_unique" ON "_contributingTeams"("A", "B");

-- CreateIndex
CREATE INDEX "_contributingTeams_B_index" ON "_contributingTeams"("B");

-- AddForeignKey
ALTER TABLE "ProjectContribution" ADD CONSTRAINT "ProjectContribution_memberUid_fkey" FOREIGN KEY ("memberUid") REFERENCES "Member"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ProjectContribution" ADD CONSTRAINT "ProjectContribution_projectUid_fkey" FOREIGN KEY ("projectUid") REFERENCES "Project"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Project" ADD CONSTRAINT "Project_maintainingTeamUid_fkey" FOREIGN KEY ("maintainingTeamUid") REFERENCES "Team"("uid") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_contributingTeams" ADD CONSTRAINT "_contributingTeams_A_fkey" FOREIGN KEY ("A") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_contributingTeams" ADD CONSTRAINT "_contributingTeams_B_fkey" FOREIGN KEY ("B") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
211 changes: 107 additions & 104 deletions apps/web-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,64 @@ datasource db {
/// TODO: User permissions/grants

model Team {
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
name String @unique
logo Image? @relation(fields: [logoUid], references: [uid])
logoUid String?
blog String?
officeHours String?
website String?
contactMethod String?
twitterHandler String?
linkedinHandler String?
telegramHandler String?
shortDescription String?
longDescription String?
plnFriend Boolean @default(false)
airtableRecId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
teamMemberRoles TeamMemberRole[]
industryTags IndustryTag[]
membershipSources MembershipSource[]
fundingStage FundingStage? @relation(fields: [fundingStageUid], references: [uid])
fundingStageUid String?
technologies Technology[]
moreDetails String?
Project Project[]
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
name String @unique
logo Image? @relation(fields: [logoUid], references: [uid])
logoUid String?
blog String?
officeHours String?
website String?
contactMethod String?
twitterHandler String?
linkedinHandler String?
telegramHandler String?
shortDescription String?
longDescription String?
plnFriend Boolean @default(false)
airtableRecId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
teamMemberRoles TeamMemberRole[]
industryTags IndustryTag[]
membershipSources MembershipSource[]
fundingStage FundingStage? @relation(fields: [fundingStageUid], references: [uid])
fundingStageUid String?
technologies Technology[]
moreDetails String?
maintainingProjects Project[] @relation("maintainingTeam")
contributingProjects Project[] @relation("contributingTeams")
}

model Member {
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
name String
email String? @unique
image Image? @relation(fields: [imageUid], references: [uid])
imageUid String?
githubHandler String?
discordHandler String?
twitterHandler String?
linkedinHandler String?
telegramHandler String?
officeHours String?
moreDetails String?
plnFriend Boolean @default(false)
plnStartDate DateTime?
airtableRecId String? @unique
externalId String? @unique
openToWork Boolean? @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
skills Skill[]
location Location? @relation(fields: [locationUid], references: [uid])
locationUid String?
teamMemberRoles TeamMemberRole[]
memberRoles MemberRole[]
preferences Json?
experience Experience[]
Project Project[]
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
name String
email String? @unique
image Image? @relation(fields: [imageUid], references: [uid])
imageUid String?
githubHandler String?
discordHandler String?
twitterHandler String?
linkedinHandler String?
telegramHandler String?
officeHours String?
moreDetails String?
plnFriend Boolean @default(false)
plnStartDate DateTime?
airtableRecId String? @unique
externalId String? @unique
openToWork Boolean? @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
skills Skill[]
location Location? @relation(fields: [locationUid], references: [uid])
locationUid String?
teamMemberRoles TeamMemberRole[]
memberRoles MemberRole[]
preferences Json?
projectContributions ProjectContribution[]
projects Project[]
}

model MemberRole {
Expand Down Expand Up @@ -206,52 +207,51 @@ model Technology {
}

model Image {
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
// The cid is not unique because this id represents an array of multiple images
// with different sizes that can be accessed trough the cid and filename
cid String
width Int
height Int
url String
filename String
size Int
type String
version ImageSize
cid String
width Int
height Int
url String
filename String
size Int
type String
version ImageSize
// This image can be a thumbnail to other image
thumbnailToUid String?
thumbnailTo Image? @relation("ImageThumbnails", fields: [thumbnailToUid], references: [uid])
thumbnailToUid String?
thumbnailTo Image? @relation("ImageThumbnails", fields: [thumbnailToUid], references: [uid])
// This image can have multiple thumbnails
thumbnails Image[] @relation("ImageThumbnails")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
thumbnails Image[] @relation("ImageThumbnails")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Reverse Relations:
Team Team[]
Member Member[]
Project Project[]
Experience Experience[]
Team Team[]
Member Member[]
Project Project[]
}

model Experience {
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
companyName String
logoUid String?
companyLogo Image? @relation(fields: [logoUid], references: [uid])
title String
currentTeam Boolean @default(false)
startDate DateTime
endDate DateTime?
description String?
memberUid String
member Member? @relation(fields: [memberUid], references: [uid])
model ProjectContribution {
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
role String?
description String?
currentProject Boolean @default(false)
startDate DateTime
endDate DateTime?
memberUid String
member Member? @relation(fields: [memberUid], references: [uid])
projectUid String
project Project? @relation(fields: [projectUid], references: [uid])
}

model Faq {
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
email String @db.VarChar(100)
question String
type String
requestIp String @db.VarChar(35)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand All @@ -267,24 +267,27 @@ model JoinRequest {
}

model Project {
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
logo Image? @relation(fields: [logoUid], references: [uid])
logoUid String?
name String
tagline String
description String
contactEmail String
lookingForFunding Boolean @default(false)
projectLinks Json?
kpis Json?
readMe String?
creator Member? @relation(fields: [createdBy], references: [uid])
createdBy String
team Team? @relation(fields: [teamUid], references: [uid])
teamUid String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
id Int @id @default(autoincrement())
uid String @unique @default(cuid())
logo Image? @relation(fields: [logoUid], references: [uid])
logoUid String?
name String
tagline String
description String
contactEmail String
lookingForFunding Boolean @default(false)
projectLinks Json?
kpis Json?
readMe String?
creator Member? @relation(fields: [createdBy], references: [uid])
createdBy String
maintainingTeam Team? @relation("maintainingTeam", fields: [maintainingTeamUid], references: [uid])
maintainingTeamUid String
contributingTeams Team[] @relation("contributingTeams")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectContributions ProjectContribution[]
isDeleted Boolean @default(false)
}

enum ImageSize {
Expand Down
Loading

0 comments on commit 1d50379

Please sign in to comment.