diff --git a/packages/database/prisma/migrations/20231023173456_added_trigger_http_endpoint_table/migration.sql b/packages/database/prisma/migrations/20231023173456_added_trigger_http_endpoint_table/migration.sql new file mode 100644 index 000000000..908da410a --- /dev/null +++ b/packages/database/prisma/migrations/20231023173456_added_trigger_http_endpoint_table/migration.sql @@ -0,0 +1,29 @@ +-- CreateTable +CREATE TABLE "TriggerHttpEndpoint" ( + "id" TEXT NOT NULL, + "key" TEXT NOT NULL, + "active" BOOLEAN NOT NULL DEFAULT true, + "immediateResponseFilter" JSONB, + "title" TEXT, + "icon" TEXT, + "properties" JSONB, + "secretReferenceId" TEXT NOT NULL, + "environmentId" TEXT NOT NULL, + "projectId" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "TriggerHttpEndpoint_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "TriggerHttpEndpoint_key_environmentId_key" ON "TriggerHttpEndpoint"("key", "environmentId"); + +-- AddForeignKey +ALTER TABLE "TriggerHttpEndpoint" ADD CONSTRAINT "TriggerHttpEndpoint_secretReferenceId_fkey" FOREIGN KEY ("secretReferenceId") REFERENCES "SecretReference"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "TriggerHttpEndpoint" ADD CONSTRAINT "TriggerHttpEndpoint_environmentId_fkey" FOREIGN KEY ("environmentId") REFERENCES "RuntimeEnvironment"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "TriggerHttpEndpoint" ADD CONSTRAINT "TriggerHttpEndpoint_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/packages/database/prisma/migrations/20231024122540_http_endpoint_scoped_to_project_not_environment/migration.sql b/packages/database/prisma/migrations/20231024122540_http_endpoint_scoped_to_project_not_environment/migration.sql new file mode 100644 index 000000000..b787f8986 --- /dev/null +++ b/packages/database/prisma/migrations/20231024122540_http_endpoint_scoped_to_project_not_environment/migration.sql @@ -0,0 +1,19 @@ +/* + Warnings: + + - You are about to drop the column `environmentId` on the `TriggerHttpEndpoint` table. All the data in the column will be lost. + - A unique constraint covering the columns `[key,projectId]` on the table `TriggerHttpEndpoint` will be added. If there are existing duplicate values, this will fail. + +*/ +-- DropForeignKey +ALTER TABLE "TriggerHttpEndpoint" DROP CONSTRAINT "TriggerHttpEndpoint_environmentId_fkey"; + +-- DropIndex +DROP INDEX "TriggerHttpEndpoint_key_environmentId_key"; + +-- AlterTable +ALTER TABLE "TriggerHttpEndpoint" DROP COLUMN "environmentId", +ALTER COLUMN "active" SET DEFAULT false; + +-- CreateIndex +CREATE UNIQUE INDEX "TriggerHttpEndpoint_key_projectId_key" ON "TriggerHttpEndpoint"("key", "projectId"); diff --git a/packages/database/prisma/schema.prisma b/packages/database/prisma/schema.prisma index 392dd1c69..1ac8b21e8 100644 --- a/packages/database/prisma/schema.prisma +++ b/packages/database/prisma/schema.prisma @@ -292,6 +292,9 @@ model RuntimeEnvironment { type RuntimeEnvironmentType @default(DEVELOPMENT) + ///A memorable code for the environment + // shortcode String? + autoEnableInternalSources Boolean @default(true) organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, onUpdate: Cascade) @@ -318,6 +321,7 @@ model RuntimeEnvironment { eventDispatchers EventDispatcher[] scheduleSources ScheduleSource[] ExternalAccount ExternalAccount[] + // @@unique([projectId, shortcode]) @@unique([projectId, slug, orgMemberId]) } @@ -340,13 +344,14 @@ model Project { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - environments RuntimeEnvironment[] - endpoints Endpoint[] - jobs Job[] - jobVersion JobVersion[] - events EventRecord[] - runs JobRun[] - sources TriggerSource[] + environments RuntimeEnvironment[] + endpoints Endpoint[] + jobs Job[] + jobVersion JobVersion[] + events EventRecord[] + runs JobRun[] + sources TriggerSource[] + httpEndpoints TriggerHttpEndpoint[] } model Endpoint { @@ -925,6 +930,7 @@ model SecretReference { connections IntegrationConnection[] integrations Integration[] triggerSources TriggerSource[] + httpEndpoints TriggerHttpEndpoint[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -1099,6 +1105,31 @@ model ScheduleSource { @@unique([key, environmentId]) } +model TriggerHttpEndpoint { + id String @id @default(cuid()) + + key String + active Boolean @default(false) + + /// If this is set, requests will be tested against the filter and we'll call the user's server immediately + immediateResponseFilter Json? + + title String? + icon String? + properties Json? + + secretReference SecretReference @relation(fields: [secretReferenceId], references: [id], onDelete: Cascade, onUpdate: Cascade) + secretReferenceId String + + project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) + projectId String + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@unique([key, projectId]) +} + model MissingConnection { id String @id @default(cuid())