Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
976 B ยท 37 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738import { eq, isNull, or, sql } from "@openstatus/db";import { externalService } from "@openstatus/db/src/schema";
import type { DB } from "../context";import { ConflictError } from "../errors";
export type GlobalReadContext = { db?: DB;};
export async function assertSlugAvailable(args: { tx: DB; slug: string; exceptServiceId?: number;}): Promise<void> { const { tx, slug, exceptServiceId } = args; const rows = await tx .select({ id: externalService.id }) .from(externalService) .where( or( eq(externalService.slug, slug), sql`EXISTS (SELECT 1 FROM json_each(${externalService.aliases}) WHERE value = ${slug})`, ), ) .all(); const conflicts = exceptServiceId ? rows.filter((r) => r.id !== exceptServiceId) : rows; if (conflicts.length > 0) { throw new ConflictError(`slug "${slug}" is already in use`); }}
export function liveOnlyClause() { return isNull(externalService.deletedAt);}