drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Cannot read properties of null (reading 'open') when running `npx drizzle-kit push`

Open lukaskoeller opened this issue 9 months ago • 3 comments

Report hasn't been filed before.

  • [x] I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.40.0

What version of drizzle-kit are you using?

0.30.5

Other packages

@electric-sql/[email protected], [email protected]

Describe the Bug

Undesired behavior

Running npx drizzle-kit push puts out TypeError: Cannot read properties of null (reading 'open') error.

Desired Result

No error is shown and the schema is correctly pushed.

Reproduction

[!NOTE] Reproduced repository: https://github.com/lukaskoeller/drizzle-pglite-open-reproduction

  1. Creating a new SvelteKit app:
npx sv create my-app
  1. Follow the "Get Started with Drizzle and PGlite" guide.
  2. Add driver: 'pglite' to drizzle.config.ts to get rid of To connect to Postgres database - please install either of 'pg', 'postgres', '@neondatabase/serverless' or '@vercel/postgres' drivers.
  3. Run npx drizzle-kit push
  4. This puts out following error in the zsh:
lukas@Mac readii % npx drizzle-kit push
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/lukas/Documents/priv/readii/drizzle.config.ts'
TypeError: Cannot read properties of null (reading 'open')
    at Object.getDB (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/release/postgres.js:9:113692)
    at Object.getRemoteSet (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/release/postgres.js:9:114890)
    at callback (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/release/postgres.js:9:113341)
    at Object.getLocalSet (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/release/postgres.js:9:114798)
    at Object.syncfs (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/release/postgres.js:9:113275)
    at mount (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/release/postgres.js:9:131497)
    at Array.forEach (<anonymous>)
    at Object.syncfs (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/release/postgres.js:9:131429)
    at <anonymous> (/Users/lukas/Documents/priv/readii/node_modules/.pnpm/@[email protected]/node_modules/@electric-sql/pglite/src/fs/idbfs.ts:31:26)
    at new Promise (<anonymous>)

Context

tsconfig.json

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"allowJs": true,
		"checkJs": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true,
		"moduleResolution": "bundler"
	}
	// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
	// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
	//
	// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
	// from the referenced tsconfig.json - TypeScript does not merge them in
}

.sveltekit/tsconfig.json

{
	"compilerOptions": {
		"paths": {
			"$lib": [
				"../src/lib"
			],
			"$lib/*": [
				"../src/lib/*"
			]
		},
		"rootDirs": [
			"..",
			"./types"
		],
		"verbatimModuleSyntax": true,
		"isolatedModules": true,
		"lib": [
			"esnext",
			"DOM",
			"DOM.Iterable"
		],
		"moduleResolution": "bundler",
		"module": "esnext",
		"noEmit": true,
		"target": "esnext"
	},
	"include": [
		"ambient.d.ts",
		"non-ambient.d.ts",
		"./types/**/$types.d.ts",
		"../vite.config.js",
		"../vite.config.ts",
		"../src/**/*.js",
		"../src/**/*.ts",
		"../src/**/*.svelte",
		"../tests/**/*.js",
		"../tests/**/*.ts",
		"../tests/**/*.svelte"
	],
	"exclude": [
		"../node_modules/**",
		"../src/service-worker.js",
		"../src/service-worker/**/*.js",
		"../src/service-worker.ts",
		"../src/service-worker/**/*.ts",
		"../src/service-worker.d.ts",
		"../src/service-worker/**/*.d.ts"
	]
}

lukaskoeller avatar Mar 16 '25 16:03 lukaskoeller

Related issue posted on Discord: https://discord.com/channels/1043890932593987624/1332861839561986069

lukaskoeller avatar Mar 16 '25 16:03 lukaskoeller

Hey everyone!

I've created this message to send in a batch to all opened issues we have, just because there are a lot of them and I want to update all of you with our current work, why issues are not responded to, and the amount of work that has been done by our team over ~8 months.

I saw a lot of issues with suggestions on how to fix something while we were not responding – so thanks everyone. Also, thanks to everyone patiently waiting for a response from us and continuing to use Drizzle!

