Skip to content

Conversation

@aaronchilcott
Copy link

@aaronchilcott aaronchilcott commented Oct 9, 2025

This change updates the zod dependency from v3 to v4.

Primarily this impacts drizzle-kit and drizzle-zod, however, there are also indirect impacts on some of the examples in drizzle-orm.

This is PR 1 of 2 aimed at resolving #4570. This branch is purely about upgrading zod to v4 while the other branch introduces new the new functionality which will resolve #4570 entirely. This approach of two PRs is intended to simplify the review process, I feel it will be clearer for the reviewer(s) to understand the upgrade and the improvements if they are kept separate.

Changelogs

Because I wasn't certain which release version these changes would go in to, here are the changelogs:

drizzle-orm

# Improvements

## Migrates zod to v4

The following impacts have been addressed to support the migration to zod v4 for the packages: drizzle-zod and drizzle-kit

### Changes

**drizzle-zod** (v0.8.0)
 - peerDependencies: `"zod": ">=4.0.0"`
 - devDependencies: `"zod": "^4.1.1"`
 - Files: drizzle-zod/package.json:68,79

**drizzle-kit** (v0.32.0)
 - devDependencies: `"zod": "^4.1.12"`
 - Files: drizzle-kit/package.json:116
 - Heavy internal usage in validation and serialization modules

**drizzle-orm** (v0.40.0)
 - devDependencies: `"zod": "^4.0.0"`
 - Files: drizzle-orm/package.json:204

**integration-tests**
 - dependencies: `"zod": "^4.1.1"`
 - Files: integration-tests/package.json:79

**examples/libsql**
 - dependencies: `"zod": "^4.1.1"`
 - Files: examples/libsql/package.json:22
 - Updated Dependencies: `@hono/zod-validator: ^0.4.1`, `znv: ^0.5.0`

### Out of date package-lock.json regeneration

These examples had zod 3.x references in their package-lock.json files from transitive dependencies. All lock files have been regenerated.

Note: These examples don't directly depend on zod. The old zod 3.x references were from transitive dependencies through drizzle-kit. After regenerating lock files, they now pull the latest drizzle-kit which uses Zod 4.x.

**examples/pg-proxy**
 - package-lock.json

**examples/mysql-proxy**
 - package-lock.json

**examples/better-sqlite3**
 - package-lock.json

**examples/aws-lambda**
 - package-lock.json

drizzle-zod

# Improvements

## Updates Zod version from v3 to v4

Upgrades the zod dependency from v3 to v4 while remaining backward compatible with previous versions.

drizzle-kit

# Improvements

## Updates Zod version from v3 to v4

Upgrades the zod dependency from v3 to v4 while remaining backward compatible with previous versions.

### Deprecated `.strict()` method has been omitted from modernisation steps 

`.strict()` is the only functionality to be skipped when modernising the code utilising zod. This is because the rewrite 
of drizzle-kit in #4439 may mean this work is discarded in later releases. `.strict()` requires quite a bit of work to
align it with the v4 API and doing so will also void backward compatibility.

# Zod v3 to v4 Migration analysis

- Pre-existing version: `zod@^3.20.2` (devDependency)
- Files using Zod: 19 files
- No problematic patterns detected (no `invalid_type_error`, `ZodError.errors`, `ctx.path`, etc.)
- Main patterns: `.optional()`, `.default()`, `.strict()`, `.merge()`, standard schemas

## Migration Steps

### 1: Upgrade to Zod v4 with v3 compatibility
- Install `zod@^4.0.0` in drizzle-kit (v4.1.12 installed)
- Run tests to ensure no immediate breakage (found type error due to @hono/zod-validator)

### Step 2: Update imports to use v3 subpath temporarily
- Update all Zod imports from `'zod'` to `'zod/v3'` (19 files updated)
- Run tests to verify everything still works

**Issue Found:** @hono/zod-validator v0.2.1 doesn't support Zod v4 yet (issue drizzle-team#1148 in honojs/middleware). The type definitions from 'zod/v3' are not compatible with @hono/zod-validator's expected types, even though they should be runtime-compatible.

**Solution Applied:**
- Added type assertion (`as any`) to schema in studio.ts:517 for @hono/zod-validator compatibility
- Added explicit type annotation for column parameter in studio.ts:648
- TypeScript compilation passes
#### Files migrated (19 total):
- src/snapshotsDiffer.ts
- src/serializer/studio.ts
- src/schemaValidator.ts
- src/cli/validations/sqlite.ts
- src/cli/commands/utils.ts
- src/serializer/sqliteSchema.ts
- src/serializer/singlestoreSchema.ts
- src/serializer/pgSchema.ts
- src/serializer/mysqlSchema.ts
- src/cli/validations/studio.ts (⚠️ intersection fix applied)
- src/cli/validations/singlestore.ts
- src/cli/validations/postgres.ts
- src/cli/validations/mysql.ts
- src/cli/validations/libsql.ts
- src/cli/validations/common.ts
- src/cli/validations/cli.ts
- src/cli/commands/singlestorePushUtils.ts
- src/cli/commands/mysqlPushUtils.ts
- src/cli/commands/migrate.ts

#### For each file:
1. Change import from `'zod/v3'` to `'zod'` (or `'zod/v4'`)
2. Ensure tests are passing
Skips modernization of `.strict()` since .strict() still works and there's no mention of performance impact, and we have 115 occurrences, I recommend we skip modernizing .strict() for now. Here's why:

  1. Still functional - .strict() works in v4
  2. Large scope - 115 occurrences would require significant refactoring
  3. Risk vs reward - No performance benefit mentioned
  4. Backward compatibility - Easier to maintain
  5. Rewrite of drizzle-kit in drizzle-team#4439 may mean this kind of modernization is thrown away in later releases
The following impacts have been addressed to support the migration to zod v4 for the packages: drizzle-zod and drizzle-kit

# Changes

**drizzle-zod** (v0.8.0)
  - peerDependencies: `"zod": ">=4.0.0"`
  - devDependencies: `"zod": "^4.1.1"`
  - Files: drizzle-zod/package.json:68,79

**drizzle-kit** (v0.32.0)
  - devDependencies: `"zod": "^4.1.12"`
  - Files: drizzle-kit/package.json:116
  - Heavy internal usage in validation and serialization modules

**drizzle-orm** (v0.40.0)
  - devDependencies: `"zod": "^4.0.0"`
  - Files: drizzle-orm/package.json:204

**integration-tests**
  - dependencies: `"zod": "^4.1.1"`
  - Files: integration-tests/package.json:79

**examples/libsql**
  - dependencies: `"zod": "^4.1.1"`
  - Files: examples/libsql/package.json:22
  - Updated Dependencies: `@hono/zod-validator: ^0.4.1`, `znv: ^0.5.0`

# Out of date package-lock.json regeneration

These examples had zod 3.x references in their package-lock.json files from transitive dependencies. All lock files have been regenerated.

Note: These examples don't directly depend on zod. The old zod 3.x references were from transitive dependencies through drizzle-kit. After regenerating lock files, they now pull the latest drizzle-kit which uses Zod 4.x.

**examples/pg-proxy**
  - package-lock.json

**examples/mysql-proxy**
    - package-lock.json

**examples/better-sqlite3**
  - package-lock.json

**examples/aws-lambda**
  - package-lock.json

# Indirect references

The following examples don't have explicit zod dependencies but use drizzle-kit:

- **examples/cloudflare-d1** - uses drizzle-kit ^0.17.0
- **examples/postgresjs** - uses drizzle-kit 0.17.1-609a4f0
- **examples/neon-cloudflare** - needs verification
- **examples/sqlite-proxy** - needs verification

# Known Breaking Changes (Zod 3.x → 4.x)

Reference: https://github.com/colinhacks/zod/releases/tag/v4.0.0

Key changes to watch for:
- Error formatting changes
- `.parse()` behavior refinements
- Type inference improvements
Updates change log files for what is included in this family of commits (for drizzle-team#4570)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: drizzle-zod incorrect mapping of date columns to zod string

1 participant