diff options
author | Calvin Morrison <calvin@pobox.com> | 2023-03-20 09:39:13 -0400 |
---|---|---|
committer | Calvin Morrison <calvin@pobox.com> | 2023-03-20 09:39:13 -0400 |
commit | 2c03461fd9f93d96bc2f0a9330c58815184cb1e5 (patch) | |
tree | 95d8503dd47103626027190a87cb22e948d31704 | |
parent | 15439b9f00bebbe6bbcb9aab7ec8c04ee5665bf3 (diff) |
migrate
-rw-r--r-- | migrate.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/migrate.php b/migrate.php new file mode 100644 index 0000000..3120a75 --- /dev/null +++ b/migrate.php @@ -0,0 +1,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"); + } +} |