fix(migrations): drop SQLite columns natively instead of by schema text - #38937
fix(migrations): drop SQLite columns natively instead of by schema text#38937bircni wants to merge 1 commit into
Conversation
The SQLite path of DropTableColumns rebuilt the table from the CREATE TABLE text in sqlite_master, stripping the target columns with a regex that only matched backtick-quoted identifiers. On a database whose schema text was written by another tool the strip matched nothing, the rebuild copied the column across, and the migration reported success. Migration 331 drops action_run.concurrency_group that way. When the drop silently did nothing, the leftover NOT NULL column was one no model writes any more, so every run insert failed with "NOT NULL constraint failed: action_run.concurrency_group" and no workflow could start. Use ALTER TABLE DROP COLUMN, which is quoting agnostic, and drop every index covering a target column first rather than only single-column ones. Migration 349 re-runs the action_run drop for instances already past 331. Fixes go-gitea#38916
wxiaoguang
left a comment
There was a problem hiding this comment.
If we have to write these SQLs from scratch .... it's still questionable whether XORM is a production-level framework or it is just a toy: its table DDL functions just can't complete a migration task, developers have to keep writing different logic for different databases ..........
That's also why I don't want to write any new migration for #38921: just bugs, plenty of bugs.
so what shall I do now? xD |
I have no idea. Just mention XORM author: @lunny |
that repo has over 300 unanswered issues.. And to find it now finally I had to fall over 2 archived Repos lol |
|
Is there any alternative to xorm? |
For this one: the whole table-rebuild dance only exists because SQLite had no |
Multiple depending on what you like/need:
There's also the option of fixing xorm's issues. |
|
Gorm imho, probably with the new generics api: https://gorm.io/docs/the_generics_way.html |
|
FYI I've now added a line in 88058a4 in AGENTS.md for this |
The SQLite path of
DropTableColumnsrebuilt the table from theCREATE TABLEtext insqlite_masterand stripped the target columns with a regex that only matched backtick-quoted identifiers. On a database whose schema text was written by another tool, the strip matched nothing, the rebuild copied the column straight across, and the migration still returned success.Migration 331 drops
action_run.concurrency_groupthat way. Where the drop silently did nothing, the leftoverNOT NULLcolumn is one no model writes any more, so every run insert fails and no workflow can start:ALTER TABLE ... DROP COLUMNis quoting agnostic and available since SQLite 3.35, well below what either bundled driver ships. Using it also means the index cleanup has to cover composite indexes, not just single-column ones — SQLite refuses to drop a column any index still references, andIDX_action_run_repo_concurrencyis exactly such an index.Migration 349 re-runs the
action_rundrop, since instances already past 331 do not get another chance at it.Not backportable to 1.27: 1.27.0 ends at migration ID 342 and 343 is taken by 1.28, so a new migration cannot be added to the release branch. Affected 1.27 instances can drop the two columns by hand in the meantime.
Fixes #38916