diff options
| author | 2020-07-08 12:11:55 +0200 | |
|---|---|---|
| committer | 2020-07-08 12:11:55 +0200 | |
| commit | 8619cf6fa65bbd90871e7b7fe29816092a9d6c33 (patch) | |
| tree | 629128aff93470b1bdb2ca948d5cb31968dc982b /p | |
| parent | 4894a9e7914b16a242ad405afdbda84d86ec3830 (diff) | |
Add a migration system (#2760)
* Add a Minz_Migrator class
Until now, we updated the database structure somewhere in the code but
it wasn't always consistent and somehow complicated to find. Also, this
code was always checked for nothing.
The Migrator aims to improve and ease the creation of migrations. It
should improve the way we apply the updates, making the update server
almost useless.
References:
- example of migration (before Migrator): https://github.com/FreshRSS/FreshRSS/commit/cc0db9af4f980829faa4bf0960617807b32fb4fa#diff-11a53443fa81512b128c66b065df0679R10
- update server: https://github.com/FreshRSS/update.freshrss.org
- PR moving the code of the update server to the core: https://github.com/FreshRSS/FreshRSS/pull/1760
* Automatically apply migrations
For now, administrators are used to have nothing to do during an update
else than getting the new code. I suggest to keep this behaviour and
automatically apply migrations if we detect new ones.
Another solution would be to create a CLI command and ask admins to call
it after getting the new code. It could hide migrations errors to end
users, but admin can forget to apply migrations since there are not used
to it.
* Add documentation for Minz Migrator
* Execute migrations even if next ones are applied
* Change mechanism to prevent multiple update at once
* Use mkdir to create the lock and to test it exists
Reference: https://stackoverflow.com/a/731634
* Append .lock to applied_migrations_path
There are no needs to define another file to serve as a lock.
* Change migrations naming convention
* Apply suggestions from code review
Co-Authored-By: Alexandre Alapetite <alexandre@alapetite.fr>
* Perform a low-cost migration versions comparaison
* Clarify version numbers concerning the migration system
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'p')
| -rwxr-xr-x | p/i/index.php | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/p/i/index.php b/p/i/index.php index d366566ab..35e53ec5e 100755 --- a/p/i/index.php +++ b/p/i/index.php @@ -42,14 +42,43 @@ if (file_exists(DATA_PATH . '/do-install.txt')) { } } + $migrations_path = APP_PATH . '/migrations'; + $applied_migrations_path = DATA_PATH . '/applied_migrations.txt'; + + // The next line is temporary: the migrate method expects the applied_migrations.txt + // file to exist. This is because the install script creates this file, so + // if it is missing, it means the application is not installed. But we + // should also take care of applications installed before the new + // migrations system (<=1.16). Indeed, they are installed but the migrations + // version file doesn't exist. So for now (1.17), we continue to check if the + // application is installed with the do-install.txt file: if yes, we create + // the version file. Starting from version 1.18, all the installed systems + // will have the file and so we will be able to remove this temporary line + // and stop using the do-install.txt file to check if FRSS is already + // installed. + touch($applied_migrations_path); + + $error = false; try { - $front_controller = new FreshRSS(); - $front_controller->init(); - $front_controller->run(); + // Apply the migrations if any + $result = Minz_Migrator::execute($migrations_path, $applied_migrations_path); + if ($result === true) { + $front_controller = new FreshRSS(); + $front_controller->init(); + $front_controller->run(); + } else { + $error = $result; + } } catch (Exception $e) { + $error = $e->getMessage(); + } + + if ($error) { + // TODO this should be definitely improved to display a nicer error + // page to the users (especially non administrators). echo '### Fatal error! ###<br />', "\n"; - Minz_Log::error($e->getMessage()); + Minz_Log::error($error); echo 'See logs files.'; - syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $e->getMessage()); + syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $error); } } |
