Skip to content

fix(sqlite): read the definition of the first column when introspecting a table - #8518

Merged
B4nan merged 2 commits into
mikro-orm:masterfrom
NgoQuocViet2001:fix-sqlite-first-column-introspection
Nov 4, 2026
Merged

B4nan merged 2 commits into
mikro-orm:masterfrom
NgoQuocViet2001:fix-sqlite-first-column-introspection

Conversation

@NgoQuocViet2001

@NgoQuocViet2001 NgoQuocViet2001 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

SQLite introspection finds each column's definition in the create table SQL with a regex that expects a comma before the column name. The first column has none, so its collation, inline check (including enum items) and generated expression were never read. The entity generator dropped them, introspection threw Cannot read properties of undefined (reading 'definition') when the first column was generated, and a collated or enum primary key (or a pivot FK column that copies its collation) made getUpdateSchemaSQL() return a table rebuild right after schema.create() instead of an empty string:

create table `country__temp_alter` (`code` text collate NOCASE not null primary key, `name` text not null);
insert into `country__temp_alter` select `code`, `name` from `country`;
drop table `country`;
alter table `country__temp_alter` rename to `country`;

The regex now also matches the column at the start of the column list. Other columns still need the leading comma.

…ng a table

The column definitions were matched with a regex that requires a comma
before the column name, so the first column of a `create table`
statement was never matched. Its collation, inline check (including
enum items) and generated expression were lost, which made
`getUpdateSchemaSQL()` rebuild the table right after `schema.create()`
and made introspection throw for a generated first column.
@B4nan
B4nan enabled auto-merge (squash) November 4, 2026 00:33
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.66%. Comparing base (e02bb16) to head (7a3a7c4).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #8518       +/-   ##
===========================================
+ Coverage   80.10%   99.66%   +19.56%     
===========================================
  Files         293      293               
  Lines       32316    32349       +33     
  Branches     8725     8735       +10     
===========================================
+ Hits        25886    32242     +6356     
+ Misses       6421      103     -6318     
+ Partials        9        4        -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@B4nan
B4nan merged commit b0f843e into mikro-orm:master Nov 4, 2026
26 checks passed
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

Successfully merging this pull request may close these issues.

2 participants