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

[BUG]: Check command is not working on [email protected]

Open fellipeutaka opened this issue 9 months ago β€’ 8 comments

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.0

Describe the Bug

When I updated drizzle-kit to the new version (0.21.0), the check command stopped working. The first time, the response was as follows:

drizzle\meta\0000_snapshot.json is not of the latest version, please run "drizzle-kit up"

So I ran the drizzle-kit up command and got the following return:

[βœ“] drizzle\meta\0000_snapshot.json
Everything's fine 🐢πŸ”₯

After that, I expected it to work, but that's not the case. Executing the check command after all these procedures, the command returns the following error:

_ZodError: [
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "received": "6",
            "code": "invalid_literal",
            "expected": "5",
            "path": [
              "version"
            ],
            "message": "Invalid literal value, expected \"5\""
          },
          {
            "received": "postgresql",
            "code": "invalid_enum_value",
            "options": [
              "sqlite"
            ],
            "path": [
              "dialect"
            ],
            "message": "Invalid enum value. Expected 'sqlite', received 'postgresql'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.account"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.comment_upvote"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.comment"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.user"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schemas"
            ],
            "path": [],
            "message": "Unrecognized key(s) in object: 'schemas'"
          }
        ],
        "name": "ZodError"
      },
      {
        "issues": [
          {
            "received": "postgresql",
            "code": "invalid_enum_value",
            "options": [
              "sqlite"
            ],
            "path": [
              "dialect"
            ],
            "message": "Invalid enum value. Expected 'sqlite', received 'postgresql'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.account"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.comment_upvote"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.comment"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schema"
            ],
            "path": [
              "tables",
              "public.user"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schemas"
            ],
            "path": [],
            "message": "Unrecognized key(s) in object: 'schemas'"
          }
        ],
        "name": "ZodError"
      }
    ],
    "path": [],
    "message": "Invalid input"
  }
]
    at get error [as error] (C:\Users\Kenji\projects\website\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:2122:28)
    at snapshots.reduce.malformed (C:\Users\Kenji\projects\website\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:6283:35)
    at Array.reduce (<anonymous>)
    at validateWithReport (C:\Users\Kenji\projects\website\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:6269:32)
    at checkHandler (C:\Users\Kenji\projects\website\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:112980:18)
    at Command.<anonymous> (C:\Users\Kenji\projects\website\node_modules\.pnpm\[email protected]\node_modules\drizzle-kit\bin.cjs:114398:3) {
  issues: [
    {
      code: 'invalid_union',
      unionErrors: [Array],
      path: [],
      message: 'Invalid input'
    }
  ],
  addIssue: [Function (anonymous)],
  addIssues: [Function (anonymous)],
  errors: [
    {
      code: 'invalid_union',
      unionErrors: [Array],
      path: [],
      message: 'Invalid input'
    }
  ]
}
drizzle\meta\0000_snapshot.json data is malformed

Expected behavior

No response

Environment & setup

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11
Binaries:
  Node: 20.12.2
  npm: N/A
  Yarn: N/A
  pnpm: 9.0.5

fellipeutaka avatar May 09 '24 16:05 fellipeutaka

same here

> drizzle-kit check

drizzle-kit: v0.21.1
drizzle-orm: v0.30.10

