OpenVPN-Admin/migration.php

56 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2017-02-05 17:03:00 +01:00
<?php
if (count($argv) !== 2) {
echo "Need the www base path as argument";
exit(0);
}
$www = $argv[1];
require("$www/include/config.php");
require("$www/include/connect.php");
require("$www/include/functions.php");
$migrations = getMigrationSchemas();
try {
$req = $bdd->prepare('SELECT `sql_schema` FROM `application` LIMIT 1');
$req->execute();
$data = $req->fetch();
2017-02-07 22:02:14 +01:00
$sql_schema = -1;
2017-02-05 17:03:00 +01:00
if ($data['sql_schema']) {
$sql_schema = $data['sql_schema'];
}
}
// Table does not exist
catch (Exception $e) {
2017-02-07 22:02:14 +01:00
$sql_schema = -1;
2017-02-05 17:03:00 +01:00
}
// For each migrations
foreach ($migrations as $migration_value) {
// Do the migration, we are behind the last schema
if ($sql_schema < $migration_value) {
// Create the tables or die
$sql_file = dirname(__FILE__) . "/sql/schema-$migration_value.sql";
try {
$sql = file_get_contents($sql_file);
$bdd->exec($sql);
}
catch (PDOException $e) {
printError($e->getMessage());
exit(1);
}
// Update schema to the new value
updateSchema($bdd, $migration_value);
2017-02-07 20:23:21 +01:00
echo "Moved to schema $migration_value\n";
2017-02-05 17:03:00 +01:00
}
}
?>