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]: drizzle-kit push TypeError Cannot use 'in' operator to search for 'default' in undefined #2385

Closed
alexisveryreal opened this issue May 28, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@alexisveryreal
Copy link

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

run drizzle-kit push
get error

 bun run db:push
$ bunx drizzle-kit push
drizzle-kit: v0.21.4
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file 'G:\dev\plan-o-clock\drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...TypeError: Cannot use 'in' operator to search for 'default' in undefined
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18362:23
    at Array.map (<anonymous>)
    at alternationsInColumn (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18361:10)
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18321:49
    at Array.map (<anonymous>)
    at findAlternationsInTable (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18321:37)
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18203:14
    at Array.map (<anonymous>)
    at applyJsonDiff (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18201:69)
    at applyPgSnapshotsDiff (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:19822:26)

I had to drop all my tables and only then it worked

bun db:push
$ bunx drizzle-kit push
drizzle-kit: v0.21.4
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file 'G:\dev\plan-o-clock\drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...[✓] Changes applied

however running it again with NO changes to schema or anything it shows the error again

bun db:push
$ bunx drizzle-kit push
drizzle-kit: v0.21.4
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file 'G:\dev\plan-o-clock\drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...[✓] Changes applied

G://plan-o-clock on  7-feat-board-components ≡  ~4
16:49:14 ❯ bun db:push
$ bunx drizzle-kit push
drizzle-kit: v0.21.4
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file 'G:\dev\plan-o-clock\drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...TypeError: Cannot use 'in' operator to search for 'default' in undefined
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18362:23
    at Array.map (<anonymous>)
    at alternationsInColumn (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18361:10)
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18321:49
    at Array.map (<anonymous>)
    at findAlternationsInTable (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18321:37)
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18203:14
    at Array.map (<anonymous>)
    at applyJsonDiff (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18201:69)
    at applyPgSnapshotsDiff (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:19822:26)

The error is also present when using npm

npm run db:push

> plan-o-clock@0.1.0 db:push
> npx drizzle-kit push

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

No config path provided, using default path
Reading config file 'G:\dev\plan-o-clock\drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...TypeError: Cannot use 'in' operator to search for 'default' in undefined
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18362:23
    at Array.map (<anonymous>)
    at alternationsInColumn (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18361:10)
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18321:49
    at Array.map (<anonymous>)
    at findAlternationsInTable (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18321:37)
    at G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18203:14
    at Array.map (<anonymous>)
    at applyJsonDiff (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:18201:69)
    at applyPgSnapshotsDiff (G:\dev\plan-o-clock\node_modules\drizzle-kit\bin.cjs:19822:26)

Error is not present on older versions of drizzle-kit

bun db:push
$ bunx drizzle-kit push:pg
drizzle-kit: v0.20.17
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file 'G:\dev\plan-o-clock\drizzle.config.ts'
[✓] Changes applied

Expected behavior

  • I should be able to run drizzle-kit push with no errors
  • without having to reset my tables
  • and errors should be present when nothing has even changed?

Please let me know if there is anything else that you need!

Environment & setup

Drizzle Config

import { defineConfig } from "drizzle-kit";

import { env } from "@/env";

export default defineConfig({
  schema: "./src/server/db/schema.ts",
  dialect: "postgresql",
  dbCredentials: {
    url: env.DATABASE_URL,
  },
  tablesFilter: ["plan-o-clock_*"],
});

Drizzle Schema

import { relations, sql } from "drizzle-orm";
import {
  index,
  pgTableCreator,
  serial,
  text,
  varchar,
  timestamp,
  pgEnum,
  date,
  integer,
} from "drizzle-orm/pg-core";

/**
 * This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
 * database instance for multiple projects.
 *
 * @see https://orm.drizzle.team/docs/goodies#multi-project-schema
 */
export const createTable = pgTableCreator((name) => `plan-o-clock_${name}`);

export const board = createTable("board", {
  id: serial("id").primaryKey(),
  title: varchar("title").notNull(),
  orgId: varchar("org_id").notNull(),
  imageId: varchar("image_id"),
  imageThumbUrl: text("image_thumb_url"),
  imageFullUrl: text("image_full_url"),
  imageUserName: text("image_user_name"),
  imageLinkHTML: text("image_link_html"),
  createdAt: timestamp("created_at")
    .default(sql`CURRENT_TIMESTAMP`)
    .notNull(),
  updatedAt: timestamp("updated_at", { mode: "date", precision: 3 }).$onUpdate(
    () => new Date(),
  ),
});

export const boardRelations = relations(board, ({ many }) => ({
  lists: many(list),
}));

export const list = createTable(
  "list",
  {
    id: serial("id").primaryKey(),
    title: varchar("title").notNull(),
    order: serial("order").notNull(),
    boardId: integer("board_id")
      .notNull()
      .references(() => board.id),
    createdAt: timestamp("created_at")
      .default(sql`CURRENT_TIMESTAMP`)
      .notNull(),
    updatedAt: timestamp("updated_at", {
      mode: "date",
      precision: 3,
    }).$onUpdate(() => new Date()),
  },
  (list) => ({
    boardIndex: index("board_index").on(list.boardId),
  }),
);

export const listRelations = relations(list, ({ many }) => ({
  cards: many(card),
}));

export const card = createTable(
  "card",
  {
    id: serial("id").primaryKey(),
    title: varchar("title").notNull(),
    order: serial("order").notNull(),
    description: text("description"),
    listId: integer("list_id")
      .notNull()
      .references(() => list.id),
    dueDate: date("due_date").notNull(),
    createdAt: timestamp("created_at")
      .default(sql`CURRENT_TIMESTAMP`)
      .notNull(),
    updatedAt: timestamp("updated_at", {
      mode: "date",
      precision: 3,
    }).$onUpdate(() => new Date()),
  },
  (card) => ({
    listIndex: index("list_index").on(card.listId),
  }),
);

