@@ -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