( schemaPath: string | string[], verbose: boolean, strict: boolean, credentials: PostgresCredentials, tablesFilter: string[], schemasFilter: string[], entities: Entities, force: boolean, casing: CasingType | undefined, )
| 287 | }; |
| 288 | |
| 289 | export const pgPush = async ( |
| 290 | schemaPath: string | string[], |
| 291 | verbose: boolean, |
| 292 | strict: boolean, |
| 293 | credentials: PostgresCredentials, |
| 294 | tablesFilter: string[], |
| 295 | schemasFilter: string[], |
| 296 | entities: Entities, |
| 297 | force: boolean, |
| 298 | casing: CasingType | undefined, |
| 299 | ) => { |
| 300 | const { preparePostgresDB } = await import('../connections'); |
| 301 | const { pgPushIntrospect } = await import('./pgIntrospect'); |
| 302 | |
| 303 | const db = await preparePostgresDB(credentials); |
| 304 | const serialized = await serializePg(schemaPath, casing, schemasFilter); |
| 305 | |
| 306 | const { schema } = await pgPushIntrospect(db, tablesFilter, schemasFilter, entities, serialized); |
| 307 | |
| 308 | const { preparePgPush } = await import('./migrate'); |
| 309 | |
| 310 | const statements = await preparePgPush( |
| 311 | { id: randomUUID(), prevId: schema.id, ...serialized }, |
| 312 | schema, |
| 313 | ); |
| 314 | |
| 315 | try { |
| 316 | if (statements.sqlStatements.length === 0) { |
| 317 | render(`[${chalk.blue('i')}] No changes detected`); |
| 318 | } else { |
| 319 | // const filteredStatements = filterStatements(statements.statements); |
| 320 | const { |
| 321 | shouldAskForApprove, |
| 322 | statementsToExecute, |
| 323 | columnsToRemove, |
| 324 | tablesToRemove, |
| 325 | matViewsToRemove, |
| 326 | tablesToTruncate, |
| 327 | infoToPrint, |
| 328 | schemasToRemove, |
| 329 | } = await pgSuggestions(db, statements.statements); |
| 330 | |
| 331 | if (verbose) { |
| 332 | console.log(); |
| 333 | // console.log(chalk.gray('Verbose logs:')); |
| 334 | console.log( |
| 335 | withStyle.warning('You are about to execute current statements:'), |
| 336 | ); |
| 337 | console.log(); |
| 338 | console.log(statementsToExecute.map((s) => chalk.blue(s)).join('\n')); |
| 339 | console.log(); |
| 340 | } |
| 341 | |
| 342 | if (!force && strict) { |
| 343 | if (!shouldAskForApprove) { |
| 344 | const { status, data } = await render( |
| 345 | new Select(['No, abort', `Yes, I want to execute all statements`]), |
| 346 | ); |
no test coverage detected