mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-13 17:24:54 +02:00
Move migration into separate file + add into admin panel
This fixes some rare bugs when database is no up-to-date and someone enters admin panel
(cherry picked from commit dbe83f8a74
)
This commit is contained in:
22
system/migrate.php
Normal file
22
system/migrate.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
// database migrations
|
||||
$tmp = '';
|
||||
if(fetchDatabaseConfig('database_version', $tmp)) { // we got version
|
||||
$tmp = (int)$tmp;
|
||||
if($tmp < DATABASE_VERSION) { // import if older
|
||||
$db->revalidateCache();
|
||||
for($i = $tmp + 1; $i <= DATABASE_VERSION; $i++) {
|
||||
require SYSTEM . 'migrations/' . $i . '.php';
|
||||
updateDatabaseConfig('database_version', $i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // register first version
|
||||
registerDatabaseConfig('database_version', 0);
|
||||
$db->revalidateCache();
|
||||
for($i = 1; $i <= DATABASE_VERSION; $i++) {
|
||||
require SYSTEM . 'migrations/' . $i . '.php';
|
||||
updateDatabaseConfig('database_version', $i);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user