Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds deployment settings to DB (#6706)
* WIP * Adds DeploymentTheme * Add missing migrations * Adds client extensions for deployment * Cleanup
- Loading branch information
Showing
5 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
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,62 @@ | ||
import { Prisma, PrismaClient } from "@prisma/client"; | ||
|
||
export function addPrismaExtensions(prisma: PrismaClient) { | ||
const xprisma = prisma.$extends({ | ||
model: { | ||
/** | ||
* We extend deployment model since it's supposed to be a single record table. | ||
* New settings should be added as Columns as needed. | ||
* */ | ||
deployment: { | ||
/** | ||
* This is the preferred method for accessing deployment settings, | ||
* it can be called without any arguments: | ||
* @example | ||
* ``` | ||
* const deployment = await prisma.deployment.get(); | ||
* ``` | ||
*/ | ||
async get(args?: Omit<Prisma.DeploymentFindUniqueArgs, "where">) { | ||
return prisma.deployment.findUnique({ where: { id: 1 }, ...args }); | ||
}, | ||
async findFirst(args: Omit<Prisma.DeploymentFindFirstArgs, "where">) { | ||
return prisma.deployment.findFirst({ where: { id: 1 }, ...args }); | ||
}, | ||
async findFirstOrThrow(args: Omit<Prisma.DeploymentFindFirstOrThrowArgs, "where">) { | ||
return prisma.deployment.findFirstOrThrow({ where: { id: 1 }, ...args }); | ||
}, | ||
async findUnique(args: Omit<Prisma.DeploymentFindUniqueArgs, "where">) { | ||
return prisma.deployment.findUnique({ where: { id: 1 }, ...args }); | ||
}, | ||
async findUniqueOrThrow(args: Omit<Prisma.DeploymentFindUniqueOrThrowArgs, "where">) { | ||
return prisma.deployment.findUniqueOrThrow({ where: { id: 1 }, ...args }); | ||
}, | ||
async upsert(args: Omit<Prisma.DeploymentUpsertArgs, "where">) { | ||
return prisma.deployment.upsert({ where: { id: 1 }, ...args }); | ||
}, | ||
async update(args: Omit<Prisma.DeploymentUpdateArgs, "where">) { | ||
return prisma.deployment.update({ where: { id: 1 }, ...args }); | ||
}, | ||
async findMany() { | ||
throw new Error("Use prisma.deployment.get method"); | ||
}, | ||
async updateMany() { | ||
throw new Error("Use prisma.deployment.update method"); | ||
}, | ||
async create() { | ||
throw new Error("Use prisma.deployment.upsert method"); | ||
}, | ||
async createMany() { | ||
throw new Error("Use prisma.deployment.upsert method"); | ||
}, | ||
async delete() { | ||
throw new Error("Deployment shouldn't be deleted"); | ||
}, | ||
async deleteMany() { | ||
throw new Error("Deployment shouldn't be deleted"); | ||
}, | ||
}, | ||
}, | ||
}); | ||
return xprisma; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
packages/prisma/migrations/20230125182832_add_deployment/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,10 @@ | ||
-- CreateTable | ||
CREATE TABLE "Deployment" ( | ||
"id" INTEGER NOT NULL DEFAULT 1, | ||
"logo" TEXT, | ||
"theme" JSONB, | ||
"licenseKey" TEXT, | ||
"agreedLicenseAt" TIMESTAMP(3), | ||
|
||
CONSTRAINT "Deployment_pkey" PRIMARY KEY ("id") | ||
); |
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
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