Roman 3 éve
szülő
commit
186083a315

+ 28 - 0
cli.php

@@ -1,7 +1,9 @@
 <?php
 
 include_once 'core/core.php';
+include_once 'core/constants.php';
 
+use Configuration\DatabaseScript;
 use Driver\SQL\SQL;
 use Objects\ConnectionData;
 
@@ -44,7 +46,33 @@ function handleDatabase($argv) {
 
   switch ($action) {
     case 'migrate':
+      $class = $argv[3] ?? null;
+      if (!$class) {
+        die("Usage: cli.php db migrate <class name>\n");
+      }
+
+      $class = str_replace('/', '\\', $class);
+      $className = "\\Configuration\\$class";
+      $classPath = getClassPath($className);
+      if (!file_exists($classPath) || !is_readable($classPath)) {
+        die("Database script file does not exist or is not readable\n");
+      }
+
+      include_once $classPath;
+      $obj = new $className();
+      if (!($obj instanceof DatabaseScript)) {
+        die("Not a database script\n");
+      }
+
       $db = connectDatabase();
+      $queries = $obj->createQueries($db);
+      foreach ($queries as $query) {
+        if (!$query->execute($db)) {
+          die($db->getLastError());
+        }
+      }
+
+      $db->close();
       break;
     case 'export':
       $config = getDatabaseConfig();

+ 2 - 1
core/Configuration/CreateDatabase.class.php

@@ -126,7 +126,8 @@ class CreateDatabase extends DatabaseScript {
       ->addString("target", 128)
       ->addString("extra", 64, true)
       ->addBool("active", true)
-      ->primaryKey("uid");
+      ->primaryKey("uid")
+      ->unique("request");
 
     $queries[] = $sql->insert("Route", array("request", "action", "target", "extra"))
       ->addRow("^/admin(/.*)?$", "dynamic", "\\Documents\\Admin", NULL)

+ 0 - 2
core/Documents/Install.class.php

@@ -280,9 +280,7 @@ namespace Documents\Install {
             $success = false;
             $msg = "Unable to write file";
           }
-        }
 
-        if ($sql) {
           $sql->close();
         }
       }

+ 1 - 1
core/Driver/SQL/PostgreSQL.class.php

@@ -53,7 +53,7 @@ class PostgreSQL extends SQL {
       }
     }
 
-    $this->connection = @pg_connect(implode(" ", $connectionString));
+    $this->connection = @pg_connect(implode(" ", $connectionString), PGSQL_CONNECT_FORCE_NEW);
     if (!$this->connection) {
       $this->lastError = "Failed to connect to Database";
       $this->connection = NULL;