Skip to content
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
52 changes: 52 additions & 0 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and Push Crove Cal Docker Image

on:
push:
branches:
- dev
- main
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Downcase repository owner for image name
id: image-name
run: |
IMAGE_NAME="ghcr.io/${{ github.repository }}"
echo "image_name=${IMAGE_NAME,,}" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ steps.image-name.outputs.image_name }}:latest
${{ steps.image-name.outputs.image_name }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
NEXT_PUBLIC_API_V2_URL=http://localhost:5555/api/v2
NEXT_PUBLIC_LICENSE_CONSENT=agree
CALCOM_TELEMETRY_DISABLED=1
18 changes: 16 additions & 2 deletions apps/api/v2/src/modules/prisma/prisma-read.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import { Pool } from "pg";

const DB_MAX_POOL_CONNECTION = 10;

function getSchemaFromUrl(url: string | undefined): string | undefined {
if (!url) return undefined;
try {
const parsed = new URL(url.replace(/^postgresql:\/\//, "http://").replace(/^postgres:\/\//, "http://"));
return parsed.searchParams.get("schema") || undefined;
} catch {
const match = url.match(/[?&]schema=([^&]+)/);
return match ? match[1] : undefined;
}
}

@Injectable()
export class PrismaReadService implements OnModuleInit, OnModuleDestroy {
private logger = new Logger("PrismaReadService");
Expand Down Expand Up @@ -39,6 +50,9 @@ export class PrismaReadService implements OnModuleInit, OnModuleDestroy {
const isE2E = options.e2e ?? false;
const usePool = options.usePool ?? true;

const schema = getSchemaFromUrl(dbUrl);
const adapterOptions = schema ? { schema } : undefined;

if (usePool) {
let maxReadConnections = options.maxReadConnections ?? DB_MAX_POOL_CONNECTION;
if (isE2E) {
Expand All @@ -51,10 +65,10 @@ export class PrismaReadService implements OnModuleInit, OnModuleDestroy {
idleTimeoutMillis: 300000,
});

const adapter = new PrismaPg(this.pool);
const adapter = new PrismaPg(this.pool, adapterOptions);
this.prisma = new PrismaClient({ adapter });
} else {
const adapter = new PrismaPg({ connectionString: dbUrl });
const adapter = new PrismaPg({ connectionString: dbUrl }, adapterOptions);
this.prisma = new PrismaClient({
adapter,
});
Expand Down
18 changes: 16 additions & 2 deletions apps/api/v2/src/modules/prisma/prisma-write.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ export interface PrismaServiceOptions {
type: "main" | "worker";
}

function getSchemaFromUrl(url: string | undefined): string | undefined {
if (!url) return undefined;
try {
const parsed = new URL(url.replace(/^postgresql:\/\//, "http://").replace(/^postgres:\/\//, "http://"));
return parsed.searchParams.get("schema") || undefined;
} catch {
const match = url.match(/[?&]schema=([^&]+)/);
return match ? match[1] : undefined;
}
}

@Injectable()
export class PrismaWriteService implements OnModuleInit, OnModuleDestroy {
private logger = new Logger("PrismaWriteService");
Expand Down Expand Up @@ -45,6 +56,9 @@ export class PrismaWriteService implements OnModuleInit, OnModuleDestroy {
const isE2E = options.e2e ?? false;
const usePool = options.usePool ?? true;

const schema = getSchemaFromUrl(dbUrl);
const adapterOptions = schema ? { schema } : undefined;

if (usePool) {
let maxWriteConnections = options.maxWriteConnections ?? DB_MAX_POOL_CONNECTION;
if (isE2E) {
Expand All @@ -57,10 +71,10 @@ export class PrismaWriteService implements OnModuleInit, OnModuleDestroy {
idleTimeoutMillis: 300000,
});

const adapter = new PrismaPg(this.pool);
const adapter = new PrismaPg(this.pool, adapterOptions);
this.prisma = new PrismaClient({ adapter });
} else {
const adapter = new PrismaPg({ connectionString: dbUrl });
const adapter = new PrismaPg({ connectionString: dbUrl }, adapterOptions);
this.prisma = new PrismaClient({
adapter,
});
Expand Down
22 changes: 20 additions & 2 deletions packages/prisma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ import { excludeLockedUsersExtension } from "./extensions/exclude-locked-users";
import { excludePendingPaymentsExtension } from "./extensions/exclude-pending-payment-teams";
import { PrismaClient, type Prisma } from "./generated/prisma/client";

function getSchemaFromUrl(url: string | undefined): string | undefined {
if (!url) return undefined;
try {
const parsed = new URL(url.replace(/^postgresql:\/\//, "http://").replace(/^postgres:\/\//, "http://"));
return parsed.searchParams.get("schema") || undefined;
} catch {
const match = url.match(/[?&]schema=([^&]+)/);
return match ? match[1] : undefined;
}
}

const connectionString = process.env.DATABASE_URL || "";
const schema = getSchemaFromUrl(connectionString);
const adapterOptions = schema ? { schema } : undefined;

const pool =
process.env.USE_POOL === "true" || process.env.USE_POOL === "1"
? new Pool({
Expand All @@ -17,7 +31,7 @@ const pool =
})
: undefined;

const adapter = pool ? new PrismaPg(pool) : new PrismaPg({ connectionString });
const adapter = pool ? new PrismaPg(pool, adapterOptions) : new PrismaPg({ connectionString }, adapterOptions);
const prismaOptions: Prisma.PrismaClientOptions = {
adapter,
};
Expand Down Expand Up @@ -52,7 +66,11 @@ export const customPrisma = (options?: Prisma.PrismaClientOptions) => {

if (options?.datasources?.db?.url) {
const customConnectionString = options.datasources.db.url;
const customAdapter = new PrismaPg({ connectionString: customConnectionString });
const customSchema = getSchemaFromUrl(customConnectionString);
const customAdapter = new PrismaPg(
{ connectionString: customConnectionString },
customSchema ? { schema: customSchema } : undefined
);

const { datasources: _datasources, ...restOptions } = options;
finalOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

-- DROP VIEW public."BookingsTimeStatus";

CREATE OR REPLACE VIEW public."BookingTimeStatus"
CREATE OR REPLACE VIEW "BookingTimeStatus"
AS
SELECT "Booking".id,
"Booking".uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

-- DROP VIEW public."BookingsTimeStatus";

CREATE OR REPLACE VIEW public."BookingTimeStatus"
CREATE OR REPLACE VIEW "BookingTimeStatus"
AS
SELECT "Booking".id,
"Booking".uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

-- DROP VIEW public."BookingsTimeStatus";

CREATE OR REPLACE VIEW public."BookingTimeStatus"
CREATE OR REPLACE VIEW "BookingTimeStatus"
AS
SELECT "Booking".id,
"Booking".uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

-- DROP VIEW public."BookingTimeStatus";

CREATE OR REPLACE VIEW public."BookingTimeStatus"
CREATE OR REPLACE VIEW "BookingTimeStatus"
AS
SELECT "Booking".id,
"Booking".uid,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE VIEW public."BookingTimeStatus"
CREATE OR REPLACE VIEW "BookingTimeStatus"
AS
SELECT
"Booking".id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE VIEW public."BookingTimeStatus"
CREATE OR REPLACE VIEW "BookingTimeStatus"
AS
SELECT
"Booking".id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
CREATE OR REPLACE VIEW public."BookingTimeStatusDenormalized" AS
CREATE OR REPLACE VIEW "BookingTimeStatusDenormalized" AS
SELECT
*,
CASE
WHEN "rescheduled" IS TRUE THEN 'rescheduled'
WHEN "status" = 'cancelled'::public."BookingStatus" AND "rescheduled" IS NULL THEN 'cancelled'
WHEN "status" = 'cancelled'::"BookingStatus" AND "rescheduled" IS NULL THEN 'cancelled'
WHEN "endTime" < now() THEN 'completed'
WHEN "endTime" > now() THEN 'uncompleted'
ELSE NULL
END as "timeStatus"
FROM public."BookingDenormalized";
FROM "BookingDenormalized";
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- AlterTable
ALTER TABLE "public"."EventType" ALTER COLUMN "createdAt" SET DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE "EventType" ALTER COLUMN "createdAt" SET DEFAULT CURRENT_TIMESTAMP;
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

*/
-- AlterTable
ALTER TABLE "public"."users" ADD COLUMN "uuid" UUID;
ALTER TABLE "users" ADD COLUMN "uuid" UUID;

-- CreateIndex
CREATE UNIQUE INDEX "users_uuid_key" ON "public"."users"("uuid");
CREATE UNIQUE INDEX "users_uuid_key" ON "users"("uuid");

-- Backfill UUIDs in batches to avoid table locking on large datasets
-- Uses FOR UPDATE SKIP LOCKED to prevent blocking other transactions
Expand All @@ -22,15 +22,15 @@ BEGIN
LOOP
WITH batch AS (
SELECT id
FROM "public"."users"
FROM "users"
WHERE uuid IS NULL
LIMIT batch_size
FOR UPDATE SKIP LOCKED
)
UPDATE "public"."users"
UPDATE "users"
SET uuid = gen_random_uuid()
FROM batch
WHERE "public"."users".id = batch.id;
WHERE "users".id = batch.id;

GET DIAGNOSTICS rows_updated = ROW_COUNT;
total_updated := total_updated + rows_updated;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- AlterTable
ALTER TABLE "public"."Webhook" ADD COLUMN "version" TEXT NOT NULL DEFAULT '2021-10-20';
ALTER TABLE "Webhook" ADD COLUMN "version" TEXT NOT NULL DEFAULT '2021-10-20';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- AlterTable
ALTER TABLE "public"."CalVideoSettings" ADD COLUMN "requireEmailForGuests" BOOLEAN NOT NULL DEFAULT false;
ALTER TABLE "CalVideoSettings" ADD COLUMN "requireEmailForGuests" BOOLEAN NOT NULL DEFAULT false;

-- CreateTable
CREATE TABLE "public"."VideoCallGuest" (
CREATE TABLE "VideoCallGuest" (
"id" TEXT NOT NULL,
"bookingUid" TEXT NOT NULL,
"email" TEXT NOT NULL,
Expand All @@ -15,10 +15,10 @@ CREATE TABLE "public"."VideoCallGuest" (
);

-- CreateIndex
CREATE INDEX "VideoCallGuest_bookingUid_idx" ON "public"."VideoCallGuest"("bookingUid");
CREATE INDEX "VideoCallGuest_bookingUid_idx" ON "VideoCallGuest"("bookingUid");

-- CreateIndex
CREATE INDEX "VideoCallGuest_email_idx" ON "public"."VideoCallGuest"("email");
CREATE INDEX "VideoCallGuest_email_idx" ON "VideoCallGuest"("email");

-- CreateIndex
CREATE UNIQUE INDEX "VideoCallGuest_bookingUid_email_key" ON "public"."VideoCallGuest"("bookingUid", "email");
CREATE UNIQUE INDEX "VideoCallGuest_bookingUid_email_key" ON "VideoCallGuest"("bookingUid", "email");
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- CreateEnum
CREATE TYPE "public"."BookingReportStatus" AS ENUM ('PENDING', 'DISMISSED', 'BLOCKED');
CREATE TYPE "BookingReportStatus" AS ENUM ('PENDING', 'DISMISSED', 'BLOCKED');

-- AlterTable
ALTER TABLE "public"."BookingReport" ADD COLUMN "status" "public"."BookingReportStatus" NOT NULL DEFAULT 'PENDING';
ALTER TABLE "BookingReport" ADD COLUMN "status" "BookingReportStatus" NOT NULL DEFAULT 'PENDING';
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

*/
-- AlterTable
ALTER TABLE "public"."users" ALTER COLUMN "uuid" SET NOT NULL;
ALTER TABLE "users" ALTER COLUMN "uuid" SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- AlterEnum
ALTER TYPE "public"."WebhookTriggerEvents" ADD VALUE 'DELEGATION_CREDENTIAL_ERROR';
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'DELEGATION_CREDENTIAL_ERROR';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- AlterTable
ALTER TABLE "public"."Agent" ADD COLUMN "outboundEventTypeId" INTEGER;
ALTER TABLE "Agent" ADD COLUMN "outboundEventTypeId" INTEGER;

-- CreateIndex
CREATE INDEX "Agent_outboundEventTypeId_idx" ON "public"."Agent"("outboundEventTypeId");
CREATE INDEX "Agent_outboundEventTypeId_idx" ON "Agent"("outboundEventTypeId");
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- AlterTable
ALTER TABLE "public"."OrganizationSettings" ADD COLUMN "orgAutoJoinOnSignup" BOOLEAN NOT NULL DEFAULT true;
ALTER TABLE "OrganizationSettings" ADD COLUMN "orgAutoJoinOnSignup" BOOLEAN NOT NULL DEFAULT true;
Loading
Loading