Skip to content

Support new drizzle#898

Merged
kibertoad merged 3 commits intomainfrom
feat/new-drizzle-support
Mar 28, 2026
Merged

Support new drizzle#898
kibertoad merged 3 commits intomainfrom
feat/new-drizzle-support

Conversation

@kibertoad
Copy link
Copy Markdown
Collaborator

Changes

Support drizzle snapshot format

Checklist

  • Apply one of following labels; major, minor, patch or skip-release
  • I've updated the documentation, or no changes were necessary
  • I've updated the tests, or no changes were necessary

AI Assistance Tracking

We're running a metric to understand where AI assists our engineering work. Please select exactly one of the options below:

Mark "Yes" if AI helped in any part of this work, for example: generating code, refactoring, debugging support,
explaining something, reviewing an idea, or suggesting an approach.

  • Yes, AI assisted with this PR
  • No, AI did not assist with this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: lokalise/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fbc6757e-78bb-4282-88fb-36e4568eb9ea

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request extends migration support in the drizzle-utils module to handle both legacy (Drizzle-kit 0.x) and new (Drizzle-kit 1.0.0-beta) migration formats. The legacy format uses a flat SQL file structure with a meta/_journal.json index, while the new format uses a folder-per-migration layout with individual migration.sql and snapshot.json files per migration. The implementation adds format detection, updates migration entry reading to support both layouts, and enhances dialect auto-detection to work with snapshot files. Documentation, test fixtures, and test coverage are updated across multiple database dialects (PostgreSQL, MySQL, CockroachDB) to reflect dual-format support.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

ai-assisted

Suggested reviewers

  • dariacm
  • CarlosGamero
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Support new drizzle' is overly vague and generic, failing to clearly convey the specific change. Revise the title to be more specific, such as 'Support drizzle snapshot format' or 'Add support for drizzle-kit 1.0.0 folder-per-migration format'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description provides the required checklist items and AI assistance tracking, but lacks meaningful detail about the changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/new-drizzle-support

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/app/drizzle-utils/test/generateMigrations.ts (1)

99-106: Consider logging cleanup failures for debugging.

Silent catch blocks can hide issues during local development. While acceptable for test utilities, logging (e.g., console.warn) could help diagnose flaky tests.

Optional: Log cleanup failures
   } finally {
     try {
       unlinkSync(schemaPath)
-    } catch {}
+    } catch (e) {
+      // Non-critical: file may not exist if generation failed early
+    }
     try {
       unlinkSync(configPath)
-    } catch {}
+    } catch (e) {
+      // Non-critical: file may not exist if generation failed early
+    }
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/app/drizzle-utils/test/generateMigrations.ts` around lines 99 - 106,
In the finally block that cleans up files (the unlinkSync calls for schemaPath
and configPath), replace the silent empty catch blocks with catches that log a
warning including the error and which path failed (e.g., using console.warn with
the error and the path variable); update the two catch blocks around
unlinkSync(schemaPath) and unlinkSync(configPath) so they report failures
instead of swallowing them to aid debugging of flaky tests.
packages/app/drizzle-utils/src/markMigrationsApplied.ts (1)

292-295: Interpolation is safe here, but consider documenting the invariants.

The comment correctly notes that hash (hex string) and createdAt (number) are safe to interpolate. For defense-in-depth, you could add a validation check that hash matches /^[0-9a-f]{64}$/ before interpolation, though the current implementation is correct since computeMigrationHash always produces valid hex output.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/app/drizzle-utils/src/markMigrationsApplied.ts` around lines 292 -
295, Add a defensive validation before interpolating migration values: in the
markMigrationsApplied logic where executor.run is called with tableName and
entry.hash/entry.createdAt, verify entry.hash matches the expected hex invariant
(e.g. /^[0-9a-f]{64}$/) and that entry.createdAt is a finite number; if
validation fails, throw or log an error instead of interpolating. This keeps the
current behavior (computeMigrationHash produces valid hex) but documents and
enforces the invariant around the executor.run insertion using tableName,
entry.hash, entry.createdAt and computeMigrationHash.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/app/drizzle-utils/src/markMigrationsApplied.ts`:
- Around line 292-295: Add a defensive validation before interpolating migration
values: in the markMigrationsApplied logic where executor.run is called with
tableName and entry.hash/entry.createdAt, verify entry.hash matches the expected
hex invariant (e.g. /^[0-9a-f]{64}$/) and that entry.createdAt is a finite
number; if validation fails, throw or log an error instead of interpolating.
This keeps the current behavior (computeMigrationHash produces valid hex) but
documents and enforces the invariant around the executor.run insertion using
tableName, entry.hash, entry.createdAt and computeMigrationHash.

In `@packages/app/drizzle-utils/test/generateMigrations.ts`:
- Around line 99-106: In the finally block that cleans up files (the unlinkSync
calls for schemaPath and configPath), replace the silent empty catch blocks with
catches that log a warning including the error and which path failed (e.g.,
using console.warn with the error and the path variable); update the two catch
blocks around unlinkSync(schemaPath) and unlinkSync(configPath) so they report
failures instead of swallowing them to aid debugging of flaky tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: lokalise/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b21de418-94d0-404d-b0ed-bedd1255fd8d

📥 Commits

Reviewing files that changed from the base of the PR and between d5dc879 and c3b367a.

📒 Files selected for processing (19)
  • packages/app/drizzle-utils/README.md
  • packages/app/drizzle-utils/docs/migrating-from-prisma.md
  • packages/app/drizzle-utils/package.json
  • packages/app/drizzle-utils/src/index.ts
  • packages/app/drizzle-utils/src/markMigrationsApplied.test.ts
  • packages/app/drizzle-utils/src/markMigrationsApplied.ts
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-cockroachdb/20260328163300_init/migration.sql
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-cockroachdb/20260328163300_init/snapshot.json
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-cockroachdb/20260328163325_add_users/migration.sql
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-cockroachdb/20260328163325_add_users/snapshot.json
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-mysql/20260328163343_init/migration.sql
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-mysql/20260328163343_init/snapshot.json
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-mysql/20260328163417_add_users/migration.sql
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format-mysql/20260328163417_add_users/snapshot.json
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format/20260328163300_init/migration.sql
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format/20260328163300_init/snapshot.json
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format/20260328163325_add_users/migration.sql
  • packages/app/drizzle-utils/test/fixtures/migrations-new-format/20260328163325_add_users/snapshot.json
  • packages/app/drizzle-utils/test/generateMigrations.ts

@kibertoad kibertoad merged commit e294edb into main Mar 28, 2026
6 checks passed
@kibertoad kibertoad deleted the feat/new-drizzle-support branch March 28, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant