drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.5k stars 643 forks source link

`introspect:mysql` ignores cloned tables #3301

Open 205g0 opened 1 year ago

205g0 commented 1 year ago

With MySQL you can create different tables but as clones from others and without redeclaring the same columns, e.g.

CREATE TABLE drafts AS
SELECT
  *
FROM
  posts
WHERE
  1 = 0;

...which is ignored by drizzle-kit

205g0 commented 1 year ago

Ok I've found the more idiomatic way to do this (which is ignored too):

CREATE TABLE drafts LIKE posts;

Would be great if you could support this with :introspect. While this sounds like a niche use case it's not. You need this very often once moderation teams need to approve content while letting users still edit their content.

You could declare the table twice but it's error-prone and wouldn't be DRY. Is this possible to implement? If give me some hints, I might be able to submit a PR, thanks @AndriiSherman