Skip to content

Commit cad7ec9

Browse files
committed
fix(init): sort postgres versions in desc order (#2267)
Synced from monorepo@d9e0ce6dea8c800f096f43feff4032b2479bf841
1 parent 11ba996 commit cad7ec9

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

.sync-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bac2bcec7cab283c725d2bacef35b10b6f674150
1+
d9e0ce6dea8c800f096f43feff4032b2479bf841

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
"module": "src/app.ts",
77
"type": "module",
88
"devDependencies": {
9-
"@aws-sdk/client-s3": "3.1024.0",
10-
"@types/bun": "1.3.11",
9+
"@aws-sdk/client-s3": "3.1029.0",
10+
"@types/bun": "1.3.12",
1111
"@types/treeify": "1.0.3"
1212
},
1313
"peerDependencies": {
1414
"typescript": "5.9.x"
1515
},
1616
"dependencies": {
17-
"@dotenvx/dotenvx": "1.60.0",
17+
"@dotenvx/dotenvx": "1.61.0",
1818
"@stricli/auto-complete": "1.2.6",
1919
"@stricli/core": "1.2.6",
2020
"chalk": "5.6.2",
2121
"chrono-node": "2.9.0",
2222
"cli-table3": "0.6.5",
2323
"dedent": "1.7.2",
2424
"enquirer": "2.4.1",
25-
"@vercel/detect-agent": "1.2.1",
25+
"@vercel/detect-agent": "1.2.2",
2626
"ci-info": "4.4.0",
2727
"is-reachable": "6.1.0",
2828
"jose": "6.2.2",
@@ -35,15 +35,15 @@
3535
"yaml": "2.8.3",
3636
"zod": "4.3.6",
3737
"zod-config": "1.4.0",
38-
"@xata.io/ai": "0.1.0",
39-
"@xata.io/api": "0.1.0",
4038
"@xata.io/config": "0.0.0",
4139
"@xata.io/lang": "0.0.1",
4240
"@xata.io/pgroll": "0.9.0",
41+
"@xata.io/pgstream": "0.2.0",
42+
"@xata.io/sql": "0.1.3",
4343
"@xata.io/tsconfig": "0.0.1",
4444
"@xata.io/utils": "0.1.0",
45-
"@xata.io/pgstream": "0.2.0",
46-
"@xata.io/sql": "0.1.3"
45+
"@xata.io/ai": "0.1.0",
46+
"@xata.io/api": "0.1.0"
4747
},
4848
"scripts": {
4949
"dev": "bun src/bin/cli.ts",

src/commands/branch/create.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { branchConfig } from '~/lib/branch-config';
77
import { CLI_NAME } from '~/lib/constants';
88

99
import type { Types } from '@xata.io/api';
10+
import { sortPostgresImagesDesc } from '@xata.io/utils';
1011
import invariant from 'tiny-invariant';
1112
import type { ProjectOptions } from '~/lib/cli-utils';
1213
import { groupAndSortRegions } from '~/lib/cli-utils';
@@ -231,7 +232,9 @@ export async function getImage(
231232
context.process.exit(1);
232233
}
233234

234-
const imageChoices = images.images.map((image) => ({
235+
const sortedImages = sortPostgresImagesDesc(images.images);
236+
237+
const imageChoices = sortedImages.map((image) => ({
235238
name: image.name,
236239
message: image.name
237240
}));
@@ -248,7 +251,10 @@ export async function getImage(
248251
return flags['postgres-version'];
249252
}
250253

251-
const image = (await context.enquirer.selectPrompt(context.isCI, title, imageChoices)) as string;
254+
const defaultIndex = sortedImages.findIndex((image) => image.name === 'postgres:18.3');
255+
const initial = defaultIndex >= 0 ? defaultIndex : 0;
256+
257+
const image = (await context.enquirer.selectPrompt(context.isCI, title, imageChoices, { initial })) as string;
252258
invariant(image, `Postgres version should exist`);
253259
return image;
254260
} catch {

src/lib/enquirer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function selectPrompt<T extends Choice>(
4545
isCI: boolean,
4646
message: string,
4747
choices: T[],
48-
{ flag }: { flag?: T['name'] } = {}
48+
{ flag, initial }: { flag?: T['name']; initial?: number } = {}
4949
) {
5050
if (flag) {
5151
return flag;
@@ -59,7 +59,8 @@ export async function selectPrompt<T extends Choice>(
5959
type: 'select',
6060
name: 'value',
6161
message,
62-
choices
62+
choices,
63+
initial
6364
});
6465

6566
return selectPrompt.value;

0 commit comments

Comments
 (0)