stephenafamo / bob

SQL query builder and ORM/Factory generator for Go with support for PostgreSQL, MySQL and SQLite
https://bob.stephenafamo.com
MIT License
760 stars 39 forks source link

Cannot load index information for functional indexes #244

Closed pcriv closed 3 months ago

pcriv commented 3 months ago

After upgrading to 0.28.0 from 0.27.1, I'm getting the following error when trying to generate code from my schema:

unable to fetch table data: unable to load indexes: sql: Scan error on column index 2, name "column_name": converting NULL to string is unsupported
stephenafamo commented 3 months ago

Can you share more details?

pcriv commented 3 months ago

driver: mysql config:

---
mysql:
  dsn: "root:@tcp(localhost:3306)/dname"
  output: internal/dbgen
  pkgname: dbgen
  except:
    schema_migrations:
relationships:
  # hidden

About the schema, I cannot share the whole schema, but is there any specific part that you have in mind that could help?

stephenafamo commented 3 months ago

is there any specific part that you have in mind that could help?

The part that helps to reproduce the error.

Perhaps you can use the only configuration to generate table-by-table till you find the offending table and share a schema of that table?

pcriv commented 3 months ago

That's a good idea! I'll try that and keep you updated, thanks!

pcriv commented 3 months ago

I think I found the offensive line. FYI, the only option did not work, it was failing no matter which table I added, so I had to get creative

This is a bit of an ugly one:

KEY `index_batches_tags_workspace_id` (((cast(json_unquote(json_extract(`tags`,_utf8mb4'$.workspaceId')) as char(255) charset utf8mb4) collate utf8mb4_bin)))
stephenafamo commented 3 months ago

This probably has something to do with #237

Can you perhaps take a look @mbezhanov?

mbezhanov commented 3 months ago

Sure, I'll have a look right away.

mbezhanov commented 3 months ago

Okay, I've identified the issue. This is a functional index (it indexes expressions rather than columns), so column_names in information_schema.statistics is indeed NULL. I'm working on a fix.

pcriv commented 3 months ago

Thanks for the quick reactions @mbezhanov and @stephenafamo ❤️

mbezhanov commented 3 months ago

No problem at all, and sorry for my oversight!