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

pushMySQLSchema() — drizzle-orm Function Reference

Architecture documentation for the pushMySQLSchema() function in api.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  e6e192c7_531c_3883_7d01_93a5da8e7116["pushMySQLSchema()"]
  e668bfef_9125_1ef0_2f94_a0f9605584bd["api.ts"]
  e6e192c7_531c_3883_7d01_93a5da8e7116 -->|defined in| e668bfef_9125_1ef0_2f94_a0f9605584bd
  0b2b83dd_9eb0_046b_3c8a_c644b899f7d0["generateMySQLDrizzleJson()"]
  e6e192c7_531c_3883_7d01_93a5da8e7116 -->|calls| 0b2b83dd_9eb0_046b_3c8a_c644b899f7d0
  f3976464_9993_b7cc_1cb7_d8087b203650["squashMysqlScheme()"]
  e6e192c7_531c_3883_7d01_93a5da8e7116 -->|calls| f3976464_9993_b7cc_1cb7_d8087b203650
  5e0b1139_8050_e207_b519_7736291ee6af["logSuggestionsAndReturn()"]
  e6e192c7_531c_3883_7d01_93a5da8e7116 -->|calls| 5e0b1139_8050_e207_b519_7736291ee6af
  style e6e192c7_531c_3883_7d01_93a5da8e7116 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/api.ts lines 409–465

export const pushMySQLSchema = async (
	imports: Record<string, unknown>,
	drizzleInstance: MySql2Database<any>,
	databaseName: string,
) => {
	const { applyMysqlSnapshotsDiff } = await import('./snapshotsDiffer');
	const { logSuggestionsAndReturn } = await import(
		'./cli/commands/mysqlPushUtils'
	);
	const { mysqlPushIntrospect } = await import(
		'./cli/commands/mysqlIntrospect'
	);
	const { sql } = await import('drizzle-orm');

	const db: DB = {
		query: async (query: string, params?: any[]) => {
			const res = await drizzleInstance.execute(sql.raw(query));
			return res[0] as unknown as any[];
		},
	};
	const cur = await generateMySQLDrizzleJson(imports);
	const { schema: prev } = await mysqlPushIntrospect(db, databaseName, []);

	const validatedPrev = mysqlSchema.parse(prev);
	const validatedCur = mysqlSchema.parse(cur);

	const squashedPrev = squashMysqlScheme(validatedPrev);
	const squashedCur = squashMysqlScheme(validatedCur);

	const { statements } = await applyMysqlSnapshotsDiff(
		squashedPrev,
		squashedCur,
		tablesResolver,
		columnsResolver,
		mySqlViewsResolver,
		validatedPrev,
		validatedCur,
		'push',
	);

	const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn(
		db,
		statements,
		validatedCur,
	);

	return {
		hasDataLoss: shouldAskForApprove,
		warnings: infoToPrint,
		statementsToExecute,
		apply: async () => {
			for (const dStmnt of statementsToExecute) {
				await db.query(dStmnt);
			}
		},
	};
};

Domain

Subdomains

Frequently Asked Questions

What does pushMySQLSchema() do?
pushMySQLSchema() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/api.ts.
Where is pushMySQLSchema() defined?
pushMySQLSchema() is defined in drizzle-kit/src/api.ts at line 409.
What does pushMySQLSchema() call?
pushMySQLSchema() calls 3 function(s): generateMySQLDrizzleJson, logSuggestionsAndReturn, squashMysqlScheme.

Analyze Your Own Codebase

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

Try Supermodel Free