Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] check throws a zod validation error #414

Open
rphlmr opened this issue May 17, 2024 · 1 comment
Open

[BUG] check throws a zod validation error #414

rphlmr opened this issue May 17, 2024 · 1 comment

Comments

@rphlmr
Copy link
Contributor

rphlmr commented May 17, 2024

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

drizzle-kit check throws a zod validation error.

dotenv -e .env -- drizzle-kit check --config=drizzle.server.config.ts
drizzle-kit: v0.21.2
drizzle-orm: v0.30.10

Reading config file '/Users/rphlmr/workspaces/rphlmr/drizzle-play/drizzle.server.config.ts'
ZodError: [
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "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.playground"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schemaTo"
            ],
            "path": [
              "tables",
              "public.user",
              "foreignKeys",
              "user_id_users_id_fk"
            ],
            "message": "Unrecognized key(s) in object: 'schemaTo'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "nullsNotDistinct"
            ],
            "path": [
              "tables",
              "public.user",
              "uniqueConstraints",
              "user_username_unique"
            ],
            "message": "Unrecognized key(s) in object: 'nullsNotDistinct'"
          },
          {
            "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.playground"
            ],
            "message": "Unrecognized key(s) in object: 'schema'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "schemaTo"
            ],
            "path": [
              "tables",
              "public.user",
              "foreignKeys",
              "user_id_users_id_fk"
            ],
            "message": "Unrecognized key(s) in object: 'schemaTo'"
          },
          {
            "code": "unrecognized_keys",
            "keys": [
              "nullsNotDistinct"
            ],
            "path": [
              "tables",
              "public.user",
              "uniqueConstraints",
              "user_username_unique"
            ],
            "message": "Unrecognized key(s) in object: 'nullsNotDistinct'"
          },
          {
            "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 handleResult (/Users/rphlmr/workspaces/rphlmr/drizzle-play/node_modules/drizzle-kit/bin.cjs:2012:24)
    at ZodUnion.safeParse (/Users/rphlmr/workspaces/rphlmr/drizzle-play/node_modules/drizzle-kit/bin.cjs:2105:16)
    at snapshots.reduce.malformed (/Users/rphlmr/workspaces/rphlmr/drizzle-play/node_modules/drizzle-kit/bin.cjs:5650:38)
    at Array.reduce (<anonymous>)
    at validateWithReport (/Users/rphlmr/workspaces/rphlmr/drizzle-play/node_modules/drizzle-kit/bin.cjs:5638:32)
    at checkHandler (/Users/rphlmr/workspaces/rphlmr/drizzle-play/node_modules/drizzle-kit/bin.cjs:112243:18)
    at Command.<anonymous> (/Users/rphlmr/workspaces/rphlmr/drizzle-play/node_modules/drizzle-kit/bin.cjs:113663: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'
    }
  ]
}
@svemat01
Copy link

TLDR: The check command currently ignores the selected dialect and instead runs for all dialects. Local solve is to comment out the dialects you're not using in the bin.cjs file, see codesnippet below.

This issue has been reported on the drizzle-orm repo aswell under drizzle-orm#2284.
I looked thru the compiled cli code for drizzle-kit and found that the check command currently ignores the dialect you have chosen. I've attached the problematic code and also the code for the up command which does the dialect check correctly.

Seems like just a dev test that was forgotten or that in the past the checkHandlers themselves quit if it wasn't the correct dialect. Should be a rather simple fix just copying what's being done in the up command.

Code snipped from bin.cjs line 113657 - 113682 in [email protected].

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);
  }
});

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

No branches or pull requests

2 participants