blob: 3120a756500559dee8b0043581023a5bd3b1bf38 (
plain)
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
|
<?php
// get my current version.
// this needs to come from the DB
// group all ver
$versions = [];
$line = fgets(STDIN);
if(!preg_match("/^# Versioned Migration Script$/", $line)) {
die("Sorry, this doesn't look like a versioned file.\n");
}
// find current version.
// find max version
$current_version = 1;
$v = "0";
while($line = fgets(STDIN)) {
$line = trim($line);
if(preg_match("/^# Version ([0-9])+/", $line, $matches)) {
$v = $matches[1];
if(array_key_exists($v, $versions)) {
die("Version $v already exists, you cannot have two of the same version\n");
}
$versions[$v] = [];
} else {
$versions[$v][] = $line;
}
}
print_r($versions);
$max = max(array_keys($versions));
print("Current version: $current_version\n");
print_r("Max version : $max\n");
if($current_version == $max) {
die("You're up to date on version $current_version");
}
if($current_version > $max) {
die("You have a new version than provided by the sql file");
}
foreach($versions as $version => $rows) {
if($version > $current_version) {
print("I should run $version\n");
}
}
|