We currently have 4 major branches with a lot of work done. Each branch was handled by different devs and teams to make sure we could make all the changes in parallel.


First branch is drizzle-kit rewrite

All of the work can be found on the alternation-engine branch. Here is a PR with the work done: https://github.com/drizzle-team/drizzle-orm/pull/4439

As you can see, it has 167k added lines of code and 67k removed, which means we've completely rewritten the drizzle-kit alternation engine, the way we handle diffs for each dialect, together with expanding our test suite from 600 tests to ~9k test units for all different types of actions you can do with kit. More importantly, we changed the migration folder structure and made commutative migrations, so you won't face complex conflicts on migrations when working in a team.

What's left here:

  • We are finishing handling defaults for Postgres, the last being geometry (yes, we fixed the srid issue here as well).
  • We are finishing commutative migrations for all dialects.
  • We are finishing up the command, so the migration flow will be as simple as drizzle-kit up for you.

Where it brings us:

  • We are getting drizzle-kit into a new good shape where we can call it [email protected]!

Timeline:

  • We need ~2 weeks to finish all of the above and send this branch to beta for testing.

Second big branch is a complex one with several HUGE updates

  • Bringing Relational Queries v2 finally live. We've done a lot of work here to actually make it faster than RQBv1 and much better from a DX point of view. But in implementing it, we had to make another big rewrite, so we completely rewrote the drizzle-orm type system, which made it much simpler and improved type performance by ~21.4x:
(types instantiations for 3300 lines production drizzle schema + 990 lines relations)

TS v5.8.3: 728.8k -> 34.1k
TS v5.9.2: 553.7k -> 25.4k

You can read more about it here.

What's left here:

Where it brings us:

  • We are getting drizzle-orm into a new good shape where we can call it [email protected]!

Breaking changes:

  • We will have them, but we will have open channels for everyone building on top of drizzle types, so we can guide you through all the changes.

Third branch is adding support for CockroachDB and MSSQL dialects

Support for them is already in the alternation-engine branch and will be available together with the drizzle-kit rewrite.

Summary

All of the work we are doing is crucial and should be done sooner rather than later. We've received a lot of feedback and worked really hard to find the best strategies and decisions for API, DX, architecture, etc., so we can confidently mark it as v1 and be sure we can improve it and remain flexible for all the features you are asking for, while becoming even better for everyone building on top of the drizzle API as well.

We didn't want to stay with some legacy decisions and solutions we had, and instead wanted to shape Drizzle in a way that will be best looking ahead to 2025–2026 trends (v1 will get proper effect support, etc.).

We believe that all of the effort we've put in will boost Drizzle and benefit everyone using it.

Thanks everyone, as we said, we are here to stay for a long time to build a great tool together!

Timelines

We are hoping to get v1 for drizzle in beta this fall and same timeline for latest. Right after that we can go through all of the issues and PRs and resond everyone. v1 for drizzle should close ~70% of all the bug tickets we have, so on beta release we will start marking them as closed!

AndriiSherman avatar Aug 30 '25 19:08 AndriiSherman

Hi @lukaskoeller. I tried to reproduce the issue using the repository you provided, and everything worked without errors. My steps:

  1. git clone https://github.com/lukaskoeller/drizzle-pglite-open-reproduction
  2. cd drizzle-pglite-open-reproduction
  3. pnpm i
  4. added .env file with this content DATABASE_URL=pglite-test
  5. npx drizzle-kit push

It might be that the DATABASE_URL in your .env is incorrect. You can double-check if your environment variable is correct by running the .ts file that creates the database instance and uses it as shown below.

Image

OleksiiKH0240 avatar Nov 12 '25 12:11 OleksiiKH0240

@OleksiiKH0240 Sorry, I just checked and it should be DATABASE_URL="idb://pglite-test" not DATABASE_URL="pglite-test". Looking at this again, it probably makes sense that it fails because it cannot access the Index DB?

From using expo-sqlite with drizzle I know there's a special useMigrations hook which is probably there to execute migrations at run time. I guess a similar functionality would be needed here too?

(I updated the repro repo accordingly)

lukaskoeller avatar Nov 21 '25 16:11 lukaskoeller