Skip to content

Refactor: Move the migration script out of the request path - #10

Merged
QuickWrite merged 7 commits into
mainfrom
3-move-sqlite-schema-migration
Sep 24, 2026
Merged

QuickWrite merged 7 commits into
mainfrom
3-move-sqlite-schema-migration

Conversation

@QuickWrite

Copy link
Copy Markdown
Owner

On every request the migration system tried a migration to ensure that the database is correct.

However this problematic in terms of perfomance and control. As such the migration logic is now inside of an external script that has to be called outside of the main request path to migrate the SQLite database. This script can be found as bin/migrate.

To ensure that the website does not work with an invalid schema the version is still checked in the request path and returns a 500 internal reponse when invalid to ensure no invalid queries.

On every request the migration system tried a migration to ensure that
the database is correct.

However this problematic in terms of perfomance and control. As such the
migration logic is now inside of an external script that has to be
called outside of the main request path to migrate the SQLite database.
This script can be found as bin/migrate.

To ensure that the website does not work with an invalid schema the
version is still checked in the request path and returns a 500 internal
reponse when invalid to ensure no invalid queries.
@QuickWrite QuickWrite self-assigned this Sep 23, 2026
@QuickWrite QuickWrite added the enhancement New feature or request label Sep 23, 2026
@QuickWrite QuickWrite linked an issue Sep 23, 2026 that may be closed by this pull request
As migrations can theoretically be incorrect, the CI should be able to
see that they are not valid.
As such a new script is added that checks the correctness of these
migrations.
It seems like there was a small oversight and the validity check was
inverted. This meant that every database version that is NOT the
current, was accepted - which is not desirable.
Previously the sorting was based on lexicographic sort. However this led
to the problem that when there are migration files like:
    V9.php and V_10.php
it would sort them in an incorrect order:
    V10.php and V9.php

This would lead to an incorrect order of applications of the migrations
and an invalid database. As such the `natsort` function is now used.
There seems to be an incorrect error message when migrating that
references an outdated class.
It seems like (It didn't occur to me from the documentation) that
natsort does not change the actual order of the keys and as such does
not create a list.
As such PHPStan (correctly) didn't like the natsort.
It seems like the MIGRATION_NAMESPACE was only static and not a
constant. This is completely valid; However this does not mean that it
is semantically correct.
@QuickWrite
QuickWrite merged commit 785d187 into main Sep 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move SQLite schema migration out of the request path into script

1 participant