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

filterStatements() — drizzle-orm Function Reference

Architecture documentation for the filterStatements() function in singlestorePushUtils.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  f6331c0e_89e7_c4cf_62e7_f03634724277["filterStatements()"]
  65107a57_7714_63e5_7018_8c2efc0f3b41["singlestorePushUtils.ts"]
  f6331c0e_89e7_c4cf_62e7_f03634724277 -->|defined in| 65107a57_7714_63e5_7018_8c2efc0f3b41
  style f6331c0e_89e7_c4cf_62e7_f03634724277 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/cli/commands/singlestorePushUtils.ts lines 12–107

export const filterStatements = (
	statements: JsonStatement[],
	currentSchema: TypeOf<typeof singlestoreSchema>,
	prevSchema: TypeOf<typeof singlestoreSchema>,
) => {
	return statements.filter((statement) => {
		if (statement.type === 'alter_table_alter_column_set_type') {
			// Don't need to handle it on migrations step and introspection
			// but for both it should be skipped
			if (
				statement.oldDataType.startsWith('tinyint')
				&& statement.newDataType.startsWith('boolean')
			) {
				return false;
			}

			if (
				statement.oldDataType.startsWith('bigint unsigned')
				&& statement.newDataType.startsWith('serial')
			) {
				return false;
			}

			if (
				statement.oldDataType.startsWith('serial')
				&& statement.newDataType.startsWith('bigint unsigned')
			) {
				return false;
			}
		} else if (statement.type === 'alter_table_alter_column_set_default') {
			if (
				statement.newDefaultValue === false
				&& statement.oldDefaultValue === 0
				&& statement.newDataType === 'boolean'
			) {
				return false;
			}
			if (
				statement.newDefaultValue === true
				&& statement.oldDefaultValue === 1
				&& statement.newDataType === 'boolean'
			) {
				return false;
			}
		} else if (statement.type === 'delete_unique_constraint') {
			const unsquashed = SingleStoreSquasher.unsquashUnique(statement.data);
			// only if constraint was removed from a serial column, than treat it as removed
			// const serialStatement = statements.find(
			//   (it) => it.type === "alter_table_alter_column_set_type"
			// ) as JsonAlterColumnTypeStatement;
			// if (
			//   serialStatement?.oldDataType.startsWith("bigint unsigned") &&
			//   serialStatement?.newDataType.startsWith("serial") &&
			//   serialStatement.columnName ===
			//     SingleStoreSquasher.unsquashUnique(statement.data).columns[0]
			// ) {
			//   return false;
			// }
			// Check if uniqueindex was only on this column, that is serial

			// if now serial and was not serial and was unique index
			if (
				unsquashed.columns.length === 1
				&& currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]]
						.type === 'serial'
				&& prevSchema.tables[statement.tableName].columns[unsquashed.columns[0]]
						.type === 'serial'
				&& currentSchema.tables[statement.tableName].columns[unsquashed.columns[0]]
						.name === unsquashed.columns[0]
			) {
				return false;
			}
		} else if (statement.type === 'alter_table_alter_column_drop_notnull') {
			// only if constraint was removed from a serial column, than treat it as removed
			const serialStatement = statements.find(
				(it) => it.type === 'alter_table_alter_column_set_type',
			) as JsonAlterColumnTypeStatement;
			if (
				serialStatement?.oldDataType.startsWith('bigint unsigned')
				&& serialStatement?.newDataType.startsWith('serial')
				&& serialStatement.columnName === statement.columnName

Domain

Subdomains

Frequently Asked Questions

What does filterStatements() do?
filterStatements() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/commands/singlestorePushUtils.ts.
Where is filterStatements() defined?
filterStatements() is defined in drizzle-kit/src/cli/commands/singlestorePushUtils.ts at line 12.

Analyze Your Own Codebase

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

Try Supermodel Free