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

logSuggestionsAndReturn() — drizzle-orm Function Reference

Architecture documentation for the logSuggestionsAndReturn() function in sqlitePushUtils.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  5e0b1139_8050_e207_b519_7736291ee6af["logSuggestionsAndReturn()"]
  934183d7_9412_6b03_702c_de0c2903ced3["sqlitePushUtils.ts"]
  5e0b1139_8050_e207_b519_7736291ee6af -->|defined in| 934183d7_9412_6b03_702c_de0c2903ced3
  c7dae276_9495_03b3_6785_ff0423e3125c["pushSQLiteSchema()"]
  c7dae276_9495_03b3_6785_ff0423e3125c -->|calls| 5e0b1139_8050_e207_b519_7736291ee6af
  e6e192c7_531c_3883_7d01_93a5da8e7116["pushMySQLSchema()"]
  e6e192c7_531c_3883_7d01_93a5da8e7116 -->|calls| 5e0b1139_8050_e207_b519_7736291ee6af
  09737f8b_925a_9628_47ce_149d9e6cce58["pushSingleStoreSchema()"]
  09737f8b_925a_9628_47ce_149d9e6cce58 -->|calls| 5e0b1139_8050_e207_b519_7736291ee6af
  f532f7a9_3781_5a3c_9695_e62bd56cabd7["fromJson()"]
  5e0b1139_8050_e207_b519_7736291ee6af -->|calls| f532f7a9_3781_5a3c_9695_e62bd56cabd7
  9667b232_d045_e591_9741_9cd299482e60["getOldTableName()"]
  5e0b1139_8050_e207_b519_7736291ee6af -->|calls| 9667b232_d045_e591_9741_9cd299482e60
  2b006da9_92ff_ab47_ba6c_8ec3d041f7e3["findAddedAndRemoved()"]
  5e0b1139_8050_e207_b519_7736291ee6af -->|calls| 2b006da9_92ff_ab47_ba6c_8ec3d041f7e3
  dd67d960_17b4_aac7_41cc_e07e2f072289["_moveDataStatements()"]
  5e0b1139_8050_e207_b519_7736291ee6af -->|calls| dd67d960_17b4_aac7_41cc_e07e2f072289
  style 5e0b1139_8050_e207_b519_7736291ee6af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/cli/commands/sqlitePushUtils.ts lines 127–322

export const logSuggestionsAndReturn = async (
	connection: SQLiteDB,
	statements: JsonStatement[],
	json1: SQLiteSchemaSquashed,
	json2: SQLiteSchemaSquashed,
	meta: SQLiteSchemaInternal['_meta'],
) => {
	let shouldAskForApprove = false;
	const statementsToExecute: string[] = [];
	const infoToPrint: string[] = [];

	const tablesToRemove: string[] = [];
	const columnsToRemove: string[] = [];
	const schemasToRemove: string[] = [];
	const tablesToTruncate: string[] = [];

	for (const statement of statements) {
		if (statement.type === 'drop_table') {
			const res = await connection.query<{ count: string }>(
				`select count(*) as count from \`${statement.tableName}\``,
			);
			const count = Number(res[0].count);
			if (count > 0) {
				infoToPrint.push(
					`· You're about to delete ${
						chalk.underline(
							statement.tableName,
						)
					} table with ${count} items`,
				);
				tablesToRemove.push(statement.tableName);
				shouldAskForApprove = true;
			}

			const fromJsonStatement = fromJson([statement], 'sqlite', 'push');
			statementsToExecute.push(
				...(Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]),
			);
		} else if (statement.type === 'alter_table_drop_column') {
			const tableName = statement.tableName;
			const columnName = statement.columnName;

			const res = await connection.query<{ count: string }>(
				`select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``,
			);
			const count = Number(res[0].count);
			if (count > 0) {
				infoToPrint.push(
					`· You're about to delete ${
						chalk.underline(
							columnName,
						)
					} column in ${tableName} table with ${count} items`,
				);
				columnsToRemove.push(`${tableName}_${statement.columnName}`);
				shouldAskForApprove = true;
			}

			const fromJsonStatement = fromJson([statement], 'sqlite', 'push');
			statementsToExecute.push(
				...(Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]),
			);
		} else if (
			statement.type === 'sqlite_alter_table_add_column'
			&& (statement.column.notNull && !statement.column.default)
		) {
			const tableName = statement.tableName;
			const columnName = statement.column.name;
			const res = await connection.query<{ count: string }>(
				`select count(*) as count from \`${tableName}\``,
			);
			const count = Number(res[0].count);
			if (count > 0) {
				infoToPrint.push(
					`· You're about to add not-null ${
						chalk.underline(
							columnName,
						)
					} column without default value, which contains ${count} items`,
				);

Domain

Subdomains

Frequently Asked Questions

What does logSuggestionsAndReturn() do?
logSuggestionsAndReturn() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/commands/sqlitePushUtils.ts.
Where is logSuggestionsAndReturn() defined?
logSuggestionsAndReturn() is defined in drizzle-kit/src/cli/commands/sqlitePushUtils.ts at line 127.
What does logSuggestionsAndReturn() call?
logSuggestionsAndReturn() calls 4 function(s): _moveDataStatements, findAddedAndRemoved, fromJson, getOldTableName.
What calls logSuggestionsAndReturn()?
logSuggestionsAndReturn() is called by 3 function(s): pushMySQLSchema, pushSQLiteSchema, pushSingleStoreSchema.

Analyze Your Own Codebase

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

Try Supermodel Free