Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modified schema to support contributing teams #1481

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
526 changes: 315 additions & 211 deletions .forestadmin-schema.json

Large diffs are not rendered by default.

31 changes: 26 additions & 5 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 @@ -36,12 +38,12 @@ const ProjectFactory = Factory.define<Omit<Project, 'id'>>(
name: name,
tagline: faker.lorem.words(3),
description: faker.lorem.paragraph(),
contactEmail: faker.internet.email(),
contactEmail: faker.internet.email().toLowerCase(),
lookingForFunding: false,
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;
Loading