Skip to content
Draft
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
50 changes: 50 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ import { serviceVersionShowCommand } from "./commands/service/version-show";
import { serviceVersionStartCommand } from "./commands/service/version-start";
import { serviceVersionStopCommand } from "./commands/service/version-stop";
import { skillsCommandFamily } from "./commands/skills/family";
import { variableAddCommand } from "./commands/variable/add";
import { variableDeleteCommand } from "./commands/variable/delete";
import { variableGroupCreateCommand } from "./commands/variable/group-create";
import { variableGroupDeleteCommand } from "./commands/variable/group-delete";
import { variableGroupListCommand } from "./commands/variable/group-list";
import { variableGroupUpdateCommand } from "./commands/variable/group-update";
import { variableListCommand } from "./commands/variable/list";
import { variableUpdateCommand } from "./commands/variable/update";
import { getCliVersion } from "./lib/version";
import { v7CommandFamily } from "./v7-redirects";

Expand Down Expand Up @@ -129,6 +137,14 @@ export const platformCommandFamily: CommandFamily = defineCommandFamily({
serviceDomainDelete: serviceDomainDeleteCommand,
serviceDomainRetry: serviceDomainRetryCommand,
serviceDomainWait: serviceDomainWaitCommand,
variableAdd: variableAddCommand,
variableUpdate: variableUpdateCommand,
variableDelete: variableDeleteCommand,
variableList: variableListCommand,
variableGroupList: variableGroupListCommand,
variableGroupCreate: variableGroupCreateCommand,
variableGroupUpdate: variableGroupUpdateCommand,
variableGroupDelete: variableGroupDeleteCommand,
},
});

Expand Down Expand Up @@ -361,6 +377,32 @@ export const cliGroups: Readonly<
description:
"An emulator runs one kind of resource locally, so 'prisma dev' needs no account or network: one runs services, one runs Postgres databases, one runs S3-compatible buckets. Each holds instances, one per service, database or bucket that a 'prisma dev' started, from any directory on this machine. Emulators keep running after 'prisma dev' ends. Instances and their data stay until 'prisma dev --fresh' removes the current app's, and a stopped instance keeps its port.",
},
variable: {
brief:
"Manage project variables. Add, update, delete, and list values per group",
description:
"Variables live in groups: production, preview (shared by every branch that matches no custom rule), or a custom group. Values reach services when they deploy. Write commands require a group. For branch-level inspection, use --branch.",
workflow: [
{
run: "variable add API_URL=https://api.example --group production",
brief: "Set a variable in the production group",
},
{
run: "variable list --branch feature/foo",
brief: "See what a branch receives",
},
{
run: "variable group create staging --equals staging",
brief: "Create a custom group for the staging branch",
},
],
},
"variable group": {
brief:
"Manage variable groups. Create, rename, change rules, and delete custom groups",
description:
"Every project has a production group and a preview group. Add up to ten custom groups, each with an equals or startsWith rule that selects which branches receive its variables.",
},
skills: {
brief:
"Manage Prisma skills for AI coding agents. Sync and list the instruction files",
Expand Down Expand Up @@ -426,6 +468,14 @@ export const mountedCommands: Readonly<Record<string, AnyCommand>> = {
"service domain delete": serviceDomainDeleteCommand,
"service domain retry": serviceDomainRetryCommand,
"service domain wait": serviceDomainWaitCommand,
"variable add": variableAddCommand,
"variable update": variableUpdateCommand,
"variable delete": variableDeleteCommand,
"variable list": variableListCommand,
"variable group list": variableGroupListCommand,
"variable group create": variableGroupCreateCommand,
"variable group update": variableGroupUpdateCommand,
"variable group delete": variableGroupDeleteCommand,
// Composer's product verbs: deploy and dev at the root, their
// children beneath them, and the local emulators under their own group.
deploy: composerCommandFamily.commands.deploy,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/branch/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function listPresentations(result: BranchListResult): Presentations {
const rows = result.branches.map((branch) => [
branch.name,
branch.role,
branch.envMap,
branch.variableGroup,
]);
return {
json: () => result,
Expand All @@ -43,7 +43,7 @@ function listPresentations(result: BranchListResult): Presentations {
: [
{
kind: "table" as const,
columns: ["Name", "Role", "Env map"],
columns: ["Name", "Role", "Variable group"],
rows,
},
]),
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/commands/project/env-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export const projectEnvAddCommand = defineCommand({
},
needs: { credentials: true },
handler: async (args, ctx) => {
ctx.report({
kind: "message",
severity: "warn",
text: "Warning: `prisma project env` is deprecated and will be removed in a future major version. Use `prisma variable` instead.",
});

const source = resolveEnvWriteSource(
args.positionals.assignment,
args.flags.file,
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/commands/project/env-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export const projectEnvDeleteCommand = defineCommand({
},
needs: { credentials: true },
handler: async (args, ctx) => {
ctx.report({
kind: "message",
severity: "warn",
text: "Warning: `prisma project env` is deprecated and will be removed in a future major version. Use `prisma variable` instead.",
});

const key = args.positionals.key;
const scope = requireEnvScope(args.flags, "delete");
const { projectId, resolved } = await resolveEnvTarget(
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/commands/project/env-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export const projectEnvListCommand = defineCommand({
},
needs: { credentials: true },
handler: async (args, ctx) => {
ctx.report({
kind: "message",
severity: "warn",
text: "Warning: `prisma project env` is deprecated and will be removed in a future major version. Use `prisma variable` instead.",
});

const explicit = resolveEnvScope(
{ roleName: args.flags.role, branchName: args.flags.branch },
{ requireExplicit: false, command: "list" },
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/commands/project/env-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export const projectEnvUpdateCommand = defineCommand({
},
needs: { credentials: true },
handler: async (args, ctx) => {
ctx.report({
kind: "message",
severity: "warn",
text: "Warning: `prisma project env` is deprecated and will be removed in a future major version. Use `prisma variable` instead.",
});

const source = resolveEnvWriteSource(
args.positionals.assignment,
args.flags.file,
Expand Down
190 changes: 190 additions & 0 deletions packages/cli/src/commands/variable/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/** The `variable add` command. */
import {
type Block,
defineCommand,
type Presentations,
positional,
} from "@prisma/cli-engine";
import { ok } from "@prisma/cli-engine/protocol";
import { parseKeyValuePositional } from "../../lib/app/env-config";
import { readEnvFileAssignments } from "../../lib/app/env-file";
import { createEnvVarInGroup } from "../../lib/variable/api";
import { resolvePinnedProject } from "../project/context";
import { resolveActiveWorkspace } from "../resources-shared/workspace";
import {
branchFlag,
enforceRolePreviewCheck,
fileFlag,
groupFlag,
projectFlag,
rejectBranchWrite,
resolveGroupByTarget,
resolveGroupTarget,
roleFlag,
variableFieldRows,
} from "./shared";

function addPresentations(result: {
projectId: string;
groupName: string;
key: string;
id: string;
updatedAt: string;
}): Presentations {
return {
stdout: () => [result.id],
json: () => result,
next: () => [],
human: (): Block[] => [
{
kind: "summary",
status: "info",
text: "Setting a new variable.",
},
{
kind: "fields",
rows: variableFieldRows(
result.projectId,
result.groupName,
result.key,
result.id,
result.updatedAt,
),
},
],
};
}

function addFilePresentations(result: {
projectId: string;
groupName: string;
keys: string[];
}): Presentations {
return {
stdout: () => result.keys,
json: () => result,
next: () => [],
human: (): Block[] => [
{
kind: "summary",
status: "info",
text: "Setting new variables from file.",
},
{
kind: "fields",
rows: [
{ label: "project", value: result.projectId },
{ label: "group", value: result.groupName },
],
},
result.keys.length === 0
? { kind: "summary", status: "info", text: "No variables imported." }
: {
kind: "table",
columns: ["key"],
rows: result.keys.map((k) => [k]),
},
],
};
}

export const variableAddCommand = defineCommand({
args: {
positionals: {
assignment: positional.optionalString({
brief:
"Variable assignment as KEY=VALUE, or KEY to read the value from the current environment",
placeholder: "assignment",
}),
},
flags: {
group: groupFlag,
role: roleFlag,
file: fileFlag,
branch: branchFlag,
project: projectFlag,
},
},
help: {
summary: "Add a variable to a group",
description:
"Creates a branch variable in the named group: production, preview, or a custom group. Use --group <name> or --role production|preview. The value comes from KEY=VALUE, from the current shell environment when only KEY is given, or from a dotenv file with --file. --branch is not accepted; use a variable group or send a service variable with the deploy.",
examples: [
"variable add STRIPE_KEY=sk_test_xxx --group production",
"variable add STRIPE_KEY=sk_test_xxx --role production",
"variable add STRIPE_KEY=sk_test_xxx --group staging",
"variable add --file .env --group preview",
"API_URL=https://api.example prisma variable add API_URL --group production",
],
},
needs: { credentials: true },
handler: async (args, ctx) => {
rejectBranchWrite(args.flags.branch, "add");

const target = resolveGroupTarget(args.flags.group, args.flags.role, "add");

const workspace = await resolveActiveWorkspace(ctx);
const resolved = await resolvePinnedProject(
ctx,
workspace,
args.flags.project,
"variable add",
);
const projectId = resolved.project.id;

await enforceRolePreviewCheck(ctx.api, projectId, target, ctx.signal);

const group = await resolveGroupByTarget(
ctx.api,
projectId,
target,
ctx.signal,
);

if (args.flags.file !== undefined) {
const assignments = await readEnvFileAssignments(
ctx.cwd,
args.flags.file,
"add",
);
const keys: string[] = [];
for (const { key, value } of assignments) {
// biome-ignore lint/performance/noAwaitInLoops: keys are added one at a time so the import stops at the first failure.
await createEnvVarInGroup(
ctx.api,
{ projectId, groupId: group.id, key, value },
ctx.signal,
);
keys.push(key);
}
return ok(
ctx.present(
{ data: { projectId, groupName: group.name, keys } },
addFilePresentations({ projectId, groupName: group.name, keys }),
),
);
}

const { key, value } = parseKeyValuePositional(
args.positionals.assignment,
"add",
ctx.env,
);

const row = (await createEnvVarInGroup(
ctx.api,
{ projectId, groupId: group.id, key, value },
ctx.signal,
)) as { id: string; key: string; updatedAt: string };

const result = {
projectId,
groupName: group.name,
key: row.key,
id: row.id,
updatedAt: row.updatedAt,
};

return ok(ctx.present({ data: result }, addPresentations(result)));
},
});
Loading
Loading