Skip to content

Commit 7266225

Browse files
authored
fix(drizzle): improve db push schema comparison (#12193)
### What? Swaps out `deepAssertEqual` for `dequal` package. Further details and motivation in [this discussion](#12192). ### Why? Dequal is about 100x faster in limited local testing. Dequal package shows 3-5x speed over `deepAssertEqual` in benchmarks. Memory usage is within acceptable levels. ### How? Move the result of dequal to a `const` for readability. Replace the `try { ... } catch { ... }` with `if { ... } else { ... }` for minimum impact and change.
1 parent 1869377 commit 7266225

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

packages/drizzle/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
},
5454
"dependencies": {
5555
"console-table-printer": "2.12.1",
56+
"dequal": "2.0.3",
5657
"drizzle-orm": "0.36.1",
5758
"prompts": "2.4.2",
5859
"to-snake-case": "1.0.0",

packages/drizzle/src/utilities/pushDevSchema.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { deepStrictEqual } from 'assert'
1+
import { dequal } from 'dequal'
22
import prompts from 'prompts'
33

44
import type { BasePostgresAdapter } from '../postgres/types.js'
@@ -23,18 +23,18 @@ export const pushDevSchema = async (adapter: DrizzleAdapter) => {
2323
const localeCodes =
2424
adapter.payload.config.localization && adapter.payload.config.localization.localeCodes
2525

26-
try {
27-
deepStrictEqual(previousSchema, {
28-
localeCodes,
29-
rawTables: adapter.rawTables,
30-
})
26+
const equal = dequal(previousSchema, {
27+
localeCodes,
28+
rawTables: adapter.rawTables,
29+
})
3130

31+
if (equal) {
3232
if (adapter.logger) {
3333
adapter.payload.logger.info('No changes detected in schema, skipping schema push.')
3434
}
3535

3636
return
37-
} catch {
37+
} else {
3838
previousSchema.localeCodes = localeCodes
3939
previousSchema.rawTables = adapter.rawTables
4040
}

pnpm-lock.yaml

Lines changed: 23 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)