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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EnvironmentDrawerTab } from "../tabs";
import { useUpdateOverridePolicy } from "./useOverridePolicy";

type Deployment = SCHEMA.Deployment & {
releaseChannels: SCHEMA.ReleaseChannel[];
releaseChannels: SCHEMA.DeploymentVersionChannel[];
};

type Policy = NonNullable<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const PolicyDropdownMenu: React.FC<{
type ViewProps = {
environmentPolicy: SCHEMA.EnvironmentPolicy & {
releaseWindows: SCHEMA.EnvironmentPolicyReleaseWindow[];
releaseChannels: SCHEMA.ReleaseChannel[];
releaseChannels: SCHEMA.DeploymentVersionChannel[];
};
activeTab: EnvironmentPolicyDrawerTab;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
import { Popover, PopoverContent, PopoverTrigger } from "@ctrlplane/ui/popover";

type Deployment = SCHEMA.Deployment & {
releaseChannels: SCHEMA.ReleaseChannel[];
releaseChannels: SCHEMA.DeploymentVersionChannel[];
};

type Policy = { releaseChannels: SCHEMA.ReleaseChannel[] };
type Policy = { releaseChannels: SCHEMA.DeploymentVersionChannel[] };

type DeploymentSelectProps = {
deployment: Deployment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { useReleaseFilter } from "../release-condition/useReleaseFilter";
import { ReleaseBadgeList } from "../ReleaseBadgeList";

type OverviewProps = {
releaseChannel: SCHEMA.ReleaseChannel;
releaseChannel: SCHEMA.DeploymentVersionChannel;
};

const getFinalFilter = (filter: ReleaseCondition | null) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ReleaseConditionDialogProps = {
condition: ReleaseCondition | null,
releaseChannelId?: string | null,
) => void;
releaseChannels?: SCHEMA.ReleaseChannel[];
releaseChannels?: SCHEMA.DeploymentVersionChannel[];
children: React.ReactNode;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ type DeploymentPageContentProps = {
deployment: Deployment;
environments: schema.Environment[];
directories: { path: string; environments: schema.Environment[] }[];
releaseChannel: schema.ReleaseChannel | null;
releaseChannel: schema.DeploymentVersionChannel | null;
};

export const DeploymentPageContent: React.FC<DeploymentPageContentProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { useReleaseChannelDrawer } from "~/app/[workspaceSlug]/(appv2)/_components/channel/drawer/useReleaseChannelDrawer";
import { ReleaseConditionBadge } from "~/app/[workspaceSlug]/(appv2)/_components/release/condition/ReleaseConditionBadge";

type ReleaseChannel = SCHEMA.ReleaseChannel & { total: number };
type ReleaseChannel = SCHEMA.DeploymentVersionChannel & { total: number };

type ReleaseChannelTableProps = { releaseChannels: ReleaseChannel[] };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { ReleaseBadgeList } from "~/app/[workspaceSlug]/(appv2)/_components/rele
import { api } from "~/trpc/react";

type OverviewProps = {
releaseChannel: SCHEMA.ReleaseChannel;
releaseChannel: SCHEMA.DeploymentVersionChannel;
};

const getFinalFilter = (filter: ReleaseCondition | null) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ReleaseConditionDialogProps = {
condition: ReleaseCondition | null,
releaseChannelId?: string | null,
) => void;
releaseChannels?: SCHEMA.ReleaseChannel[];
releaseChannels?: SCHEMA.DeploymentVersionChannel[];
children: React.ReactNode;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ export const DELETE = request()
async (ctx, { params }) => {
try {
await ctx.db
.delete(schema.releaseChannel)
.delete(schema.deploymentVersionChannel)
.where(
and(
eq(schema.releaseChannel.deploymentId, params.deploymentId),
eq(schema.releaseChannel.name, params.name),
eq(
schema.deploymentVersionChannel.deploymentId,
params.deploymentId,
),
eq(schema.deploymentVersionChannel.name, params.name),
),
);

Expand Down
4 changes: 2 additions & 2 deletions apps/webservice/src/app/api/v1/environments/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const POST = request()

const channels = await tx
.select()
.from(schema.releaseChannel)
.where(inArray(schema.releaseChannel.id, releaseChannels))
.from(schema.deploymentVersionChannel)
.where(inArray(schema.deploymentVersionChannel.id, releaseChannels))
.then((rows) =>
_.uniqBy(rows, (r) => r.deploymentId).map((r) => ({
channelId: r.id,
Expand Down
14 changes: 7 additions & 7 deletions apps/webservice/src/app/api/v1/release-channels/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { z } from "zod";
import { NextResponse } from "next/server";

import { and, eq, takeFirst, takeFirstOrNull } from "@ctrlplane/db";
import { createReleaseChannel } from "@ctrlplane/db/schema";
import { createDeploymentVersionChannel } from "@ctrlplane/db/schema";
import * as SCHEMA from "@ctrlplane/db/schema";
import { Permission } from "@ctrlplane/validators/auth";

Expand All @@ -12,23 +12,23 @@ import { request } from "../middleware";

export const POST = request()
.use(authn)
.use(parseBody(createReleaseChannel))
.use(parseBody(createDeploymentVersionChannel))
.use(
authz(({ ctx, can }) =>
can
.perform(Permission.ReleaseChannelCreate)
.on({ type: "deployment", id: ctx.body.deploymentId }),
),
)
.handle<{ body: z.infer<typeof createReleaseChannel> }>(
.handle<{ body: z.infer<typeof createDeploymentVersionChannel> }>(
async ({ db, body }) => {
const releaseChannel = await db
.select()
.from(SCHEMA.releaseChannel)
.from(SCHEMA.deploymentVersionChannel)
.where(
and(
eq(SCHEMA.releaseChannel.deploymentId, body.deploymentId),
eq(SCHEMA.releaseChannel.name, body.name),
eq(SCHEMA.deploymentVersionChannel.deploymentId, body.deploymentId),
eq(SCHEMA.deploymentVersionChannel.name, body.name),
),
)
.then(takeFirstOrNull);
Expand All @@ -40,7 +40,7 @@ export const POST = request()
);

return db
.insert(SCHEMA.releaseChannel)
.insert(SCHEMA.deploymentVersionChannel)
.values(body)
.returning()
.then(takeFirst)
Expand Down
15 changes: 8 additions & 7 deletions packages/api/src/router/deployment-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,19 @@ export const versionRouter = createTRPCRouter({
.query(async ({ input }) => {
const policyRCSubquery = db
.select({
releaseChannelId: SCHEMA.releaseChannel.id,
releaseChannelId: SCHEMA.deploymentVersionChannel.id,
releaseChannelPolicyId:
SCHEMA.environmentPolicyReleaseChannel.policyId,
releaseChannelDeploymentId: SCHEMA.releaseChannel.deploymentId,
releaseChannelFilter: SCHEMA.releaseChannel.releaseFilter,
releaseChannelDeploymentId:
SCHEMA.deploymentVersionChannel.deploymentId,
releaseChannelFilter: SCHEMA.deploymentVersionChannel.releaseFilter,
})
.from(SCHEMA.environmentPolicyReleaseChannel)
.innerJoin(
SCHEMA.releaseChannel,
SCHEMA.deploymentVersionChannel,
eq(
SCHEMA.environmentPolicyReleaseChannel.channelId,
SCHEMA.releaseChannel.id,
SCHEMA.deploymentVersionChannel.id,
),
)
.as("policyRCSubquery");
Expand Down Expand Up @@ -588,10 +589,10 @@ export const versionRouter = createTRPCRouter({
),
)
.leftJoin(
SCHEMA.releaseChannel,
SCHEMA.deploymentVersionChannel,
eq(
SCHEMA.environmentPolicyReleaseChannel.channelId,
SCHEMA.releaseChannel.id,
SCHEMA.deploymentVersionChannel.id,
),
)
.where(eq(SCHEMA.environment.id, environmentId))
Expand Down
39 changes: 24 additions & 15 deletions packages/api/src/router/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { versionRouter } from "./deployment-version";

const releaseChannelRouter = createTRPCRouter({
create: protectedProcedure
.input(SCHEMA.createReleaseChannel)
.input(SCHEMA.createDeploymentVersionChannel)
.meta({
authorizationCheck: ({ canUser, input }) =>
canUser.perform(Permission.ReleaseChannelCreate).on({
Expand All @@ -38,12 +38,15 @@ const releaseChannelRouter = createTRPCRouter({
}),
})
.mutation(({ ctx, input }) =>
ctx.db.insert(SCHEMA.releaseChannel).values(input).returning(),
ctx.db.insert(SCHEMA.deploymentVersionChannel).values(input).returning(),
),

update: protectedProcedure
.input(
z.object({ id: z.string().uuid(), data: SCHEMA.updateReleaseChannel }),
z.object({
id: z.string().uuid(),
data: SCHEMA.updateDeploymentVersionChannel,
}),
)
.meta({
authorizationCheck: ({ canUser, input }) =>
Expand All @@ -53,9 +56,9 @@ const releaseChannelRouter = createTRPCRouter({
})
.mutation(({ ctx, input }) =>
ctx.db
.update(SCHEMA.releaseChannel)
.update(SCHEMA.deploymentVersionChannel)
.set(input.data)
.where(eq(SCHEMA.releaseChannel.id, input.id))
.where(eq(SCHEMA.deploymentVersionChannel.id, input.id))
.returning(),
),

Expand All @@ -69,8 +72,8 @@ const releaseChannelRouter = createTRPCRouter({
})
.mutation(({ ctx, input }) =>
ctx.db
.delete(SCHEMA.releaseChannel)
.where(eq(SCHEMA.releaseChannel.id, input)),
.delete(SCHEMA.deploymentVersionChannel)
.where(eq(SCHEMA.deploymentVersionChannel.id, input)),
),

list: createTRPCRouter({
Expand All @@ -85,8 +88,8 @@ const releaseChannelRouter = createTRPCRouter({
.query(async ({ ctx, input }) => {
const channels = await ctx.db
.select()
.from(SCHEMA.releaseChannel)
.where(eq(SCHEMA.releaseChannel.deploymentId, input));
.from(SCHEMA.deploymentVersionChannel)
.where(eq(SCHEMA.deploymentVersionChannel.deploymentId, input));

const promises = channels.map(async (channel) => {
const filter = channel.releaseFilter ?? undefined;
Expand Down Expand Up @@ -116,8 +119,8 @@ const releaseChannelRouter = createTRPCRouter({
.on({ type: "releaseChannel", id: input }),
})
.query(async ({ ctx, input }) => {
const rc = await ctx.db.query.releaseChannel.findFirst({
where: eq(SCHEMA.releaseChannel.id, input),
const rc = await ctx.db.query.deploymentVersionChannel.findFirst({
where: eq(SCHEMA.deploymentVersionChannel.id, input),
with: {
environmentPolicyReleaseChannels: {
with: { environmentPolicy: true },
Expand Down Expand Up @@ -530,8 +533,11 @@ export const deploymentRouter = createTRPCRouter({
eq(SCHEMA.jobAgent.id, SCHEMA.deployment.jobAgentId),
)
.leftJoin(
SCHEMA.releaseChannel,
eq(SCHEMA.releaseChannel.deploymentId, SCHEMA.deployment.id),
SCHEMA.deploymentVersionChannel,
eq(
SCHEMA.deploymentVersionChannel.deploymentId,
SCHEMA.deployment.id,
),
)
.where(
and(
Expand Down Expand Up @@ -567,8 +573,11 @@ export const deploymentRouter = createTRPCRouter({
.select()
.from(SCHEMA.deployment)
.leftJoin(
SCHEMA.releaseChannel,
eq(SCHEMA.releaseChannel.deploymentId, SCHEMA.deployment.id),
SCHEMA.deploymentVersionChannel,
eq(
SCHEMA.deploymentVersionChannel.deploymentId,
SCHEMA.deployment.id,
),
)
.innerJoin(
SCHEMA.system,
Expand Down
9 changes: 6 additions & 3 deletions packages/api/src/router/environment-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
import {
createEnvironmentPolicy,
createEnvironmentPolicyDeployment,
deploymentVersionChannel,
environment,
environmentPolicy,
environmentPolicyDeployment,
environmentPolicyReleaseChannel,
environmentPolicyReleaseWindow,
releaseChannel,
updateEnvironmentPolicy,
} from "@ctrlplane/db/schema";
import { handleEnvironmentPolicyReleaseChannelUpdate } from "@ctrlplane/job-dispatch";
Expand All @@ -37,8 +37,11 @@ const basePolicyQuery = (db: Tx) =>
eq(environmentPolicyReleaseChannel.policyId, environmentPolicy.id),
)
.leftJoin(
releaseChannel,
eq(environmentPolicyReleaseChannel.channelId, releaseChannel.id),
deploymentVersionChannel,
eq(
environmentPolicyReleaseChannel.channelId,
deploymentVersionChannel.id,
),
)
.leftJoin(
environmentPolicyReleaseWindow,
Expand Down
19 changes: 11 additions & 8 deletions packages/api/src/router/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
} from "@ctrlplane/db";
import {
createEnvironment,
deploymentVersionChannel,
environment,
environmentMetadata,
environmentPolicy,
environmentPolicyReleaseChannel,
environmentPolicyReleaseWindow,
releaseChannel,
resource,
resourceMatchesMetadata,
system,
Expand Down Expand Up @@ -58,16 +58,19 @@ export const environmentRouter = createTRPCRouter({
const policyRCSubquery = ctx.db
.select({
releaseChannelPolicyId: environmentPolicyReleaseChannel.policyId,
releaseChannelDeploymentId: releaseChannel.deploymentId,
releaseChannelDescription: releaseChannel.description,
releaseChannelFilter: releaseChannel.releaseFilter,
releaseChannelId: releaseChannel.id,
releaseChannelName: releaseChannel.name,
releaseChannelDeploymentId: deploymentVersionChannel.deploymentId,
releaseChannelDescription: deploymentVersionChannel.description,
releaseChannelFilter: deploymentVersionChannel.releaseFilter,
releaseChannelId: deploymentVersionChannel.id,
releaseChannelName: deploymentVersionChannel.name,
})
.from(environmentPolicyReleaseChannel)
.innerJoin(
releaseChannel,
eq(environmentPolicyReleaseChannel.channelId, releaseChannel.id),
deploymentVersionChannel,
eq(
environmentPolicyReleaseChannel.channelId,
deploymentVersionChannel.id,
),
)
.as("policyRCSubquery");

Expand Down
9 changes: 6 additions & 3 deletions packages/auth/src/utils/rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
deployment,
deploymentVariable,
deploymentVersion,
deploymentVersionChannel,
entityRole,
environment,
environmentPolicy,
job,
jobAgent,
releaseChannel,
releaseJobTrigger,
resource,
resourceMetadataGroup,
Expand Down Expand Up @@ -115,8 +115,11 @@ const getReleaseChannelScopes = async (id: string) => {
.from(workspace)
.innerJoin(system, eq(system.workspaceId, workspace.id))
.innerJoin(deployment, eq(deployment.systemId, system.id))
.innerJoin(releaseChannel, eq(releaseChannel.deploymentId, deployment.id))
.where(eq(releaseChannel.id, id))
.innerJoin(
deploymentVersionChannel,
eq(deploymentVersionChannel.deploymentId, deployment.id),
)
.where(eq(deploymentVersionChannel.id, id))
.then(takeFirst);

return [
Expand Down
Loading
Loading