szurubooru/upgrade.php

33 lines
827 B
PHP
Raw Normal View History

2013-10-20 11:05:46 +02:00
<?php
require_once 'src/core.php';
$config = configFactory();
$dbVersion = Model_Property::get('db-version');
printf('DB version = %d' . PHP_EOL, $dbVersion);
$upgrades = glob('src/Upgrades/*.sql');
natcasesort($upgrades);
foreach ($upgrades as $upgradePath)
{
preg_match('/(\d+)\.sql/', $upgradePath, $matches);
$upgradeVersion = intval($matches[1]);
if ($upgradeVersion > $dbVersion)
{
printf('Executing %s...' . PHP_EOL, $upgradePath);
$upgradeSql = file_get_contents($upgradePath);
2013-11-10 12:23:59 +01:00
$upgradeSql = preg_replace('/^[ \t]+(.*);/m', '\0--', $upgradeSql);
2013-10-20 11:05:46 +02:00
$queries = preg_split('/;\s*[\r\n]+/s', $upgradeSql);
$queries = array_map('trim', $queries);
foreach ($queries as $query)
{
echo $query . PHP_EOL;
R::exec($query);
echo PHP_EOL;
}
}
Model_Property::set('db-version', $upgradeVersion);
}