MCPcopy
hub / github.com/drizzle-team/drizzle-orm / pgPush

Function pgPush

drizzle-kit/src/cli/commands/push.ts:289–411  ·  view source on GitHub ↗
(
	schemaPath: string | string[],
	verbose: boolean,
	strict: boolean,
	credentials: PostgresCredentials,
	tablesFilter: string[],
	schemasFilter: string[],
	entities: Entities,
	force: boolean,
	casing: CasingType | undefined,
)

Source from the content-addressed store, hash-verified

287};
288
289export 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 );

Callers 1

schema.tsFile · 0.85

Calls 6

serializePgFunction · 0.90
pgSuggestionsFunction · 0.90
preparePostgresDBFunction · 0.85
pgPushIntrospectFunction · 0.85
preparePgPushFunction · 0.85
queryMethod · 0.45

Tested by

no test coverage detected