summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2023-07-27 21:04:27 -0400
committerCalvin Morrison <calvin@pobox.com>2023-07-27 21:04:27 -0400
commit4e5e8bf507be75facfd1274b2288d137764e63bc (patch)
tree029a7435b47f35f6401db52e4223d35910cc5759
parent2c03461fd9f93d96bc2f0a9330c58815184cb1e5 (diff)
start working n the db side of detecting.
-rw-r--r--migrate.php32
1 files changed, 30 insertions, 2 deletions
diff --git a/migrate.php b/migrate.php
index 3120a75..0172330 100644
--- a/migrate.php
+++ b/migrate.php
@@ -1,18 +1,46 @@
<?php
+function abort() {
+ print("exiting\n");
+ exit;
+}
// get my current version.
-// this needs to come from the DB
+if(file_exists("./db.ini")) {
+ $config = parse_ini_file("./db.ini");
+} else {
+ die("No config file found\n");
+}
+
+if(!is_array($config)) {
+ die("Can't parse your db.ini!\n");
+}
+$con = mysqli_connect($config['server'], $config['user'], $config['password']);
-// group all ver
+// check if DB exists. Otherwise create.
$versions = [];
+$query = "show databases like '" . $config['database'] . "'";
+if($res = $con->query($query)) {
+ if($res->num_rows == 0) {
+ print("no database found\n");
+ if(readline("No database exists. Do want us to create it? (Y) ") != "Y") {
+ abort();
+ }
+ }
+}
+
+// connect to DB.
+$con->select_db($config['database']);
+
+// group all ver
$line = fgets(STDIN);
if(!preg_match("/^# Versioned Migration Script$/", $line)) {
die("Sorry, this doesn't look like a versioned file.\n");
}
+
// find current version.