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

libSqlLogSuggestionsAndReturn() — drizzle-orm Function Reference

Architecture documentation for the libSqlLogSuggestionsAndReturn() function in libSqlPushUtils.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7["libSqlLogSuggestionsAndReturn()"]
  0232777b_2a7f_2d05_d5d8_ae34939c6599["libSqlPushUtils.ts"]
  3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7 -->|defined in| 0232777b_2a7f_2d05_d5d8_ae34939c6599
  282ad536_6bf2_f2d6_69aa_6c9e64464e83["libSQLPush()"]
  282ad536_6bf2_f2d6_69aa_6c9e64464e83 -->|calls| 3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7
  f532f7a9_3781_5a3c_9695_e62bd56cabd7["fromJson()"]
  3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7 -->|calls| f532f7a9_3781_5a3c_9695_e62bd56cabd7
  79111b8f_e391_9378_7198_f936c93c19be["getOldTableName()"]
  3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7 -->|calls| 79111b8f_e391_9378_7198_f936c93c19be
  615e941b_9f5e_d8e2_86b7_7a83b56b1da5["_moveDataStatements()"]
  3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7 -->|calls| 615e941b_9f5e_d8e2_86b7_7a83b56b1da5
  style 3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/cli/commands/libSqlPushUtils.ts lines 113–355

export const libSqlLogSuggestionsAndReturn = 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 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], 'turso', 'push', json2);
			statementsToExecute.push(
				...(Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]),
			);
		} else if (statement.type === 'alter_table_drop_column') {
			const tableName = statement.tableName;

			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 delete ${
						chalk.underline(
							statement.columnName,
						)
					} column in ${tableName} table with ${count} items`,
				);
				columnsToRemove.push(`${tableName}_${statement.columnName}`);
				shouldAskForApprove = true;
			}

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

				tablesToTruncate.push(newTableName);
				statementsToExecute.push(`delete from ${newTableName};`);

Domain

Subdomains

Called By

Frequently Asked Questions

What does libSqlLogSuggestionsAndReturn() do?
libSqlLogSuggestionsAndReturn() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/commands/libSqlPushUtils.ts.
Where is libSqlLogSuggestionsAndReturn() defined?
libSqlLogSuggestionsAndReturn() is defined in drizzle-kit/src/cli/commands/libSqlPushUtils.ts at line 113.
What does libSqlLogSuggestionsAndReturn() call?
libSqlLogSuggestionsAndReturn() calls 3 function(s): _moveDataStatements, fromJson, getOldTableName.
What calls libSqlLogSuggestionsAndReturn()?
libSqlLogSuggestionsAndReturn() is called by 1 function(s): libSQLPush.

Analyze Your Own Codebase

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

Try Supermodel Free