Home / Function/ pgPush() — drizzle-orm Function Reference

pgPush() — drizzle-orm Function Reference

Architecture documentation for the pgPush() function in push.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  5f1dc8e1_c9ac_354c_77c5_286782036654["pgPush()"]
  6219550e_1686_ca7a_0d96_0838fb90e7cb["push.ts"]
  5f1dc8e1_c9ac_354c_77c5_286782036654 -->|defined in| 6219550e_1686_ca7a_0d96_0838fb90e7cb
  a6191ddf_c119_718d_8adb_1cf1f8e385b3["render()"]
  5f1dc8e1_c9ac_354c_77c5_286782036654 -->|calls| a6191ddf_c119_718d_8adb_1cf1f8e385b3
  99a768a1_158f_61ad_5701_374c946e2765["pgSuggestions()"]
  5f1dc8e1_c9ac_354c_77c5_286782036654 -->|calls| 99a768a1_158f_61ad_5701_374c946e2765
  5c1d25fb_ce50_e380_1070_f223ed9b8f49["filterStatements()"]
  5f1dc8e1_c9ac_354c_77c5_286782036654 -->|calls| 5c1d25fb_ce50_e380_1070_f223ed9b8f49
  style 5f1dc8e1_c9ac_354c_77c5_286782036654 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/cli/commands/push.ts lines 289–411

export const pgPush = async (
	schemaPath: string | string[],
	verbose: boolean,
	strict: boolean,
	credentials: PostgresCredentials,
	tablesFilter: string[],
	schemasFilter: string[],
	entities: Entities,
	force: boolean,
	casing: CasingType | undefined,
) => {
	const { preparePostgresDB } = await import('../connections');
	const { pgPushIntrospect } = await import('./pgIntrospect');

	const db = await preparePostgresDB(credentials);
	const serialized = await serializePg(schemaPath, casing, schemasFilter);

	const { schema } = await pgPushIntrospect(db, tablesFilter, schemasFilter, entities, serialized);

	const { preparePgPush } = await import('./migrate');

	const statements = await preparePgPush(
		{ id: randomUUID(), prevId: schema.id, ...serialized },
		schema,
	);

	try {
		if (statements.sqlStatements.length === 0) {
			render(`[${chalk.blue('i')}] No changes detected`);
		} else {
			// const filteredStatements = filterStatements(statements.statements);
			const {
				shouldAskForApprove,
				statementsToExecute,
				columnsToRemove,
				tablesToRemove,
				matViewsToRemove,
				tablesToTruncate,
				infoToPrint,
				schemasToRemove,
			} = await pgSuggestions(db, statements.statements);

			if (verbose) {
				console.log();
				// console.log(chalk.gray('Verbose logs:'));
				console.log(
					withStyle.warning('You are about to execute current statements:'),
				);
				console.log();
				console.log(statementsToExecute.map((s) => chalk.blue(s)).join('\n'));
				console.log();
			}

			if (!force && strict) {
				if (!shouldAskForApprove) {
					const { status, data } = await render(
						new Select(['No, abort', `Yes, I want to execute all statements`]),
					);
					if (data?.index === 0) {
						render(`[${chalk.red('x')}] All changes were aborted`);
						process.exit(0);
					}
				}
			}

			if (!force && shouldAskForApprove) {
				console.log(withStyle.warning('Found data-loss statements:'));
				console.log(infoToPrint.join('\n'));
				console.log();
				console.log(
					chalk.red.bold(
						'THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n',
					),
				);

				console.log(chalk.white('Do you still want to push changes?'));

				const { status, data } = await render(
					new Select([
						'No, abort',
						`Yes, I want to${

Domain

Subdomains

Frequently Asked Questions

What does pgPush() do?
pgPush() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/commands/push.ts.
Where is pgPush() defined?
pgPush() is defined in drizzle-kit/src/cli/commands/push.ts at line 289.
What does pgPush() call?
pgPush() calls 3 function(s): filterStatements, pgSuggestions, render.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free