-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,167 additions
and
157 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
prisma/migrations/20230214212125_add_tags_and_refactor_names/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `contact_link` on the `ContactMethods` table. All the data in the column will be lost. | ||
- You are about to drop the column `contact_type` on the `ContactMethods` table. All the data in the column will be lost. | ||
- You are about to drop the column `organization_id` on the `ContactMethods` table. All the data in the column will be lost. | ||
- You are about to drop the column `email_address` on the `Managers` table. All the data in the column will be lost. | ||
- You are about to drop the column `organization_id` on the `Managers` table. All the data in the column will be lost. | ||
- You are about to drop the column `foundation_date` on the `Organization` table. All the data in the column will be lost. | ||
- You are about to drop the column `long_description` on the `Organization` table. All the data in the column will be lost. | ||
- You are about to drop the column `number_of_users` on the `Organization` table. All the data in the column will be lost. | ||
- You are about to drop the column `owner_id` on the `Organization` table. All the data in the column will be lost. | ||
- You are about to drop the column `organization_id` on the `Projects` table. All the data in the column will be lost. | ||
- A unique constraint covering the columns `[slug]` on the table `Organization` will be added. If there are existing duplicate values, this will fail. | ||
- A unique constraint covering the columns `[ownerId]` on the table `Organization` will be added. If there are existing duplicate values, this will fail. | ||
- Added the required column `contactLink` to the `ContactMethods` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `contactType` to the `ContactMethods` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `organizationId` to the `ContactMethods` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `organizationId` to the `Managers` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `foundationDate` to the `Organization` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `longDescription` to the `Organization` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `numberOfUsers` to the `Organization` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `ownerId` to the `Organization` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `slug` to the `Organization` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `organizationId` to the `Projects` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "ContactMethods" DROP CONSTRAINT "ContactMethods_organization_id_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Managers" DROP CONSTRAINT "Managers_organization_id_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Organization" DROP CONSTRAINT "Organization_owner_id_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Projects" DROP CONSTRAINT "Projects_organization_id_fkey"; | ||
|
||
-- DropIndex | ||
DROP INDEX "Organization_owner_id_key"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "ContactMethods" DROP COLUMN "contact_link", | ||
DROP COLUMN "contact_type", | ||
DROP COLUMN "organization_id", | ||
ADD COLUMN "contactLink" TEXT NOT NULL, | ||
ADD COLUMN "contactType" TEXT NOT NULL, | ||
ADD COLUMN "organizationId" TEXT NOT NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Managers" DROP COLUMN "email_address", | ||
DROP COLUMN "organization_id", | ||
ADD COLUMN "email" TEXT, | ||
ADD COLUMN "organizationId" TEXT NOT NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Organization" DROP COLUMN "foundation_date", | ||
DROP COLUMN "long_description", | ||
DROP COLUMN "number_of_users", | ||
DROP COLUMN "owner_id", | ||
ADD COLUMN "foundationDate" TIMESTAMP(3) NOT NULL, | ||
ADD COLUMN "longDescription" TEXT NOT NULL, | ||
ADD COLUMN "numberOfUsers" INTEGER NOT NULL, | ||
ADD COLUMN "ownerId" TEXT NOT NULL, | ||
ADD COLUMN "slug" TEXT NOT NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Projects" DROP COLUMN "organization_id", | ||
ADD COLUMN "organizationId" TEXT NOT NULL; | ||
|
||
-- CreateTable | ||
CREATE TABLE "Tag" ( | ||
"id" TEXT NOT NULL, | ||
"text" TEXT NOT NULL, | ||
|
||
CONSTRAINT "Tag_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "_OrganizationToTag" ( | ||
"A" TEXT NOT NULL, | ||
"B" TEXT NOT NULL | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Tag_text_key" ON "Tag"("text"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "_OrganizationToTag_AB_unique" ON "_OrganizationToTag"("A", "B"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "_OrganizationToTag_B_index" ON "_OrganizationToTag"("B"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Organization_slug_key" ON "Organization"("slug"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Organization_ownerId_key" ON "Organization"("ownerId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ContactMethods" ADD CONSTRAINT "ContactMethods_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Projects" ADD CONSTRAINT "Projects_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Managers" ADD CONSTRAINT "Managers_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Organization" ADD CONSTRAINT "Organization_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_OrganizationToTag" ADD CONSTRAINT "_OrganizationToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_OrganizationToTag" ADD CONSTRAINT "_OrganizationToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "Tag"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
5 changes: 5 additions & 0 deletions
5
prisma/migrations/20230214212354_add_cascade_delete_to_managers/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "Managers" DROP CONSTRAINT "Managers_organizationId_fkey"; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Managers" ADD CONSTRAINT "Managers_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { faker } from "@faker-js/faker/locale/pl"; | ||
import type { Prisma } from "@prisma/client"; | ||
|
||
const contactTypes = ["Facebook", "Instagram", "Website", "Email"]; | ||
|
||
export const contactMethodFactory = ( | ||
props?: Partial<Prisma.ContactMethodsCreateInput> | ||
): Omit<Prisma.ContactMethodsCreateInput, "organization"> => { | ||
return { | ||
contactLink: faker.internet.url(), | ||
contactType: faker.helpers.arrayElement(contactTypes), | ||
...props, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { faker } from "@faker-js/faker/locale/pl"; | ||
import type { Prisma } from "@prisma/client"; | ||
|
||
export const managerFactory = ( | ||
props?: Partial<Prisma.ManagersCreateInput> | ||
): Omit<Prisma.ManagersCreateInput, "organization"> => { | ||
const firstName = faker.name.firstName(); | ||
const lastName = faker.name.lastName(); | ||
|
||
return { | ||
name: firstName + " " + lastName, | ||
email: faker.internet.email(firstName, lastName), | ||
...props, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { faker } from "@faker-js/faker/locale/pl"; | ||
import type { Prisma } from "@prisma/client"; | ||
import slugify from "slugify"; | ||
import { contactMethodFactory } from "./contactMethod.factory"; | ||
import { managerFactory } from "./manager.factory"; | ||
import { projectFactory } from "./project.factory"; | ||
import { tagFactory } from "./tag.factory"; | ||
import { userFactory } from "./user.factory"; | ||
|
||
const departments = [ | ||
"W1", | ||
"W2", | ||
"W3", | ||
"W4", | ||
"W5", | ||
"W6", | ||
"W7", | ||
"W8", | ||
"W9", | ||
"W10", | ||
"W11", | ||
"W12", | ||
]; | ||
|
||
export const organizationFactory = ( | ||
props?: Partial<Prisma.OrganizationCreateInput> | ||
): Prisma.OrganizationCreateInput => { | ||
const name = faker.company.name(); | ||
|
||
const tags = Array.from({ | ||
length: faker.datatype.number({ min: 1, max: 6 }), | ||
}).map(() => tagFactory()); | ||
|
||
return { | ||
name, | ||
description: faker.commerce.productDescription(), | ||
longDescription: faker.lorem.paragraphs(9), | ||
createdAt: faker.date.past(), | ||
slug: slugify(name) + faker.random.numeric(4), | ||
numberOfUsers: faker.datatype.number(100), | ||
foundationDate: faker.date.past(), | ||
residence: faker.helpers.arrayElement(departments), | ||
owner: { | ||
create: userFactory({ role: "OWNER" }), | ||
}, | ||
Tags: { | ||
connectOrCreate: tags.map((tag) => ({ | ||
where: { | ||
text: tag.text, | ||
}, | ||
create: tag, | ||
})), | ||
}, | ||
ContactMethods: { | ||
create: Array.from({ length: 3 }).map(() => contactMethodFactory()), | ||
}, | ||
Managers: { | ||
createMany: { | ||
data: Array.from({ length: 3 }).map(() => managerFactory()), | ||
}, | ||
}, | ||
Projects: { | ||
createMany: { | ||
data: Array.from({ | ||
length: faker.datatype.number({ min: 0, max: 4 }), | ||
}).map(() => projectFactory()), | ||
}, | ||
}, | ||
...props, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { faker } from "@faker-js/faker/locale/pl"; | ||
import type { Prisma } from "@prisma/client"; | ||
|
||
export const projectFactory = ( | ||
props?: Partial<Prisma.ProjectsCreateInput> | ||
): Omit<Prisma.ProjectsCreateInput, "organization"> => { | ||
return { | ||
name: faker.company.name(), | ||
description: faker.commerce.productDescription(), | ||
...props, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { faker } from "@faker-js/faker/locale/pl"; | ||
import type { Prisma } from "@prisma/client"; | ||
|
||
const tags = [ | ||
"Druk3D", | ||
"Piwo", | ||
"Fotografia", | ||
"Programowanie", | ||
"Muzyka", | ||
"Taniec", | ||
"Kultura", | ||
"Sport", | ||
]; | ||
|
||
export const tagFactory = ( | ||
props?: Partial<Prisma.TagCreateInput> | ||
): Prisma.TagCreateInput => { | ||
return { | ||
text: faker.helpers.arrayElement(tags), | ||
...props, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { faker } from "@faker-js/faker/locale/pl"; | ||
import type { Prisma } from "@prisma/client"; | ||
|
||
export const userFactory = ( | ||
props?: Partial<Prisma.UserCreateInput> | ||
): Prisma.UserCreateInput => { | ||
const firstName = faker.name.firstName(); | ||
const lastName = faker.name.lastName(); | ||
|
||
return { | ||
name: firstName + " " + lastName, | ||
email: faker.internet.email(firstName, lastName), | ||
role: "USER", | ||
...props, | ||
}; | ||
}; |
Oops, something went wrong.