Repository navigation
Migrate legacy SQLite inline constrains and fix long running ones - #7440
Conversation
SQLite databases that started on the schema before xorm still carry inline UNIQUE table constraints. The column renames of migration 009 kept them, and xorm Sync cannot see them because they have no index SQL, so they were never dropped. Three are stricter than the models: users UNIQUE(login) blocks the same login on another forge, configs UNIQUE(hash, repo_id) blocks the same content under another name, and secrets UNIQUE(name, repo_id) blocks the same secret name in two orgs or in an org and globally. perms carries a duplicate of its model index. On SQLite, rebuild users, configs, secrets and perms if they still have such a constraint: rename the table, create it again from a frozen copy of its model, copy the rows (a NULL in a column that is NOT NULL in the model gets the column default), and keep sqlite_sequence so ids are not handed out again. Other databases are left alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qcZ1iGzw7htVjQYqkh7yQ
Run the migration over the legacy SQLite fixture, which carries the same inline constraints as old instances, and check that they are gone, that no row is lost and ids are not reused, that the rows the old constraints blocked can be stored while the model constraints still hold, that the rebuilt tables match a new install, and that a second run changes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qcZ1iGzw7htVjQYqkh7yQ
Drop what the rebuild does not need: the row count check and the final constraint check guard against things the transaction and Sync already rule out, the table existence check is covered by pragma_index_list returning no rows, and the column type sniffing is replaced by the column default or ''. The old sqlite_sequence row is now moved to the new table instead of being read and written back. Test that the sequence is kept when it is higher than the highest id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qcZ1iGzw7htVjQYqkh7yQ
steps and pipelines carry the same kind of inline UNIQUE constraint. It only repeats a model index, but removing it brings these tables in line with a new install too. Rebuilding them also drops leftover columns the models no longer have, such as pipeline_enqueued or step_machine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qcZ1iGzw7htVjQYqkh7yQ
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7440 +/- ##
==========================================
+ Coverage 66.76% 66.77% +0.01%
==========================================
Files 450 451 +1
Lines 22582 22653 +71
==========================================
+ Hits 15076 15127 +51
- Misses 7506 7526 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
xoxys
left a comment
There was a problem hiding this comment.
Especially pipelines and steps table can become quiet big on large instances. I have some performance concerns.
Admins must opt in with WOODPECKER_MIGRATIONS_ALLOW_LONG, and the rebuild runs in one transaction, so it needs free disk space of about twice the database size (review by xoxys).
|
aah ... about Long, they can be skipped ... in this case i have to rewrite the migration to be skip safe ... |
|
one note: #1847 would have fixed that ... |
The migration is Long, so it can be skipped and run some versions later, after the sync has already moved the tables on. Rebuilding from frozen structs would then drop data of columns added in between. Find the tables by their inline UNIQUE constraints, recreate each one with its own columns and copy all rows over. The indexes go with the old table and are added back by the sync after the migrations. Column types and NOT NULL stay as they were; only indexes and constraints matter here.
|
with this we dont get rid of wrong defaults and wrong NULL or NOT NULL defiitions ... but that one mostly makes no problems as xorm handles and prefills anyway |
|
I dont like |
convert-to-new-pipeline-error-format was Long since v2.1.0, so instances upgraded from 1.x without allowing long migrations skipped it. Since v2.7.0 unify-columns-tables renames pipeline_id and pipeline_errors, and a late run failed with "Cannot add a PRIMARY KEY column", which stops the server from starting. Read the column names from the table, so it works before and after the rename, and run it on every start until it is done: the old error texts are still there and get converted.
The test called the migration and the sync by hand because a late run of convert-to-new-pipeline-error-format failed. That is fixed now, so let a second start with long migrations allowed do the real work.
|
Surge PR preview deployment was removed |
Without pipeline_error there is nothing to convert, but the migration still added the column only to drop it again. Check for it first and stop if it is gone.
Long migrations can be skipped and run many versions later against a newer schema. Two of them broke that way, so tell developers to write them for any schema.
xormigrate skips long migrations silently when they are not allowed, so admins never learn that one is waiting. Log a warning for each of them after the migrations.
Run all migrations without the long ones first, then start again with them allowed, like an admin who turns them on later. This would have caught convert-to-new-pipeline-error-format failing after unify-columns-tables. The same flow in TestPendingLongMigrations moves here.
|
@lafriks ... now long migrations work propperly ... took me bit longer than fliping a bool 😓 |
|
Ill take a second look. |


like witho our own database, we still have an constrains that should be longe gone:
this currently permits me from logging into ci.woodpecker-ci.org with my codeberg account ...