Skip to content

Commit b0f1278

Browse files
authored
Merge pull request #9 from replit/jt/devprod/add_select_resolver_pg_suggestions
devprod/add select resolver pg suggestions
2 parents c471f37 + 66d329f commit b0f1278

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

drizzle-kit/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ Make any changes you require to the `drizzle-kit/api` file ([see here](./drizzle
1313
```bash
1414
pnpm build
1515
```
16-
This will build a `dist` file that you can import into `repl-it-web` using the `file:` protocol in `package.json` like so:
16+
This will build a `dist` file that you can import into `repl-it-web` using the `file:` by running:
17+
```bash
18+
cd pkg/pid2/
19+
20+
pnpm add @drizzle-team/drizzle-kit@file:../../../drizzle-orm/drizzle-kit/dist
21+
```
22+
Which should add the following to `pkg/pid2/package.json`:
1723
```
1824
"@drizzle-team/drizzle-kit": "file:../drizzle-orm/drizzle-kit/dist",
1925
```

drizzle-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@drizzle-team/drizzle-kit",
3-
"version": "0.31.8",
3+
"version": "0.31.10",
44
"homepage": "https://orm.drizzle.team",
55
"keywords": [
66
"drizzle",

drizzle-kit/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export const getPgClientPool = async (
166166
return pool;
167167
};
168168

169+
export type { SelectResolverInput, SelectResolverOutput } from './cli/commands/pgPushUtils';
169170
export { applyPgSnapshotsDiff } from './snapshotsDiffer';
170171
export type {
171172
ColumnsResolverInput,

drizzle-kit/src/cli/commands/migrate.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,7 @@ export const policyResolver = async (
248248
export const indPolicyResolver = async (
249249
input: PolicyResolverInput<Policy>,
250250
): Promise<PolicyResolverOutput<Policy>> => {
251-
const result = await promptNamedConflict(
252-
input.created,
253-
input.deleted,
254-
'policy',
255-
);
251+
const result = await promptNamedConflict(input.created, input.deleted, 'policy');
256252
return {
257253
created: result.created,
258254
deleted: result.deleted,

drizzle-kit/src/cli/commands/pgPushUtils.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,30 @@ function tableNameWithSchemaFrom(
5656
return concatSchemaAndTableName(newSchemaName, newTableName);
5757
}
5858

59-
export const pgSuggestions = async (db: DB, statements: JsonStatement[]) => {
59+
export type SelectResolverInput = {
60+
entity: {
61+
type: 'createUniqueConstraint';
62+
name: string;
63+
count: number;
64+
tableName: string;
65+
};
66+
items: string[];
67+
};
68+
69+
export type SelectResolverOutput = {
70+
data: {
71+
index: number;
72+
value: string;
73+
};
74+
};
75+
76+
export const pgSuggestions = async (
77+
db: DB,
78+
statements: JsonStatement[],
79+
selectResolver?: (
80+
input: SelectResolverInput,
81+
) => Promise<SelectResolverOutput>,
82+
) => {
6083
let shouldAskForApprove = false;
6184
const statementsToExecute: string[] = [];
6285
const infoToPrint: string[] = [];
@@ -236,8 +259,20 @@ export const pgSuggestions = async (db: DB, statements: JsonStatement[]) => {
236259
)
237260
} table?\n`,
238261
);
239-
const { status, data } = await render(
240-
new Select(['No, add the constraint without truncating the table', `Yes, truncate the table`]),
262+
263+
const entity = {
264+
type: 'createUniqueConstraint' as const,
265+
name: unsquashedUnique.name,
266+
count,
267+
tableName: statement.tableName,
268+
};
269+
const items = ['no', 'yes'];
270+
271+
const { data } = selectResolver ? await selectResolver({ entity, items }) : await render(
272+
new Select([
273+
'No, add the constraint without truncating the table',
274+
`Yes, truncate the table`,
275+
]),
241276
);
242277
if (data?.index === 1) {
243278
tablesToTruncate.push(statement.tableName);

0 commit comments

Comments
 (0)