@@ -129,6 +129,9 @@ program
129129 . option ( "--monitoring-user <name>" , "Monitoring role name to create/update" , "postgres_ai_mon" )
130130 . option ( "--password <password>" , "Monitoring role password (overrides PGAI_MON_PASSWORD)" )
131131 . option ( "--skip-optional-permissions" , "Skip optional permissions (RDS/self-managed extras)" , false )
132+ . option ( "--print-sql" , "Print SQL steps before applying (passwords redacted by default)" , false )
133+ . option ( "--show-secrets" , "When printing SQL, do not redact secrets (DANGEROUS)" , false )
134+ . option ( "--dry-run" , "Print SQL steps and exit without applying changes" , false )
132135 . action ( async ( conn : string | undefined , opts : {
133136 dbUrl ?: string ;
134137 host ?: string ;
@@ -139,6 +142,9 @@ program
139142 monitoringUser : string ;
140143 password ?: string ;
141144 skipOptionalPermissions ?: boolean ;
145+ printSql ?: boolean ;
146+ showSecrets ?: boolean ;
147+ dryRun ?: boolean ;
142148 } ) => {
143149 let adminConn ;
144150 try {
@@ -165,6 +171,8 @@ program
165171 console . log ( `Monitoring user: ${ opts . monitoringUser } ` ) ;
166172 console . log ( `Optional permissions: ${ includeOptionalPermissions ? "enabled" : "skipped" } ` ) ;
167173
174+ const shouldPrintSql = ! ! opts . printSql || ! ! opts . dryRun ;
175+
168176 // Use native pg client instead of requiring psql to be installed
169177 const { Client } = require ( "pg" ) ;
170178 const client = new Client ( adminConn . clientConfig ) ;
@@ -210,6 +218,30 @@ program
210218 roleExists,
211219 } ) ;
212220
221+ if ( shouldPrintSql ) {
222+ const redact = ! opts . showSecrets ;
223+ const redactPasswords = ( sql : string ) : string => {
224+ if ( ! redact ) return sql ;
225+ // Replace PASSWORD '<literal>' (handles doubled quotes inside).
226+ return sql . replace ( / p a s s w o r d \s + ' (?: ' ' | [ ^ ' ] ) * ' / gi, "password '<redacted>'" ) ;
227+ } ;
228+
229+ console . log ( "\n--- SQL plan ---" ) ;
230+ for ( const step of plan . steps ) {
231+ console . log ( `\n-- ${ step . name } ${ step . optional ? " (optional)" : "" } ` ) ;
232+ console . log ( redactPasswords ( step . sql ) ) ;
233+ }
234+ console . log ( "\n--- end SQL plan ---\n" ) ;
235+ if ( redact ) {
236+ console . log ( "Note: passwords are redacted in the printed SQL (use --show-secrets to print them)." ) ;
237+ }
238+ }
239+
240+ if ( opts . dryRun ) {
241+ console . log ( "✓ dry-run completed (no changes were applied)" ) ;
242+ return ;
243+ }
244+
213245 const { applied, skippedOptional } = await applyInitPlan ( { client, plan } ) ;
214246
215247 console . log ( "✓ init completed" ) ;
0 commit comments