Skip to content

Commit

Permalink
fix: Rename to resourceMatches
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Nov 13, 2024
1 parent 57d3467 commit 4606845
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 23 deletions.
8 changes: 4 additions & 4 deletions packages/api/src/router/deployment-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
deploymentVariableValue,
environment,
resource,
resourceMatchesMetadata,
system,
targetMatchesMetadata,
updateDeploymentVariable,
updateDeploymentVariableValue,
} from "@ctrlplane/db/schema";
Expand Down Expand Up @@ -214,11 +214,11 @@ const valueRouter = createTRPCRouter({
};

const oldTargets = await ctx.db.query.resource.findMany({
where: targetMatchesMetadata(ctx.db, oldTargetFilter),
where: resourceMatchesMetadata(ctx.db, oldTargetFilter),
});

const newTargets = await ctx.db.query.resource.findMany({
where: targetMatchesMetadata(ctx.db, newTargetFilter),
where: resourceMatchesMetadata(ctx.db, newTargetFilter),
});

const oldTargetIds = new Set(oldTargets.map((t) => t.id));
Expand Down Expand Up @@ -331,7 +331,7 @@ export const deploymentVariableRouter = createTRPCRouter({
.where(
and(
eq(resource.id, input),
targetMatchesMetadata(ctx.db, targetFilter),
resourceMatchesMetadata(ctx.db, targetFilter),
),
)
.then(takeFirstOrNull);
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/router/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
releaseJobTrigger,
releaseMatchesCondition,
resource,
resourceMatchesMetadata,
system,
targetMatchesMetadata,
updateDeployment,
updateReleaseChannel,
workspace,
Expand Down Expand Up @@ -440,7 +440,7 @@ export const deploymentRouter = createTRPCRouter({
.leftJoin(release, eq(release.deploymentId, deployment.id))
.innerJoin(
resource,
targetMatchesMetadata(ctx.db, env.environment.resourceFilter),
resourceMatchesMetadata(ctx.db, env.environment.resourceFilter),
)
.leftJoin(
releaseJobTrigger,
Expand Down
11 changes: 7 additions & 4 deletions packages/api/src/router/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
environmentReleaseChannel,
releaseChannel,
resource,
resourceMatchesMetadata,
system,
targetMatchesMetadata,
updateEnvironment,
} from "@ctrlplane/db/schema";
import { getEventsForEnvironmentDeleted, handleEvent } from "@ctrlplane/events";
Expand Down Expand Up @@ -160,7 +160,10 @@ export const environmentRouter = createTRPCRouter({
.select()
.from(resource)
.where(
targetMatchesMetadata(ctx.db, e.environment.resourceFilter),
resourceMatchesMetadata(
ctx.db,
e.environment.resourceFilter,
),
)
: [],
})),
Expand Down Expand Up @@ -231,7 +234,7 @@ export const environmentRouter = createTRPCRouter({
);

if (hasTargetFiltersChanged) {
const oldQuery = targetMatchesMetadata(
const oldQuery = resourceMatchesMetadata(
ctx.db,
oldEnv.environment.resourceFilter,
);
Expand All @@ -241,7 +244,7 @@ export const environmentRouter = createTRPCRouter({
.where(
and(
eq(resource.workspaceId, oldEnv.system.workspaceId),
targetMatchesMetadata(ctx.db, resourceFilter),
resourceMatchesMetadata(ctx.db, resourceFilter),
oldQuery && not(oldQuery),
),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/router/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const targetViews = createTRPCRouter({
const total = await ctx.db
.select({ count: count() })
.from(schema.resource)
.where(schema.targetMatchesMetadata(ctx.db, view.filter))
.where(schema.resourceMatchesMetadata(ctx.db, view.filter))
.then(takeFirst)
.then((t) => t.count);

Expand Down Expand Up @@ -353,7 +353,7 @@ export const targetRouter = createTRPCRouter({
schema.resource.workspaceId,
input.workspaceId,
);
const targetConditions = schema.targetMatchesMetadata(
const targetConditions = schema.resourceMatchesMetadata(
ctx.db,
input.filter,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/schema/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const buildCondition = (tx: Tx, cond: TargetCondition): SQL => {
return cond.not ? not(con) : con;
};

export function targetMatchesMetadata(
export function resourceMatchesMetadata(
tx: Tx,
metadata?: TargetCondition | null,
): SQL<unknown> | undefined {
Expand Down
2 changes: 1 addition & 1 deletion packages/events/src/triggers/deployment-deleted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getEventsForDeploymentDeleted = async (
};

const targets = await db.query.resource.findMany({
where: SCHEMA.targetMatchesMetadata(db, systemFilter),
where: SCHEMA.resourceMatchesMetadata(db, systemFilter),
});

return targets.map((target) => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/events/src/triggers/environment-deleted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getEventsForEnvironmentDeleted = async (
const targets = await db
.select()
.from(SCHEMA.resource)
.where(SCHEMA.targetMatchesMetadata(db, environment.resourceFilter));
.where(SCHEMA.resourceMatchesMetadata(db, environment.resourceFilter));
if (targets.length === 0) return [];

const checks = and(
Expand Down Expand Up @@ -46,7 +46,7 @@ export const getEventsForEnvironmentDeleted = async (
.from(SCHEMA.resource)
.where(
and(
SCHEMA.targetMatchesMetadata(db, removedFromSystemFilter),
SCHEMA.resourceMatchesMetadata(db, removedFromSystemFilter),
inArray(
SCHEMA.resource.id,
targets.map((t) => t.id),
Expand Down
2 changes: 1 addition & 1 deletion packages/events/src/triggers/target-deleted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getEventsForTargetDeleted = async (
};

const matchedTarget = await db.query.resource.findFirst({
where: SCHEMA.targetMatchesMetadata(db, systemFilter),
where: SCHEMA.resourceMatchesMetadata(db, systemFilter),
});
if (matchedTarget == null) return [];

Expand Down
2 changes: 1 addition & 1 deletion packages/job-dispatch/src/environment-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const createJobsForNewEnvironment = async (
.where(
and(
eq(SCHEMA.resource.workspaceId, workspaceId),
SCHEMA.targetMatchesMetadata(db, resourceFilter),
SCHEMA.resourceMatchesMetadata(db, resourceFilter),
),
);
if (resources.length === 0) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const getMatchedTarget = (
.where(
and(
eq(SCHEMA.resource.id, targetId),
SCHEMA.targetMatchesMetadata(tx, targetFilter),
SCHEMA.resourceMatchesMetadata(tx, targetFilter),
),
)
.then(takeFirstOrNull);
Expand Down
4 changes: 2 additions & 2 deletions packages/job-dispatch/src/release-job-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
release,
releaseJobTrigger,
resource,
resourceMatchesMetadata,
system,
targetMatchesMetadata,
} from "@ctrlplane/db/schema";

type FilterFunc = (
Expand Down Expand Up @@ -142,7 +142,7 @@ class ReleaseJobTriggerBuilder {
.from(resource)
.where(
and(
targetMatchesMetadata(this.tx, resourceFilter),
resourceMatchesMetadata(this.tx, resourceFilter),
eq(resource.workspaceId, workspaceId),
isNull(resource.lockedAt),
this.targetIds && inArray(resource.id, this.targetIds),
Expand Down
4 changes: 2 additions & 2 deletions packages/job-dispatch/src/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { db } from "@ctrlplane/db/client";
import {
environment,
resource,
resourceMatchesMetadata,
resourceMetadata,
resourceVariable,
system,
targetMatchesMetadata,
} from "@ctrlplane/db/schema";
import { logger } from "@ctrlplane/logger";
import { variablesAES256 } from "@ctrlplane/secrets";
Expand Down Expand Up @@ -53,7 +53,7 @@ const dispatchNewTargets = async (db: Tx, newTargets: Target[]) => {
.where(
and(
inArray(resource.id, targetIds),
targetMatchesMetadata(db, env.resourceFilter),
resourceMatchesMetadata(db, env.resourceFilter),
),
)
.then((tgs) => {
Expand Down

0 comments on commit 4606845

Please sign in to comment.