export const actionEnum = pgEnum("action", ["CREATE", "UPDATE", "DELETE"]);

export const entityTypeEnum = pgEnum("entity_type", ["BOARD", "LIST", "CARD"]);

export const auditLog = createTable("audit_log", {
  id: serial("id").primaryKey(),
  orgId: varchar("org_id").notNull(),
  action: actionEnum("action").notNull(),
  entityId: varchar("entity_id").notNull(),
  entityType: entityTypeEnum("entity_type").notNull(),
  entityTitle: varchar("entity_title"),
  userId: varchar("user_id").notNull(),
  userImage: text("user_image"),
  userName: varchar("user_name"),
  createdAt: timestamp("created_at")
    .default(sql`CURRENT_TIMESTAMP`)
    .notNull(),
  updatedAt: timestamp("updated_at", { mode: "date", precision: 3 }).$onUpdate(
    () => new Date(),
  ),
});

export type Board = typeof board.$inferSelect;
export type NewBoard = typeof board.$inferInsert;
export type List = typeof list.$inferSelect;
export type NewList = typeof list.$inferInsert;
export type Card = typeof card.$inferSelect;
export type NewCard = typeof card.$inferInsert;
export type AuditLog = typeof auditLog.$inferSelect;
export type NewAuditLog = typeof auditLog.$inferInsert;

Package.json

{
  "name": "plan-o-clock",
  "version": "0.1.0",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "next build",
    "db:push": "bunx drizzle-kit push:pg",
    "db:studio": "bunx drizzle-kit studio",
    "dev": "next dev",
    "lint": "next lint",
    "start": "next start"
  },
  "dependencies": {
    "@clerk/nextjs": "^4.29.5",
    "@heroicons/react": "^2.1.1",
    "@hookform/resolvers": "^3.3.4",
    "@neondatabase/serverless": "^0.9.1",
    "@planetscale/database": "^1.11.0",
    "@radix-ui/react-accordion": "^1.1.2",
    "@radix-ui/react-dialog": "^1.0.5",
    "@radix-ui/react-icons": "^1.3.0",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-popover": "^1.0.7",
    "@radix-ui/react-separator": "^1.0.3",
    "@radix-ui/react-slot": "^1.0.2",
    "@t3-oss/env-nextjs": "^0.7.1",
    "@types/lodash": "^4.17.4",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.0",
    "cmdk": "^1.0.0",
    "date-fns": "^3.6.0",
    "drizzle-kit": "^0.21.4",
    "drizzle-orm": "^0.30.10",
    "lodash": "^4.17.21",
    "lucide-react": "^0.321.0",
    "next": "^14.0.4",
    "next-themes": "^0.3.0",
    "react": "18.2.0",
    "react-day-picker": "^8.10.1",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.49.3",
    "sonner": "^1.4.41",
    "tailwind-merge": "^2.2.1",
    "tailwindcss-animate": "^1.0.7",
    "usehooks-ts": "^3.1.0",
    "vaul": "^0.9.0",
    "zod": "^3.22.4",
    "zustand": "^4.5.0"
  },
  "devDependencies": {
    "@types/eslint": "^8.44.7",
    "@types/node": "^18.17.0",
    "@types/react": "^18.2.37",
    "@types/react-dom": "^18.2.15",
    "@typescript-eslint/eslint-plugin": "^6.11.0",
    "@typescript-eslint/parser": "^6.11.0",
    "autoprefixer": "^10.4.14",
    "eslint": "^8.54.0",
    "eslint-config-next": "^14.0.4",
    "pg": "^8.11.5",
    "postcss": "^8.4.31",
    "prettier": "^3.1.0",
    "prettier-plugin-tailwindcss": "^0.5.7",
    "tailwindcss": "^3.3.5",
    "typescript": "^5.1.6"
  },
  "ct3aMetadata": {
    "initVersion": "7.26.0"
  }
}
@alexisveryreal alexisveryreal added the bug Something isn't working label May 28, 2024
@cayter
Copy link
Contributor

cayter commented May 28, 2024

This is likely due to drizzle-kit is trying to patch to ensure timestamp(N) and timestamp (N) are seen as no difference. However, this part of the code forgot to filter out the no difference part which led to the bug.

Screenshot 2024-05-28 at 12 39 29 PM

@KostarSf
Copy link

Same error when trying to change timestamp's mode from "string" to "date"

@aneurycasado
Copy link

Is there an update on this bug? I am running into it as well.

@sp88011
Copy link

sp88011 commented Jun 2, 2024

Getting a similar error since moving to drizzle-kit 0.22.0 and drizzle-orm 0.31.0

No error in drizzle-kit 0.21.0 and drizzle-orm 0.30.7.

drizzle Error: Cannot use 'in' operator to search for 'enumValues' in undefined

@michaeldebetaz
Copy link

michaeldebetaz commented Jun 3, 2024

Same error when trying to change timestamp's mode from "string" to "date"

Same problem here when changing just one timestamp mode from "string" to "date". Can't do any migration with latest release until it's fixed. I'll downgrade for the time being 👍

@BradNut
Copy link

BradNut commented Jun 4, 2024

Any update on this? I wanted to use the new full text search in these new versions but sadly I will still need to wait.

@AndriiSherman
Copy link
Member

Should be fixed in drizzle-kit@0.22.5

@madebyfabian
Copy link

Geting the same as @sp88011 when trying to use the built in geometry. Does anyone still have similar issues?

@austinm911
Copy link

Geting the same as @sp88011 when trying to use the built in geometry. Does anyone still have similar issues?

i reopened this as I'm getting the error with drizzle-zod #2890

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants