Skip to content

Commit

Permalink
feat(project-update): add project update options and refactor code (#…
Browse files Browse the repository at this point in the history
…main)

This commit introduces new options for project updates including
block_vpc_connections and block_public_connections. It also refactors
the existing code for improved readability and maintainability, by sorting the parameters for the `project update` command alphabetically.
  • Loading branch information
chaporgin committed Jan 30, 2025
1 parent 0e5c51e commit 714f08b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
15 changes: 5 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 33 additions & 4 deletions src/commands/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
import yargs from 'yargs';

import { log } from '../log.js';
import { projectCreateRequest } from '../parameters.gen.js';
import {
projectCreateRequest,
projectUpdateRequest,
} from '../parameters.gen.js';
import { CommonProps, IdOrNameProps } from '../types.js';
import { writer } from '../writer.js';
import { psql } from '../utils/psql.js';
Expand Down Expand Up @@ -108,15 +111,27 @@ export const builder = (argv: yargs.Argv) => {
'Update a project',
(yargs) =>
yargs.options({
name: {
describe: projectCreateRequest['project.name'].description,
type: 'string',
block_vpc_connections: {
describe:
projectUpdateRequest['project.settings.block_vpc_connections']
.description,
type: 'boolean',
},
block_public_connections: {
describe:
projectUpdateRequest['project.settings.block_public_connections']
.description,
type: 'boolean',
},
cu: {
describe:
'The number of Compute Units. Could be a fixed size (e.g. "2") or a range delimited by a dash (e.g. "0.5-3").',
type: 'string',
},
name: {
describe: projectUpdateRequest['project.name'].description,
type: 'string',
},
}),
async (args) => {
await update(args as any);
Expand Down Expand Up @@ -270,9 +285,23 @@ const update = async (
IdOrNameProps & {
name?: string;
cu?: string;
block_vpc_connections?: boolean;
block_public_connections?: boolean;
},
) => {
const project: ProjectUpdateRequest['project'] = {};
if (props.block_public_connections !== undefined) {
if (!project.settings) {
project.settings = {};
}
project.settings.block_public_connections = props.block_public_connections;
}
if (props.block_vpc_connections !== undefined) {
if (!project.settings) {
project.settings = {};
}
project.settings.block_vpc_connections = props.block_vpc_connections;
}
if (props.name) {
project.name = props.name;
}
Expand Down
15 changes: 7 additions & 8 deletions src/parameters.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const projectCreateRequest = {
},
'project.default_endpoint_settings.suspend_timeout_seconds': {
type: "number",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the default value.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Scale to zero configuration](https://neon.tech/docs/manage/endpoints#scale-to-zero-configuration).\n",
demandOption: false,
},
'project.pg_version': {
Expand Down Expand Up @@ -196,7 +196,7 @@ export const projectUpdateRequest = {
},
'project.default_endpoint_settings.suspend_timeout_seconds': {
type: "number",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the default value.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Scale to zero configuration](https://neon.tech/docs/manage/endpoints#scale-to-zero-configuration).\n",
demandOption: false,
},
'project.history_retention_seconds': {
Expand Down Expand Up @@ -242,11 +242,10 @@ export const branchCreateRequest = {
description: "Whether to create the branch as archived\n",
demandOption: false,
},
'branch.schema_initialization_type': {
'branch.init_source': {
type: "string",
description: "The type of schema initialization. Defines how the schema is initialized, currently only empty is supported. This parameter is under\nactive development and may change its semantics in the future.\n",
description: "The initialization source type for the branch. Valid values are `import`, `empty`, `schema` and `parent-data`.\nThis parameter is under active development and may change its semantics in the future.\n",
demandOption: false,
choices: ["empty"],
},
} as const;

Expand All @@ -264,7 +263,7 @@ export const branchCreateRequestEndpointOptions = {
},
'suspend_timeout_seconds': {
type: "number",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the default value.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Scale to zero configuration](https://neon.tech/docs/manage/endpoints#scale-to-zero-configuration).\n",
demandOption: false,
},
} as const;
Expand Down Expand Up @@ -327,7 +326,7 @@ export const endpointCreateRequest = {
},
'endpoint.suspend_timeout_seconds': {
type: "number",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the default value.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Scale to zero configuration](https://neon.tech/docs/manage/endpoints#scale-to-zero-configuration).\n",
demandOption: false,
},
} as const;
Expand Down Expand Up @@ -366,7 +365,7 @@ export const endpointUpdateRequest = {
},
'endpoint.suspend_timeout_seconds': {
type: "number",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n",
description: "Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the default value.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe minimum value is `60` seconds (1 minute).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Scale to zero configuration](https://neon.tech/docs/manage/endpoints#scale-to-zero-configuration).\n",
demandOption: false,
},
} as const;
Expand Down

0 comments on commit 714f08b

Please sign in to comment.