neon 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/dist/_shared/auth_selection.js +76 -79
- package/dist/_shared/credentials.js +166 -187
- package/dist/_shared/env-core/env.js +354 -517
- package/dist/_shared/env-core/reuse-secrets.js +159 -203
- package/dist/_shared/paths.js +129 -126
- package/dist/_shared/profiles.js +192 -242
- package/dist/_shared/secure_file.js +36 -38
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/analytics.js +163 -207
- package/dist/api.js +815 -758
- package/dist/auth.js +121 -141
- package/dist/auth_context.js +39 -53
- package/dist/cli.js +4 -7
- package/dist/commands/api.js +220 -250
- package/dist/commands/api_keys.js +251 -314
- package/dist/commands/auth.js +283 -328
- package/dist/commands/bootstrap.js +372 -437
- package/dist/commands/branches.js +304 -455
- package/dist/commands/bucket.js +374 -514
- package/dist/commands/checkout.js +213 -298
- package/dist/commands/config.js +573 -690
- package/dist/commands/connection_string.js +137 -165
- package/dist/commands/data_api.js +238 -260
- package/dist/commands/databases.js +67 -76
- package/dist/commands/deploy.js +31 -25
- package/dist/commands/dev.js +639 -719
- package/dist/commands/diff.js +156 -200
- package/dist/commands/env.js +243 -303
- package/dist/commands/functions.js +275 -355
- package/dist/commands/index.js +70 -65
- package/dist/commands/init.js +84 -119
- package/dist/commands/inspect.js +55 -55
- package/dist/commands/ip_allow.js +88 -120
- package/dist/commands/link.js +874 -1019
- package/dist/commands/logs.js +291 -0
- package/dist/commands/neon_auth.js +725 -933
- package/dist/commands/operations.js +34 -25
- package/dist/commands/orgs.js +28 -18
- package/dist/commands/profile.js +614 -845
- package/dist/commands/projects.js +313 -373
- package/dist/commands/psql.js +60 -58
- package/dist/commands/roles.js +55 -58
- package/dist/commands/schema_diff.js +87 -131
- package/dist/commands/set_context.js +34 -26
- package/dist/commands/snapshots.js +288 -413
- package/dist/commands/status.js +41 -37
- package/dist/commands/user.js +21 -10
- package/dist/commands/vpc_endpoints.js +85 -113
- package/dist/config.js +7 -6
- package/dist/config_format.js +50 -66
- package/dist/config_template.js +128 -157
- package/dist/context.js +183 -235
- package/dist/current_branch_fast_path.js +40 -49
- package/dist/dev/env.js +313 -394
- package/dist/dev/functions.js +54 -68
- package/dist/dev/inputs.js +46 -58
- package/dist/dev/runtime.js +135 -164
- package/dist/dev/websocket.js +766 -959
- package/dist/env.js +27 -33
- package/dist/env_file.js +118 -132
- package/dist/env_services.js +36 -38
- package/dist/errors.js +57 -68
- package/dist/functions_api.js +45 -43
- package/dist/help.js +189 -140
- package/dist/index.js +182 -257
- package/dist/init/agents.js +137 -118
- package/dist/init/auth.js +58 -68
- package/dist/init/bootstrap.js +325 -396
- package/dist/init/build_config.js +4 -2
- package/dist/init/detect_agent.js +56 -101
- package/dist/init/editors.js +35 -52
- package/dist/init/enrich_output.js +51 -66
- package/dist/init/extension.js +134 -171
- package/dist/init/inspect.js +179 -266
- package/dist/init/interactive.js +510 -622
- package/dist/init/neonctl.js +117 -168
- package/dist/init/orchestrate.js +157 -173
- package/dist/init/phases/auth.js +188 -202
- package/dist/init/phases/cleanup.js +23 -23
- package/dist/init/phases/db.js +251 -277
- package/dist/init/phases/getting_started.js +213 -223
- package/dist/init/phases/mcp.js +174 -224
- package/dist/init/phases/migrations.js +247 -248
- package/dist/init/phases/neon_auth.js +114 -133
- package/dist/init/phases/setup.js +546 -703
- package/dist/init/phases/skills.js +75 -86
- package/dist/init/phases/status.js +72 -67
- package/dist/init/resolve_context.js +102 -99
- package/dist/init/route_command.js +91 -98
- package/dist/init/skills.js +174 -218
- package/dist/init/vsix.js +77 -99
- package/dist/log.js +17 -16
- package/dist/neon_services.js +104 -129
- package/dist/parameters.gen.js +481 -471
- package/dist/pkg.js +17 -19
- package/dist/profile_keys.js +44 -47
- package/dist/psql/cli.js +44 -47
- package/dist/psql/command/cmd_cond.js +231 -406
- package/dist/psql/command/cmd_connect.js +557 -764
- package/dist/psql/command/cmd_copy.js +727 -983
- package/dist/psql/command/cmd_describe.js +1499 -1688
- package/dist/psql/command/cmd_format.js +733 -905
- package/dist/psql/command/cmd_io.js +1293 -2082
- package/dist/psql/command/cmd_lo.js +297 -359
- package/dist/psql/command/cmd_meta.js +727 -878
- package/dist/psql/command/cmd_misc.js +138 -172
- package/dist/psql/command/cmd_pipeline.js +547 -1099
- package/dist/psql/command/cmd_restrict.js +119 -155
- package/dist/psql/command/cmd_show.js +529 -688
- package/dist/psql/command/dispatch.js +261 -325
- package/dist/psql/command/inputQueue.js +35 -33
- package/dist/psql/command/shared.js +49 -63
- package/dist/psql/complete/filenames.js +90 -133
- package/dist/psql/complete/index.js +59 -97
- package/dist/psql/complete/matcher.js +236 -300
- package/dist/psql/complete/psqlVars.js +218 -223
- package/dist/psql/complete/queries.js +159 -177
- package/dist/psql/complete/rules.js +1493 -2299
- package/dist/psql/core/common.js +762 -1180
- package/dist/psql/core/help.js +456 -546
- package/dist/psql/core/mainloop.js +692 -1302
- package/dist/psql/core/prompt.js +391 -408
- package/dist/psql/core/settings.js +429 -644
- package/dist/psql/core/sqlHelp.js +480 -554
- package/dist/psql/core/startup.js +626 -815
- package/dist/psql/core/syncVars.js +67 -110
- package/dist/psql/core/variables.js +156 -278
- package/dist/psql/describe/formatters.js +884 -1285
- package/dist/psql/describe/processNamePattern.js +173 -260
- package/dist/psql/describe/queries.js +1368 -2403
- package/dist/psql/describe/versionGate.js +32 -41
- package/dist/psql/index.js +1414 -1927
- package/dist/psql/io/history.js +232 -271
- package/dist/psql/io/input.js +103 -108
- package/dist/psql/io/lineEditor/buffer.js +238 -319
- package/dist/psql/io/lineEditor/complete.js +135 -213
- package/dist/psql/io/lineEditor/filename.js +139 -148
- package/dist/psql/io/lineEditor/index.js +653 -870
- package/dist/psql/io/lineEditor/keymap.js +544 -702
- package/dist/psql/io/lineEditor/vt100.js +294 -341
- package/dist/psql/io/pgpass.js +158 -187
- package/dist/psql/io/pgservice.js +146 -183
- package/dist/psql/io/psqlrc.js +328 -403
- package/dist/psql/print/aligned.js +1020 -1683
- package/dist/psql/print/asciidoc.js +180 -214
- package/dist/psql/print/crosstab.js +281 -442
- package/dist/psql/print/csv.js +48 -70
- package/dist/psql/print/html.js +195 -226
- package/dist/psql/print/json.js +75 -88
- package/dist/psql/print/latex.js +291 -364
- package/dist/psql/print/pager.js +171 -242
- package/dist/psql/print/troff.js +194 -226
- package/dist/psql/print/unaligned.js +69 -95
- package/dist/psql/print/units.js +167 -169
- package/dist/psql/scanner/slash.js +428 -483
- package/dist/psql/scanner/sql.js +445 -889
- package/dist/psql/scanner/stringutils.js +309 -379
- package/dist/psql/types/index.js +2 -7
- package/dist/psql/types/scanner.js +25 -22
- package/dist/psql/wire/connection.js +2042 -2803
- package/dist/psql/wire/copy.js +84 -100
- package/dist/psql/wire/notify.js +39 -59
- package/dist/psql/wire/pipeline.js +305 -518
- package/dist/psql/wire/protocol.js +349 -417
- package/dist/psql/wire/sasl.js +180 -265
- package/dist/psql/wire/tls.js +400 -561
- package/dist/storage_api.js +115 -129
- package/dist/test_utils/fixtures.js +94 -113
- package/dist/test_utils/oauth_server.js +10 -7
- package/dist/test_utils/project_dir.js +33 -0
- package/dist/utils/ai_gateway_notice.js +131 -162
- package/dist/utils/api_enums.js +21 -28
- package/dist/utils/auth.js +10 -4
- package/dist/utils/branch_notice.js +20 -19
- package/dist/utils/branch_picker.js +83 -89
- package/dist/utils/cli_name.js +15 -12
- package/dist/utils/compute_units.js +20 -27
- package/dist/utils/config_diff.js +127 -158
- package/dist/utils/enrichers.js +95 -148
- package/dist/utils/esbuild.js +130 -189
- package/dist/utils/flags.js +35 -47
- package/dist/utils/formats.js +8 -15
- package/dist/utils/git_diff.js +69 -80
- package/dist/utils/inspect_db.js +101 -143
- package/dist/utils/inspect_queries.js +179 -142
- package/dist/utils/middlewares.js +37 -44
- package/dist/utils/openapi.js +87 -99
- package/dist/utils/package_manager.js +312 -110
- package/dist/utils/point_in_time.js +49 -53
- package/dist/utils/psql.js +89 -106
- package/dist/utils/service_picker.js +55 -58
- package/dist/utils/string.js +5 -5
- package/dist/utils/ui.js +38 -55
- package/dist/utils/write_sync.js +26 -35
- package/dist/utils/zip.js +4 -3
- package/dist/writer.js +67 -87
- package/package.json +7 -5
|
@@ -1,488 +1,337 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { log } from "../log.js";
|
|
1
3
|
import { retryOnLock } from "../api.js";
|
|
2
4
|
import { contextBranch, readContextFile } from "../context.js";
|
|
3
|
-
import {
|
|
5
|
+
import { writer } from "../writer.js";
|
|
4
6
|
import { branchCreateRequest } from "../parameters.gen.js";
|
|
5
7
|
import { EndpointType } from "../utils/api_enums.js";
|
|
6
8
|
import { getComputeUnits } from "../utils/compute_units.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
+
import { looksLikeBranchId, looksLikeLSN, looksLikeTimestamp } from "../utils/formats.js";
|
|
10
|
+
import { branchIdFromProps, branchIdResolve, fillSingleProject } from "../utils/enrichers.js";
|
|
9
11
|
import { parsePointInTime } from "../utils/point_in_time.js";
|
|
10
12
|
import { psql } from "../utils/psql.js";
|
|
11
|
-
import { writer } from "../writer.js";
|
|
12
13
|
import { parseSchemaDiffParams, schemaDiff } from "./schema_diff.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
//#region src/commands/branches.ts
|
|
15
|
+
var branches_exports = /* @__PURE__ */ __exportAll({
|
|
16
|
+
BRANCH_FIELDS: () => BRANCH_FIELDS,
|
|
17
|
+
aliases: () => aliases,
|
|
18
|
+
builder: () => builder,
|
|
19
|
+
command: () => command,
|
|
20
|
+
describe: () => describe,
|
|
21
|
+
handler: () => handler
|
|
22
|
+
});
|
|
23
|
+
const BRANCH_FIELDS = [
|
|
24
|
+
"name",
|
|
25
|
+
"id",
|
|
26
|
+
"current_state",
|
|
27
|
+
"created_at",
|
|
28
|
+
"expires_at"
|
|
19
29
|
];
|
|
20
30
|
const BRANCH_FIELDS_RESET = [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
"name",
|
|
32
|
+
"id",
|
|
33
|
+
"default",
|
|
34
|
+
"current_state",
|
|
35
|
+
"created_at",
|
|
36
|
+
"last_reset_at"
|
|
27
37
|
];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
builder: (yargs) => yargs.options({
|
|
154
|
-
"expires-at": {
|
|
155
|
-
describe: "Set a expiration date for the branch. If omitted, expiration will be removed. Format [RFC3339]: 2024-12-31T23:59:59Z",
|
|
156
|
-
type: "string",
|
|
157
|
-
requiresArg: false,
|
|
158
|
-
},
|
|
159
|
-
}),
|
|
160
|
-
handler: (args) => setExpiration(args),
|
|
161
|
-
})
|
|
162
|
-
.command("add-compute <id|name>", "Add a compute to a branch", (yargs) => yargs.options({
|
|
163
|
-
type: {
|
|
164
|
-
type: "string",
|
|
165
|
-
choices: Object.values(EndpointType),
|
|
166
|
-
describe: "Type of compute to add",
|
|
167
|
-
default: EndpointType.ReadOnly,
|
|
168
|
-
},
|
|
169
|
-
cu: {
|
|
170
|
-
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").',
|
|
171
|
-
type: "string",
|
|
172
|
-
},
|
|
173
|
-
name: {
|
|
174
|
-
type: "string",
|
|
175
|
-
describe: "Optional name of the compute",
|
|
176
|
-
},
|
|
177
|
-
}), (args) => addCompute(args))
|
|
178
|
-
.command("delete <id|name>", "Delete a branch", (yargs) => yargs, (args) => deleteBranch(args))
|
|
179
|
-
.command("get <id|name>", "Get a branch", (yargs) => yargs, (args) => get(args))
|
|
180
|
-
.command({
|
|
181
|
-
command: "schema-diff [base-branch] [compare-source[@(timestamp|lsn)]]",
|
|
182
|
-
aliases: ["sd"],
|
|
183
|
-
describe: "Compare the latest schemas of any two branches, or compare a branch to its own or another branch's history.",
|
|
184
|
-
builder: (yargs) => {
|
|
185
|
-
return yargs
|
|
186
|
-
.middleware((args) => (args.compareSource =
|
|
187
|
-
args["compare-source@(timestamp"]))
|
|
188
|
-
.middleware(parseSchemaDiffParams)
|
|
189
|
-
.options({
|
|
190
|
-
database: {
|
|
191
|
-
alias: "db",
|
|
192
|
-
type: "string",
|
|
193
|
-
description: "Name of the database for which the schema comparison is performed",
|
|
194
|
-
},
|
|
195
|
-
})
|
|
196
|
-
.example([
|
|
197
|
-
[
|
|
198
|
-
"$0 branches schema-diff main br-compare-branch-123456",
|
|
199
|
-
"Compares the main branch to the head of the branch with ID br-compare-branch-123456",
|
|
200
|
-
],
|
|
201
|
-
[
|
|
202
|
-
"$0 branches schema-diff main compare@2024-06-01T00:00:00Z",
|
|
203
|
-
"Compares the main branch to the state of the compare branch at timestamp 2024-06-01T00:00:00.000Z",
|
|
204
|
-
],
|
|
205
|
-
[
|
|
206
|
-
"$0 branches schema-diff my-branch ^self@0/123456",
|
|
207
|
-
"Compares my-branch to LSN 0/123456 from its own history",
|
|
208
|
-
],
|
|
209
|
-
[
|
|
210
|
-
"$0 branches schema-diff my-branch ^parent",
|
|
211
|
-
"Compares my-branch to the head of its parent branch",
|
|
212
|
-
],
|
|
213
|
-
[
|
|
214
|
-
"$0 branches schema-diff",
|
|
215
|
-
"If a branch is specified in 'set-context', compares this branch to its parent. Otherwise, compares the default branch to its parent.",
|
|
216
|
-
],
|
|
217
|
-
]);
|
|
218
|
-
},
|
|
219
|
-
handler: (args) => schemaDiff(args),
|
|
38
|
+
const command = "branches";
|
|
39
|
+
const describe = "Manage branches";
|
|
40
|
+
const aliases = ["branch"];
|
|
41
|
+
const builder = (argv) => argv.usage("$0 branches <sub-command> [options]").options({ "project-id": {
|
|
42
|
+
describe: "Project ID",
|
|
43
|
+
type: "string"
|
|
44
|
+
} }).middleware(fillSingleProject).middleware((args) => {
|
|
45
|
+
args.branchId ??= args.id;
|
|
46
|
+
}).command("list", "List branches", (yargs) => yargs, (args) => list(args)).command("create", "Create a branch", (yargs) => yargs.options({
|
|
47
|
+
name: branchCreateRequest["branch.name"],
|
|
48
|
+
parent: {
|
|
49
|
+
describe: "Parent branch name or id or timestamp or LSN. Defaults to the default branch",
|
|
50
|
+
type: "string"
|
|
51
|
+
},
|
|
52
|
+
compute: {
|
|
53
|
+
describe: "Create a branch with or without a compute. By default branch is created with a read-write compute. To create a branch without compute use --no-compute",
|
|
54
|
+
type: "boolean",
|
|
55
|
+
default: true
|
|
56
|
+
},
|
|
57
|
+
type: {
|
|
58
|
+
describe: "Type of compute to add",
|
|
59
|
+
type: "string",
|
|
60
|
+
implies: "compute",
|
|
61
|
+
default: EndpointType.ReadWrite,
|
|
62
|
+
choices: Object.values(EndpointType)
|
|
63
|
+
},
|
|
64
|
+
"suspend-timeout": {
|
|
65
|
+
describe: "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 maximum value is `604800` seconds (1 week).",
|
|
66
|
+
type: "number",
|
|
67
|
+
implies: "compute",
|
|
68
|
+
default: 0
|
|
69
|
+
},
|
|
70
|
+
cu: {
|
|
71
|
+
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\").",
|
|
72
|
+
type: "string",
|
|
73
|
+
implies: "compute"
|
|
74
|
+
},
|
|
75
|
+
psql: {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
describe: "Connect to a new branch via psql",
|
|
78
|
+
default: false
|
|
79
|
+
},
|
|
80
|
+
fallback: {
|
|
81
|
+
type: "boolean",
|
|
82
|
+
describe: "Force the embedded TypeScript psql fallback (for testing)",
|
|
83
|
+
default: false,
|
|
84
|
+
hidden: true
|
|
85
|
+
},
|
|
86
|
+
annotation: {
|
|
87
|
+
type: "string",
|
|
88
|
+
hidden: true,
|
|
89
|
+
default: "{}"
|
|
90
|
+
},
|
|
91
|
+
"schema-only": {
|
|
92
|
+
describe: "Create a schema-only branch. Requires exactly one read-write compute.",
|
|
93
|
+
type: "boolean",
|
|
94
|
+
default: false
|
|
95
|
+
},
|
|
96
|
+
"expires-at": {
|
|
97
|
+
describe: "Set an expiration date for the branch. Accepts a date string (e.g., 2024-12-31T23:59:59Z).",
|
|
98
|
+
type: "string",
|
|
99
|
+
requiresArg: true
|
|
100
|
+
},
|
|
101
|
+
protected: {
|
|
102
|
+
describe: branchCreateRequest["branch.protected"].description,
|
|
103
|
+
type: "boolean"
|
|
104
|
+
}
|
|
105
|
+
}), (args) => create(args)).command("reset <id|name>", "Reset a branch", (yargs) => yargs.options({
|
|
106
|
+
parent: {
|
|
107
|
+
describe: "Reset to a parent branch",
|
|
108
|
+
type: "boolean",
|
|
109
|
+
default: false
|
|
110
|
+
},
|
|
111
|
+
"preserve-under-name": { describe: "Name under which to preserve the old branch" }
|
|
112
|
+
}), (args) => reset(args)).command("restore <target-id|name> <source>[@(timestamp|lsn)]", "Restores a branch to a specific point in time\n<source> can be: ^self, ^parent, or <source-branch-id|name>", (yargs) => yargs.middleware((args) => {
|
|
113
|
+
args.id = args.targetId;
|
|
114
|
+
args.pointInTime = args["source@(timestamp"];
|
|
115
|
+
args.branchId = args.id;
|
|
116
|
+
}).usage("$0 branches restore <target-id|name> <source>[@(timestamp|lsn)]").options({ "preserve-under-name": { describe: "Name under which to preserve the old branch" } }).example([
|
|
117
|
+
["$0 branches restore main br-source-branch-123456", "Restores main to the head of the branch with id br-source-branch-123456"],
|
|
118
|
+
["$0 branches restore main source@2021-01-01T00:00:00Z", "Restores main to the timestamp 2021-01-01T00:00:00Z of the source branch"],
|
|
119
|
+
["$0 branches restore my-branch ^self@0/123456", "Restores my-branch to the LSN 0/123456 from its own history"],
|
|
120
|
+
["$0 branches restore my-branch ^parent", "Restore my-branch to the head of its parent branch"]
|
|
121
|
+
]), (args) => restore(args)).command("rename <id|name> <new-name>", "Rename a branch", (yargs) => yargs, (args) => rename(args)).command("set-default <id|name>", "Set a branch as default", (yargs) => yargs, (args) => setDefault(args)).command({
|
|
122
|
+
command: "set-expiration <id|name>",
|
|
123
|
+
describe: "Set an expiration date for the branch",
|
|
124
|
+
builder: (yargs) => yargs.options({ "expires-at": {
|
|
125
|
+
describe: "Set a expiration date for the branch. If omitted, expiration will be removed. Format [RFC3339]: 2024-12-31T23:59:59Z",
|
|
126
|
+
type: "string",
|
|
127
|
+
requiresArg: false
|
|
128
|
+
} }),
|
|
129
|
+
handler: (args) => setExpiration(args)
|
|
130
|
+
}).command("add-compute <id|name>", "Add a compute to a branch", (yargs) => yargs.options({
|
|
131
|
+
type: {
|
|
132
|
+
type: "string",
|
|
133
|
+
choices: Object.values(EndpointType),
|
|
134
|
+
describe: "Type of compute to add",
|
|
135
|
+
default: EndpointType.ReadOnly
|
|
136
|
+
},
|
|
137
|
+
cu: {
|
|
138
|
+
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\").",
|
|
139
|
+
type: "string"
|
|
140
|
+
},
|
|
141
|
+
name: {
|
|
142
|
+
type: "string",
|
|
143
|
+
describe: "Optional name of the compute"
|
|
144
|
+
}
|
|
145
|
+
}), (args) => addCompute(args)).command("delete <id|name>", "Delete a branch", (yargs) => yargs, (args) => deleteBranch(args)).command("get <id|name>", "Get a branch", (yargs) => yargs, (args) => get(args)).command({
|
|
146
|
+
command: "schema-diff [base-branch] [compare-source[@(timestamp|lsn)]]",
|
|
147
|
+
aliases: ["sd"],
|
|
148
|
+
describe: "Compare the latest schemas of any two branches, or compare a branch to its own or another branch's history.",
|
|
149
|
+
builder: (yargs) => {
|
|
150
|
+
return yargs.middleware((args) => args.compareSource = args["compare-source@(timestamp"]).middleware(parseSchemaDiffParams).options({ database: {
|
|
151
|
+
alias: "db",
|
|
152
|
+
type: "string",
|
|
153
|
+
description: "Name of the database for which the schema comparison is performed"
|
|
154
|
+
} }).example([
|
|
155
|
+
["$0 branches schema-diff main br-compare-branch-123456", "Compares the main branch to the head of the branch with ID br-compare-branch-123456"],
|
|
156
|
+
["$0 branches schema-diff main compare@2024-06-01T00:00:00Z", "Compares the main branch to the state of the compare branch at timestamp 2024-06-01T00:00:00.000Z"],
|
|
157
|
+
["$0 branches schema-diff my-branch ^self@0/123456", "Compares my-branch to LSN 0/123456 from its own history"],
|
|
158
|
+
["$0 branches schema-diff my-branch ^parent", "Compares my-branch to the head of its parent branch"],
|
|
159
|
+
["$0 branches schema-diff", "If a branch is specified in 'set-context', compares this branch to its parent. Otherwise, compares the default branch to its parent."]
|
|
160
|
+
]);
|
|
161
|
+
},
|
|
162
|
+
handler: (args) => schemaDiff(args)
|
|
220
163
|
});
|
|
221
|
-
|
|
222
|
-
|
|
164
|
+
const handler = (args) => {
|
|
165
|
+
return args;
|
|
223
166
|
};
|
|
224
167
|
const list = async (props) => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
if (br.protected) {
|
|
245
|
-
labels.push("[protected]");
|
|
246
|
-
}
|
|
247
|
-
if (isAnon) {
|
|
248
|
-
labels.push("[anon]");
|
|
249
|
-
}
|
|
250
|
-
if (currentBranch !== undefined &&
|
|
251
|
-
(br.id === currentBranch || br.name === currentBranch)) {
|
|
252
|
-
labels.push("[current]");
|
|
253
|
-
}
|
|
254
|
-
labels.push(br.name);
|
|
255
|
-
return labels.join(" ");
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
});
|
|
168
|
+
const { data: { branches, annotations } } = await props.apiClient.listProjectBranches({ projectId: props.projectId });
|
|
169
|
+
const currentBranch = contextBranch(readContextFile(props.contextFile));
|
|
170
|
+
writer(props).end(branches, {
|
|
171
|
+
fields: BRANCH_FIELDS,
|
|
172
|
+
renderColumns: {
|
|
173
|
+
expires_at: (br) => br.expires_at || "never",
|
|
174
|
+
name: (br) => {
|
|
175
|
+
const isAnon = annotations[br.id]?.value.anonymized;
|
|
176
|
+
const labels = [];
|
|
177
|
+
if (br.default) labels.push("[default]");
|
|
178
|
+
if (br.protected) labels.push("[protected]");
|
|
179
|
+
if (isAnon) labels.push("[anon]");
|
|
180
|
+
if (currentBranch !== void 0 && (br.id === currentBranch || br.name === currentBranch)) labels.push("[current]");
|
|
181
|
+
labels.push(br.name);
|
|
182
|
+
return labels.join(" ");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
259
186
|
};
|
|
260
187
|
const create = async (props) => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
? getComputeUnits(props.cu)
|
|
319
|
-
: undefined),
|
|
320
|
-
},
|
|
321
|
-
]
|
|
322
|
-
: [],
|
|
323
|
-
annotation_value: props.annotation
|
|
324
|
-
? JSON.parse(props.annotation)
|
|
325
|
-
: undefined,
|
|
326
|
-
}));
|
|
327
|
-
const parent = branches.find((b) => b.id === data.branch.parent_id);
|
|
328
|
-
if (parent?.protected) {
|
|
329
|
-
log.warning("The parent branch is protected; a unique role password has been generated for the new branch.");
|
|
330
|
-
}
|
|
331
|
-
const out = writer(props);
|
|
332
|
-
out.write(data.branch, {
|
|
333
|
-
fields: BRANCH_FIELDS,
|
|
334
|
-
title: "branch",
|
|
335
|
-
emptyMessage: "No branches have been found.",
|
|
336
|
-
});
|
|
337
|
-
if (data.endpoints?.length > 0) {
|
|
338
|
-
out.write(data.endpoints, {
|
|
339
|
-
fields: ["id", "created_at"],
|
|
340
|
-
title: "endpoints",
|
|
341
|
-
emptyMessage: "No endpoints have been found.",
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
if (data.connection_uris?.length) {
|
|
345
|
-
out.write(data.connection_uris, {
|
|
346
|
-
fields: ["connection_uri"],
|
|
347
|
-
title: "connection_uris",
|
|
348
|
-
emptyMessage: "No connection uris have been found",
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
out.end();
|
|
352
|
-
if (props.psql) {
|
|
353
|
-
if (!data.connection_uris?.length) {
|
|
354
|
-
throw new Error(`Branch ${data.branch.id} doesn't have a connection uri`);
|
|
355
|
-
}
|
|
356
|
-
const connection_uri = data.connection_uris[0].connection_uri;
|
|
357
|
-
const psqlArgs = props["--"];
|
|
358
|
-
await psql(connection_uri, psqlArgs, {
|
|
359
|
-
mode: props.fallback ? "ts" : "auto",
|
|
360
|
-
});
|
|
361
|
-
}
|
|
188
|
+
const branches = await props.apiClient.listProjectBranches({ projectId: props.projectId }).then(({ data }) => data.branches);
|
|
189
|
+
const parentProps = (() => {
|
|
190
|
+
if (!props.parent) {
|
|
191
|
+
const branch = branches.find((b) => b.default);
|
|
192
|
+
if (!branch) throw new Error("No default branch found");
|
|
193
|
+
return { parent_id: branch.id };
|
|
194
|
+
}
|
|
195
|
+
if (looksLikeLSN(props.parent)) return { parent_lsn: props.parent };
|
|
196
|
+
if (looksLikeTimestamp(props.parent)) return { parent_timestamp: props.parent };
|
|
197
|
+
if (looksLikeBranchId(props.parent)) return { parent_id: props.parent };
|
|
198
|
+
const branch = branches.find((b) => b.name === props.parent);
|
|
199
|
+
if (!branch) throw new Error(`Branch ${props.parent} not found`);
|
|
200
|
+
return { parent_id: branch.id };
|
|
201
|
+
})();
|
|
202
|
+
if (props.schemaOnly) {
|
|
203
|
+
if (!props.compute) throw new Error("Schema-only branches require a compute endpoint");
|
|
204
|
+
if (props.type !== EndpointType.ReadWrite) throw new Error("Schema-only branches require a read-write compute endpoint");
|
|
205
|
+
}
|
|
206
|
+
const { data } = await retryOnLock(() => props.apiClient.createProjectBranch(props.projectId, {
|
|
207
|
+
branch: {
|
|
208
|
+
name: props.name,
|
|
209
|
+
...parentProps,
|
|
210
|
+
...props.schemaOnly ? { init_source: "schema-only" } : {},
|
|
211
|
+
...props["expires-at"] ? { expires_at: new Date(props["expires-at"]).toISOString() } : {},
|
|
212
|
+
...props.protected !== void 0 ? { protected: props.protected } : {}
|
|
213
|
+
},
|
|
214
|
+
endpoints: props.compute ? [{
|
|
215
|
+
type: props.type,
|
|
216
|
+
suspend_timeout_seconds: props.suspendTimeout === 0 ? void 0 : props.suspendTimeout,
|
|
217
|
+
...props.cu ? getComputeUnits(props.cu) : void 0
|
|
218
|
+
}] : [],
|
|
219
|
+
annotation_value: props.annotation ? JSON.parse(props.annotation) : void 0
|
|
220
|
+
}));
|
|
221
|
+
if (branches.find((b) => b.id === data.branch.parent_id)?.protected) log.warning("The parent branch is protected; a unique role password has been generated for the new branch.");
|
|
222
|
+
const out = writer(props);
|
|
223
|
+
out.write(data.branch, {
|
|
224
|
+
fields: BRANCH_FIELDS,
|
|
225
|
+
title: "branch",
|
|
226
|
+
emptyMessage: "No branches have been found."
|
|
227
|
+
});
|
|
228
|
+
if (data.endpoints?.length > 0) out.write(data.endpoints, {
|
|
229
|
+
fields: ["id", "created_at"],
|
|
230
|
+
title: "endpoints",
|
|
231
|
+
emptyMessage: "No endpoints have been found."
|
|
232
|
+
});
|
|
233
|
+
if (data.connection_uris?.length) out.write(data.connection_uris, {
|
|
234
|
+
fields: ["connection_uri"],
|
|
235
|
+
title: "connection_uris",
|
|
236
|
+
emptyMessage: "No connection uris have been found"
|
|
237
|
+
});
|
|
238
|
+
out.end();
|
|
239
|
+
if (props.psql) {
|
|
240
|
+
if (!data.connection_uris?.length) throw new Error(`Branch ${data.branch.id} doesn't have a connection uri`);
|
|
241
|
+
const connection_uri = data.connection_uris[0].connection_uri;
|
|
242
|
+
const psqlArgs = props["--"];
|
|
243
|
+
await psql(connection_uri, psqlArgs, { mode: props.fallback ? "ts" : "auto" });
|
|
244
|
+
}
|
|
362
245
|
};
|
|
363
246
|
const rename = async (props) => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
name: props.newName,
|
|
368
|
-
},
|
|
369
|
-
}));
|
|
370
|
-
writer(props).end(data.branch, {
|
|
371
|
-
fields: BRANCH_FIELDS,
|
|
372
|
-
});
|
|
247
|
+
const branchId = await branchIdFromProps(props);
|
|
248
|
+
const { data } = await retryOnLock(() => props.apiClient.updateProjectBranch(props.projectId, branchId, { branch: { name: props.newName } }));
|
|
249
|
+
writer(props).end(data.branch, { fields: BRANCH_FIELDS });
|
|
373
250
|
};
|
|
374
251
|
const setDefault = async (props) => {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
fields: BRANCH_FIELDS,
|
|
379
|
-
});
|
|
252
|
+
const branchId = await branchIdFromProps(props);
|
|
253
|
+
const { data } = await retryOnLock(() => props.apiClient.setDefaultProjectBranch(props.projectId, branchId));
|
|
254
|
+
writer(props).end(data.branch, { fields: BRANCH_FIELDS });
|
|
380
255
|
};
|
|
381
256
|
const deleteBranch = async (props) => {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (data) {
|
|
386
|
-
writer(props).end(data.branch, {
|
|
387
|
-
fields: BRANCH_FIELDS,
|
|
388
|
-
});
|
|
389
|
-
}
|
|
257
|
+
const branchId = await branchIdFromProps(props);
|
|
258
|
+
const { data } = await retryOnLock(() => props.apiClient.deleteProjectBranch(props.projectId, branchId));
|
|
259
|
+
if (data) writer(props).end(data.branch, { fields: BRANCH_FIELDS });
|
|
390
260
|
};
|
|
391
261
|
const get = async (props) => {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
fields: BRANCH_FIELDS,
|
|
396
|
-
});
|
|
262
|
+
const branchId = await branchIdFromProps(props);
|
|
263
|
+
const { data } = await props.apiClient.getProjectBranch(props.projectId, branchId);
|
|
264
|
+
writer(props).end(data.branch, { fields: BRANCH_FIELDS });
|
|
397
265
|
};
|
|
398
266
|
const addCompute = async (props) => {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}));
|
|
409
|
-
writer(props).end(data.endpoint, {
|
|
410
|
-
fields: ["id", "host"],
|
|
411
|
-
});
|
|
267
|
+
const branchId = await branchIdFromProps(props);
|
|
268
|
+
const computeName = props.name ? { name: props.name } : null;
|
|
269
|
+
const { data } = await retryOnLock(() => props.apiClient.createProjectEndpoint(props.projectId, { endpoint: {
|
|
270
|
+
branch_id: branchId,
|
|
271
|
+
type: props.type,
|
|
272
|
+
...props.cu ? getComputeUnits(props.cu) : void 0,
|
|
273
|
+
...computeName
|
|
274
|
+
} }));
|
|
275
|
+
writer(props).end(data.endpoint, { fields: ["id", "host"] });
|
|
412
276
|
};
|
|
413
277
|
const reset = async (props) => {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
source_branch_id: parent_id,
|
|
424
|
-
preserve_under_name: props.preserveUnderName || undefined,
|
|
425
|
-
}));
|
|
426
|
-
writer(props).end(data.branch, {
|
|
427
|
-
// need to reset types until we expose reset api
|
|
428
|
-
fields: BRANCH_FIELDS_RESET,
|
|
429
|
-
});
|
|
278
|
+
if (!props.parent) throw new Error("Only resetting to parent is supported for now");
|
|
279
|
+
const branchId = await branchIdFromProps(props);
|
|
280
|
+
const { data: { branch: { parent_id } } } = await props.apiClient.getProjectBranch(props.projectId, branchId);
|
|
281
|
+
if (!parent_id) throw new Error("Branch has no parent");
|
|
282
|
+
const { data } = await retryOnLock(() => props.apiClient.restoreProjectBranch(props.projectId, branchId, {
|
|
283
|
+
source_branch_id: parent_id,
|
|
284
|
+
preserve_under_name: props.preserveUnderName || void 0
|
|
285
|
+
}));
|
|
286
|
+
writer(props).end(data.branch, { fields: BRANCH_FIELDS_RESET });
|
|
430
287
|
};
|
|
431
288
|
const restore = async (props) => {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
writeInst.end();
|
|
289
|
+
const targetBranchId = await branchIdResolve({
|
|
290
|
+
branch: props.id,
|
|
291
|
+
projectId: props.projectId,
|
|
292
|
+
apiClient: props.apiClient
|
|
293
|
+
});
|
|
294
|
+
const pointInTime = await parsePointInTime({
|
|
295
|
+
pointInTime: props.pointInTime,
|
|
296
|
+
targetBranchId,
|
|
297
|
+
projectId: props.projectId,
|
|
298
|
+
api: props.apiClient
|
|
299
|
+
});
|
|
300
|
+
log.info(`Restoring branch ${targetBranchId} to the branch ${pointInTime.branchId} ${pointInTime.tag === "lsn" && "LSN " + pointInTime.lsn || pointInTime.tag === "timestamp" && "timestamp " + pointInTime.timestamp || "head"}`);
|
|
301
|
+
const { data } = await retryOnLock(() => props.apiClient.restoreProjectBranch(props.projectId, targetBranchId, {
|
|
302
|
+
source_branch_id: pointInTime.branchId,
|
|
303
|
+
preserve_under_name: props.preserveUnderName || void 0,
|
|
304
|
+
...pointInTime.tag === "lsn" && { source_lsn: pointInTime.lsn },
|
|
305
|
+
...pointInTime.tag === "timestamp" && { source_timestamp: pointInTime.timestamp }
|
|
306
|
+
}));
|
|
307
|
+
const writeInst = writer(props).write(data.branch, {
|
|
308
|
+
title: "Restored branch",
|
|
309
|
+
fields: [
|
|
310
|
+
"id",
|
|
311
|
+
"name",
|
|
312
|
+
"last_reset_at"
|
|
313
|
+
],
|
|
314
|
+
emptyMessage: "No branches have been restored."
|
|
315
|
+
});
|
|
316
|
+
const parentId = data.branch.parent_id;
|
|
317
|
+
if (props.preserveUnderName && parentId) {
|
|
318
|
+
const { data } = await props.apiClient.getProjectBranch(props.projectId, parentId);
|
|
319
|
+
writeInst.write(data.branch, {
|
|
320
|
+
title: "Backup branch",
|
|
321
|
+
fields: ["id", "name"],
|
|
322
|
+
emptyMessage: "Backup branch has not been found."
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
writeInst.end();
|
|
470
326
|
};
|
|
471
327
|
const setExpiration = async (props) => {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
: null;
|
|
480
|
-
const { data } = await retryOnLock(() => props.apiClient.updateProjectBranch(props.projectId, branchId, {
|
|
481
|
-
branch: {
|
|
482
|
-
expires_at: expiresAt,
|
|
483
|
-
},
|
|
484
|
-
}));
|
|
485
|
-
writer(props).end(data.branch, {
|
|
486
|
-
fields: BRANCH_FIELDS,
|
|
487
|
-
});
|
|
328
|
+
const branchId = await branchIdFromProps({
|
|
329
|
+
...props,
|
|
330
|
+
id: props.branchId
|
|
331
|
+
});
|
|
332
|
+
const expiresAt = typeof props.expiresAt === "string" ? new Date(props.expiresAt).toISOString() : null;
|
|
333
|
+
const { data } = await retryOnLock(() => props.apiClient.updateProjectBranch(props.projectId, branchId, { branch: { expires_at: expiresAt } }));
|
|
334
|
+
writer(props).end(data.branch, { fields: BRANCH_FIELDS });
|
|
488
335
|
};
|
|
336
|
+
//#endregion
|
|
337
|
+
export { BRANCH_FIELDS, aliases, branches_exports, builder, command, describe, handler };
|