Skip to content

[BUG]: drizzle-kit pull fails if db includes views which are not in "tablesFilter" #4170

@nd1312

Description

@nd1312

Report hasn't been filed before.

  • 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.39.3

What version of drizzle-kit are you using?

0.30.4

Other packages

No response

Describe the Bug

I'm trying to introspect our aws mysql db with drizzle-kit pull.
The database contains about 100 tables and 5 views.

In drizzle.config i've set tablesFitler to one table.

When running drizzle-kit pull it fails with: Cannot read properties of undefined (reading 'columns')

Pulling from ['public'] list of schemas

[✓] 1  tables fetched
[✓] 11 columns fetched
[⣽] 2  indexes fetching
[✓] 42 foreign keys fetched
[⣽] 0  policies fetching
[⣽] 0  check constraints fetching
[⣽] 5  views fetching
TypeError: Cannot read properties of undefined (reading 'columns')
    at fromDatabase (/home/.../node_modules/drizzle-kit/bin.cjs:17811:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Here's the relevant code in bin.cjs:

const views = await db.query(
        `select * from INFORMATION_SCHEMA.VIEWS WHERE table_schema = '${inputSchema}';`
      );
      const resultViews = {};
      viewsCount = views.length;
      if (progressCallback) {
        progressCallback("views", viewsCount, "fetching");
      }
      for await (const view4 of views) {
        const viewName = view4["TABLE_NAME"];
        const definition = view4["VIEW_DEFINITION"];
        const withCheckOption = view4["CHECK_OPTION"] === "NONE" ? void 0 : view4["CHECK_OPTION"].toLowerCase();
        const sqlSecurity = view4["SECURITY_TYPE"].toLowerCase();
        const [createSqlStatement] = await db.query(`SHOW CREATE VIEW \`${viewName}\`;`);
        const algorithmMatch = createSqlStatement["Create View"].match(/ALGORITHM=([^ ]+)/);
        const algorithm = algorithmMatch ? algorithmMatch[1].toLowerCase() : void 0;
        const columns2 = result[viewName].columns; // <--- error

The problem seems to be that result only contains the data for the one filtered table but for views the filter is ignored and all views are being iterated.

If I add all the views to tablesFilter then drizzle-kit pull works as expected.

I'm using bun, but it also fails with npx

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdrizzle/kitpriorityWill be worked on next

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions