Skip to content

Harden CI: MySQL upgrade path, database matrix, schema diff, PHPStan - #1505

Merged
akalongman merged 11 commits into
devfrom
ci-hardening
Nov 12, 2026
Merged

akalongman merged 11 commits into
devfrom
ci-hardening

Conversation

@akalongman

Copy link
Copy Markdown
Member
? !
Type bug / improvement
BC Break no
Fixed issues

Summary

CI now fails a pull request on three kinds of error that have reached releases before: a migration chain that breaks on MySQL, drift between a migrated and a fresh schema, and new static analysis errors. The design record is docs/specs/2026-11-11-ci-hardening-design.md.

Migrations. On MySQL 8.4 and 9.7, 0.60.0-0.61.0.sql and 0.62.0-0.63.0.sql stopped on dropping an index or primary key that backs a foreign key, and on MariaDB-only IF EXISTS syntax. That also left 0.82.0-0.83.0.sql failing on the missing message.via_bot column. Both files now look keys up by column in information_schema and apply changes through PREPARE, so they run unchanged on both servers and can be run more than once.

  • On MariaDB the migrated schema is unchanged except for one line. 0.62.0-0.63.0.sql was meant to drop a duplicate foreign key on message.forward_from named message_ibfk_6. MariaDB 12 names it 6, so the drop was skipped. The file now finds the duplicate by column.
  • On MySQL the telegram_update.poll_answer_poll_id key is not restored after the poll_answer primary key is rebuilt, because MySQL refuses a foreign key to part of a composite key. 0.83.1-0.84.0.sql already adds its reference to poll (id), as on MariaDB.
  • The changelog notes tell MySQL users which files to re-run. That recovery was measured on a MySQL 8.4 database that had kept upgrading release by release.

Database matrix. PHP 8.1 to 8.5 runs on MariaDB 12.3, and PHP 8.5 also runs on MariaDB 10.11, MySQL 8.4 and MySQL 9.7. MariaDB 10.3, which is past end of life, is dropped. Each job does the following:

  • composer db-prepare loads structure.sql into one database, and the 0.44.1 schema plus every migration into another.
  • composer schema-diff compares the two.
  • The test suite runs.

Schema diff. utils/db-schema-diff.php compares the two databases through information_schema:

  • tables, with their engine and collation;
  • columns, with type, nullability, default, character set, collation and extra attributes;
  • indexes, marked as primary key, unique or non-unique;
  • foreign keys, with their ON DELETE and ON UPDATE rules.

Generated key names, comments and column order are ignored. Three known differences are accepted, each with a reason, in utils/db-schema-diff-accepted.txt: botan_shortener, message.new_chat_member and the length of user.username. An accepted entry that no longer matches any difference fails the diff too.

Static analysis. PHPStan runs at level 5 over src/ (composer analyse), with a baseline holding the existing findings. It runs as a Static analysis job that Tests depends on. PHPStan is pinned to exactly 2.3.5, because composer.lock is not committed and the baseline records exact error counts.

The diff now also reads each table's engine and collation, column
EXTRA (auto_increment, on update), the primary key apart from a unique
index on the same columns, and the ON DELETE and ON UPDATE rules of
foreign keys. Keys keep their spelling, so the accepted list is
unchanged; its header now says an entry hides later changes under the
same key. DB_HOST localhost reaches 127.0.0.1 over TCP, as db-prepare.sh
does, instead of the local socket.
Before dropping, every base table of both databases is read, and one
holding a row stops the script with exit 1 unless DB_PREPARE_FORCE=1.
The wait loop gives each attempt a 5 s connect timeout and stops at once
on ERROR 1045 or 1044. A DB_PASSWORD with a double quote or a newline
is refused before the option file is written.
CLAUDE.md describes the extended schema diff, the db-prepare row guard
and the exact exit codes, removes the example container afterwards and
names the TB_ constant list in phpstan.neon.dist. The four schema tools
are export-ignored while utils/db-schema-update keeps shipping, and
.editorconfig keeps tabs in the generated phpstan-baseline.neon.
@akalongman
akalongman merged commit 40e67a0 into dev Nov 12, 2026
11 checks passed
@akalongman
akalongman deleted the ci-hardening branch November 12, 2026 08:41
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.

1 participant