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

validateWithReport() — drizzle-orm Function Reference

Architecture documentation for the validateWithReport() function in utils.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  b18145b4_f05d_a9ae_4a8e_98368ec2cf0d["validateWithReport()"]
  5847e5ae_7b4a_4b02_b68f_883ef88b3c1a["utils.ts"]
  b18145b4_f05d_a9ae_4a8e_98368ec2cf0d -->|defined in| 5847e5ae_7b4a_4b02_b68f_883ef88b3c1a
  3082c777_0c92_ea57_9752_a40713e25ea2["checkHandler()"]
  3082c777_0c92_ea57_9752_a40713e25ea2 -->|calls| b18145b4_f05d_a9ae_4a8e_98368ec2cf0d
  b88883be_9aee_d2b0_1c78_5ac04683bbbf["upPgHandler()"]
  b88883be_9aee_d2b0_1c78_5ac04683bbbf -->|calls| b18145b4_f05d_a9ae_4a8e_98368ec2cf0d
  0b87f963_e54e_497f_7271_110d21942e56["prepareMigrationFolder()"]
  0b87f963_e54e_497f_7271_110d21942e56 -->|calls| b18145b4_f05d_a9ae_4a8e_98368ec2cf0d
  ac6c01b3_f59e_3d11_ee54_ca20e6dc14e7["validatorForDialect()"]
  b18145b4_f05d_a9ae_4a8e_98368ec2cf0d -->|calls| ac6c01b3_f59e_3d11_ee54_ca20e6dc14e7
  4faee74a_425e_9f08_40df_f43ccc717e6e["info()"]
  b18145b4_f05d_a9ae_4a8e_98368ec2cf0d -->|calls| 4faee74a_425e_9f08_40df_f43ccc717e6e
  style b18145b4_f05d_a9ae_4a8e_98368ec2cf0d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/utils.ts lines 132–191

export const validateWithReport = (snapshots: string[], dialect: Dialect) => {
	// ✅ check if drizzle-kit can handle snapshot version
	// ✅ check if snapshot is of the last version
	// ✅ check if id of the snapshot is valid
	// ✅ collect {} of prev id -> snapshotName[], if there's more than one - tell about collision
	const { validator, version } = validatorForDialect(dialect);

	const result = snapshots.reduce(
		(accum, it) => {
			const raw = JSON.parse(readFileSync(`./${it}`).toString());

			accum.rawMap[it] = raw;

			if (raw['version'] && Number(raw['version']) > version) {
				console.log(
					info(
						`${it} snapshot is of unsupported version, please update drizzle-kit`,
					),
				);
				process.exit(0);
			}

			const result = validator.safeParse(raw);
			if (!result.success) {
				accum.malformed.push(it);
				return accum;
			}

			const snapshot = result.data;
			if (snapshot.version !== String(version)) {
				accum.nonLatest.push(it);
				return accum;
			}

			// only if latest version here
			const idEntry = accum.idsMap[snapshot['prevId']] ?? {
				parent: it,
				snapshots: [],
			};
			idEntry.snapshots.push(it);
			accum.idsMap[snapshot['prevId']] = idEntry;

			return accum;
		},
		{
			malformed: [],
			nonLatest: [],
			idToNameMap: {},
			idsMap: {},
			rawMap: {},
		} as {
			malformed: string[];
			nonLatest: string[];
			idsMap: Record<string, { parent: string; snapshots: string[] }>;
			rawMap: Record<string, any>;
		},
	);

	return result;
};

Domain

Subdomains

Frequently Asked Questions

What does validateWithReport() do?
validateWithReport() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/utils.ts.
Where is validateWithReport() defined?
validateWithReport() is defined in drizzle-kit/src/utils.ts at line 132.
What does validateWithReport() call?
validateWithReport() calls 2 function(s): info, validatorForDialect.
What calls validateWithReport()?
validateWithReport() is called by 3 function(s): checkHandler, prepareMigrationFolder, upPgHandler.

Analyze Your Own Codebase

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

Try Supermodel Free