No config path provided, using default 'drizzle.config.ts'
Reading config file '/drizzle.config.ts'
_ZodError: [
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "received": "6",
            "code": "invalid_literal",
            "expected": "5",

AlonMiz avatar May 13 '24 07:05 AlonMiz

Looking into it, thanks!

AndriiSherman avatar May 13 '24 09:05 AndriiSherman

+1, ran into the same issue.

nigelnindodev avatar May 14 '24 23:05 nigelnindodev

Got this issue aswell on 0.21.2. Following the stack trace, this seems to come from what I assume to be a dev test forgotten where it ignores the desired dialect from config/params and instead runs all three dialects.

Code snipped pulled from bin.cjs line 113657 - 113682 in [email protected]. I also included the up command which seems to be doing it properly.

var checkCommand = new import_commander.Command("check").option("--config <config>", `Drizzle config file path`).option("--dialect <dialect>", "Database dialect").option("--out <out>", `Output folder`).action(async (options) => {
  await printVersions();
  await assertOrmCoreVersion();
  const params = cliConfigCheck.parse(options);
  const { out, dialect: dialect7 } = await assertOutFolder(params);
  checkHandler(out, "postgresql");
  checkHandler(out, "sqlite");
  checkHandler(out, "mysql");
  console.log("Everything's fine \u{1F436}\u{1F525}");
});
var upCommand = new import_commander.Command("up").option("--config <config>", `Drizzle config file path`).option("--dialect <dialect>", "Database dialect").option("--out <out>", `Output folder`).action(async (options) => {
  await printVersions();
  await assertOrmCoreVersion();
  const params = cliConfigCheck.parse(options);
  const { out, dialect: dialect7 } = await assertOutFolder(params);
  await assertPackages("drizzle-orm");
  if (dialect7 === "postgresql") {
    upPgHandler(out);
  }
  if (dialect7 === "mysql") {
    upMysqlHandler(out);
  }
  if (dialect7 === "sqlite") {
    upSqliteHandler(out);
  }
});

@AndriiSherman Might be useful information if you're still looking into this :)

svemat01 avatar May 15 '24 12:05 svemat01

+1 here!

dkmooers avatar May 15 '24 17:05 dkmooers

having the same issue, upgraded from

 "drizzle-kit": "^0.20.6",
 "drizzle-orm": "^0.29.1",

To

  "drizzle-orm": "0.30.10",
  "drizzle-kit": "0.21.0",

here is my drizzle.config.ts if it help

import dotenv from  "dotenv"
import type { Config } from "drizzle-kit"
dotenv.config({path: '.env.local'})
export default {
  schema: "./src/db/schema.ts",
  out: "./src/db/migrations",
  dialect: 'postgresql',
  dbCredentials: {
    url: process.env.DB_CONNECTION_URL ?? ''
  },
  migrations: {
    schema: 'public',
    table: 'migrations'
  }

} satisfies Config

TuanManhCao avatar May 17 '24 03:05 TuanManhCao

same problem here

serhii-kucherenko avatar May 20 '24 21:05 serhii-kucherenko

+1, ran into the same issue.

Versions "drizzle-orm": "0.30.6", "drizzle-kit": "0.21.2",

cillajelf avatar May 21 '24 17:05 cillajelf

Same here

ZodError: [
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "code": "invalid_literal",
            "expected": "5",
            "path": [
              "version"
            ],
            "message": "Invalid literal value, expected \"5\""
          },
          {
            "code": "invalid_literal",
            "expected": "pg",
            "path": [
              "dialect"
            ],
            "message": "Invalid literal value, expected \"pg\""
          },
          {
            "code": "invalid_type",
            "expected": "string",
            "received": "undefined",
            "path": [
              "tables",
              "segment",
              "schema"
            ],
            "message": "Required"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "index"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "startLat"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "startLng"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "endLat"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "endLng"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "startDate"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "endDate"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "tripId"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "invalid_type",
            "expected": "object",
            "received": "undefined",
            "path": [
              "schemas"
            ],
            "message": "Required"
          }
        ],
        "name": "ZodError"
      },
      {
        "issues": [
          {
            "code": "invalid_literal",
            "expected": "postgresql",
            "path": [
              "dialect"
            ],
            "message": "Invalid literal value, expected \"postgresql\""
          },
          {
            "code": "invalid_type",
            "expected": "string",
            "received": "undefined",
            "path": [
              "tables",
              "segment",
              "schema"
            ],
            "message": "Required"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "index"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "startLat"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "startLng"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "endLat"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "endLng"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "startDate"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "endDate"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "autoincrement"
            ],
            "path": [
              "tables",
              "segment",
              "columns",
              "tripId"
            ],
            "message": "Unrecognized key(s) in object: 'autoincrement'"
          },
          {
            "code": "invalid_type",
            "expected": "object",
            "received": "undefined",
            "path": [
              "schemas"
            ],
            "message": "Required"
          }
        ],
        "name": "ZodError"
      }
    ],
    "path": [],
    "message": "Invalid input"
  }
]

XantreDev avatar May 22 '24 11:05 XantreDev

Here is a patch (for pnpm) patches/[email protected]

diff --git a/bin.cjs b/bin.cjs
index 02a2165a023b86ad1bbc2e3fef1193404b2c97f1..787b7830b3f6d88b19c916e2eed34d1b9b1ceeba 100644
--- a/bin.cjs
+++ b/bin.cjs
@@ -113659,9 +113659,7 @@ var checkCommand = new import_commander.Command("check").option("--config <confi
   await assertOrmCoreVersion();
   const params = cliConfigCheck.parse(options);
   const { out, dialect: dialect7 } = await assertOutFolder(params);
-  checkHandler(out, "postgresql");
-  checkHandler(out, "sqlite");
-  checkHandler(out, "mysql");
+  checkHandler(out, dialect7);
   console.log("Everything's fine \u{1F436}\u{1F525}");
 });
 var upCommand = new import_commander.Command("up").option("--config <config>", `Drizzle config file path`).option("--dialect <dialect>", "Database dialect").option("--out <out>", `Output folder`).action(async (options) => {

XantreDev avatar May 22 '24 11:05 XantreDev

This should be fixed in [email protected]. If the issue persists, feel free to reopen it!

AndriiSherman avatar May 22 '24 14:05 AndriiSherman

This should be fixed in [email protected]. If the issue persists, feel free to reopen it!

lifesaver, thanks

serhii-kucherenko avatar May 22 '24 18:05 serhii-kucherenko

drizzle-kit check

It's still an issue in 22.7

MincePie avatar Jun 23 '24 01:06 MincePie

Still an issue in 22.8

jdublon avatar Jul 08 '24 13:07 jdublon