neonctl 1.29.3 → 1.29.4
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.
|
@@ -95,20 +95,22 @@ export const handler = async (props) => {
|
|
|
95
95
|
.map((r) => r.name)
|
|
96
96
|
.join(', ')}`);
|
|
97
97
|
}));
|
|
98
|
+
const { data: { databases: branchDatabases }, } = await props.apiClient.listProjectBranchDatabases(projectId, branchId);
|
|
98
99
|
const database = props.databaseName ||
|
|
99
|
-
(
|
|
100
|
-
.
|
|
101
|
-
.then(({ data }) => {
|
|
102
|
-
if (data.databases.length === 0) {
|
|
100
|
+
(() => {
|
|
101
|
+
if (branchDatabases.length === 0) {
|
|
103
102
|
throw new Error(`No databases found for the branch: ${branchId}`);
|
|
104
103
|
}
|
|
105
|
-
if (
|
|
106
|
-
return
|
|
104
|
+
if (branchDatabases.length === 1) {
|
|
105
|
+
return branchDatabases[0].name;
|
|
107
106
|
}
|
|
108
|
-
throw new Error(`Multiple databases found for the branch, please provide one with the --database-name option: ${
|
|
107
|
+
throw new Error(`Multiple databases found for the branch, please provide one with the --database-name option: ${branchDatabases
|
|
109
108
|
.map((d) => d.name)
|
|
110
109
|
.join(', ')}`);
|
|
111
|
-
}));
|
|
110
|
+
})();
|
|
111
|
+
if (!branchDatabases.find((d) => d.name === database)) {
|
|
112
|
+
throw new Error(`Database not found: ${database}`);
|
|
113
|
+
}
|
|
112
114
|
const { data: { password }, } = await props.apiClient.getProjectBranchRolePassword(props.projectId, endpoint.branch_id, role);
|
|
113
115
|
let host = props.pooled
|
|
114
116
|
? endpoint.host.replace(endpoint.id, `${endpoint.id}-pooler`)
|
|
@@ -116,7 +118,7 @@ export const handler = async (props) => {
|
|
|
116
118
|
if (parsedPIT.tag !== 'head') {
|
|
117
119
|
host = endpoint.host.replace(endpoint.id, endpoint.branch_id);
|
|
118
120
|
}
|
|
119
|
-
const connectionString = new URL(`
|
|
121
|
+
const connectionString = new URL(`postgresql://${host}`);
|
|
120
122
|
connectionString.pathname = database;
|
|
121
123
|
connectionString.username = role;
|
|
122
124
|
connectionString.password = password;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe } from '@jest/globals';
|
|
1
|
+
import { describe, expect } from '@jest/globals';
|
|
2
2
|
import { testCliCommand } from '../test_utils/test_cli_command';
|
|
3
3
|
describe('connection_string', () => {
|
|
4
4
|
testCliCommand({
|
|
@@ -233,4 +233,21 @@ describe('connection_string', () => {
|
|
|
233
233
|
snapshot: true,
|
|
234
234
|
},
|
|
235
235
|
});
|
|
236
|
+
testCliCommand({
|
|
237
|
+
name: 'connection_string fails for non-existing database',
|
|
238
|
+
args: [
|
|
239
|
+
'connection-string',
|
|
240
|
+
'test_branch',
|
|
241
|
+
'--project-id',
|
|
242
|
+
'test',
|
|
243
|
+
'--database-name',
|
|
244
|
+
'non_existing_db',
|
|
245
|
+
'--role-name',
|
|
246
|
+
'test_role',
|
|
247
|
+
],
|
|
248
|
+
expected: {
|
|
249
|
+
code: 1,
|
|
250
|
+
stderr: expect.stringMatching(/Database not found/),
|
|
251
|
+
},
|
|
252
|
+
});
|
|
236
253
|
});
|