Skip to content

Migrate legacy SQLite inline constrains and fix long running ones - #7440

Merged
6543 merged 16 commits into
woodpecker-ci:mainfrom
6543-forks:db-migrate_rm-legacy-sqlite-constrains
Nov 24, 2026
Merged

6543 merged 16 commits into
woodpecker-ci:mainfrom
6543-forks:db-migrate_rm-legacy-sqlite-constrains

Conversation

@6543

@6543 6543 commented Oct 30, 2026

Copy link
Copy Markdown
Member

like witho our own database, we still have an constrains that should be longe gone:

sqlite> SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'users';
PRAGMA index_list('users');
sql                                                         
------------------------------------------------------------
CREATE TABLE "users" ( "id" INTEGER PRIMARY KEY AUTOINCREMEN
T, "login" TEXT, "access_token" TEXT, "refresh_token" TEXT, 
"expiry" INTEGER, "email" TEXT, "avatar" TEXT, "admin" BOOLE
AN, "hash" TEXT, `forge_remote_id` TEXT NULL, "org_id" INTEG
ER NULL, `forge_id` INTEGER NULL, UNIQUE("login") )         
seq  name                      unique  origin  partial
---  ------------------------  ------  ------  -------
0    UQE_users_forge_login     1       c       0      
1    UQE_users_forge           1       c       0      
2    UQE_users_hash            1       c       0      
3    sqlite_autoindex_users_1  1       u       0

this currently permits me from logging into ci.woodpecker-ci.org with my codeberg account ...

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
@6543 6543 added bug Something isn't working server labels Oct 30, 2026
@6543

6543 commented Oct 30, 2026

Copy link
Copy Markdown
Member Author
image we have more ...

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
@6543

6543 commented Oct 30, 2026

Copy link
Copy Markdown
Member Author
image aww if i just would have not tryed to log into codeberg ... no rabithoole would have been opened 😆

@6543
6543 requested a review from a team October 30, 2026 02:31
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.75000% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.77%. Comparing base (913b07e) to head (26e9e7e).
⚠️ Report is 61 commits behind head on main.

Files with missing lines Patch % Lines
...igration/032_remove_sqlite_legacy_inline_unique.go 72.72% 12 Missing ⚠️
...ation/005_convert_to_new_pipeline_errors_format.go 85.71% 3 Missing ⚠️
server/store/datastore/migration/migration.go 86.66% 2 Missing ⚠️
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.
📢 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.

@xoxys xoxys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially pipelines and steps table can become quiet big on large instances. I have some performance concerns.

6543 and others added 3 commits November 12, 2026 11:47
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).
@6543
6543 requested a review from xoxys November 12, 2026 11:00
@6543

6543 commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

aah ... about Long, they can be skipped ... in this case i have to rewrite the migration to be skip safe ...

@6543

6543 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member Author

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.
@6543

6543 commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

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

@6543

6543 commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

I dont like Long migrations! ... they are skiped by default and can run at any point long int the future ... currently old installations are broken because of that if you enable it ... I'll append a fix here but we should reconsidder using this :/

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.
@woodpecker-bot

woodpecker-bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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.
@6543 6543 changed the title Migrate legacy SQLite inline constrains Migrate legacy SQLite inline constrains and fix long running ones Nov 12, 2026
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.
@6543

6543 commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

@lafriks ... now long migrations work propperly ... took me bit longer than fliping a bool 😓

@xoxys

xoxys commented Nov 13, 2026

Copy link
Copy Markdown
Member

Ill take a second look.

@6543
6543 merged commit d1aedfd into woodpecker-ci:main Nov 24, 2026
9 checks passed
@6543
6543 deleted the db-migrate_rm-legacy-sqlite-constrains branch November 24, 2026 10:58
@woodpecker-bot woodpecker-bot mentioned this pull request Nov 24, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants