forked from Chocobozzz/OpenVPN-Admin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
migration.php
55 lines (43 loc) · 1.18 KB
/
migration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?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();
$sql_schema = -1;
if ($data['sql_schema']) {
$sql_schema = $data['sql_schema'];
}
}
// Table does not exist
catch (Exception $e) {
$sql_schema = -1;
}
// 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);
echo "Moved to schema $migration_value\n";
}
}
?>