Prechádzať zdrojové kódy

improve stability and fix bugs

phpdevcommunity 1 mesiac pred
rodič
commit
666d09f454

+ 2 - 2
README.md

@@ -21,7 +21,7 @@ PaperORM is available via **Composer** and installs in seconds.
 
 ### 📦 Via Composer (recommended)
 ```bash
-composer require phpdevcommunity/paper-orm:1.0.3-alpha
+composer require phpdevcommunity/paper-orm:1.0.6-alpha
 ```  
 
 ### 🔧 Minimal Configuration
@@ -245,7 +245,7 @@ PaperORM est disponible via **Composer** et s'installe en quelques secondes.
 
 ### 📦 Via Composer (recommandé)
 ```bash
-composer require phpdevcommunity/paper-orm:1.0.3-alpha
+composer require phpdevcommunity/paper-orm:1.0.6-alpha
 ```  
 
 ### 🔧 Configuration minimale

+ 2 - 2
src/Command/DatabaseCreateCommand.php

@@ -26,13 +26,13 @@ class DatabaseCreateCommand implements CommandInterface
 
     public function getDescription(): string
     {
-        return 'Create a new SQL database';
+        return 'Creates the database configured for PaperORM';
     }
 
     public function getOptions(): array
     {
         return [
-            new CommandOption('if-not-exists', null, 'Create the SQL database only if it does not already exist', true)
+            new CommandOption('if-not-exists', null, 'Only create the database if it does not already exist', true)
         ];
     }
 

+ 1 - 1
src/Command/DatabaseDropCommand.php

@@ -63,6 +63,6 @@ class DatabaseDropCommand implements CommandInterface
 
     private function isEnabled(): bool
     {
-        return 'dev' === $this->env;
+        return 'dev' === $this->env || 'test' === $this->env;
     }
 }

+ 3 - 3
src/Debugger/SqlDebugger.php

@@ -24,7 +24,7 @@ class SqlDebugger
             'query' => sprintf('[%s] %s', strtok($query, " "), $query),
             'params' => $params,
             'startTime' => microtime(true),
-            'executionTime' => 0
+            'executionTime' => 0,
         ];
     }
 
@@ -35,9 +35,9 @@ class SqlDebugger
         }
 
         $start = $this->queries[$this->currentQuery]['startTime'];
-        $this->queries[$this->currentQuery]['executionTime'] = microtime(true) - $start;
+        $this->queries[$this->currentQuery]['executionTime'] = round(microtime(true) - $start, 3);
         if ($this->logger !== null) {
-            $this->logger->debug($this->queries[$this->currentQuery]);
+            $this->logger->debug(json_encode($this->queries[$this->currentQuery]));
         }
     }
 

+ 10 - 3
src/Migration/PaperMigration.php

@@ -179,21 +179,28 @@ SQL;
     public function down(string $version): void
     {
         $migration = $this->directory->getMigration($version);
+        $txDdl = $this->platform->supportsTransactionalDDL();
         $conn = $this->getConnection();
         $pdo = $conn->getPdo();
         $currentQuery = '';
         try {
-            $pdo->beginTransaction();
+            if ($txDdl && !$pdo->inTransaction()) {
+                $pdo->beginTransaction();
+            }
             foreach (explode(';' . PHP_EOL, self::contentDown($migration)) as $query) {
                 $currentQuery = $query;
                 $this->executeQuery($query);
             }
             $conn->executeStatement('DELETE FROM ' . $this->tableName . ' WHERE version = :version', ['version' => $version]);
 
-            $pdo->commit();
+            if ($pdo->inTransaction()) {
+                $pdo->commit();
+            }
 
         } catch (PDOException $e) {
-            $pdo->rollBack();
+            if ($pdo->inTransaction()) {
+                $pdo->rollBack();
+            }
             throw new RuntimeException(sprintf('Failed to migrate version %s : %s -> %s', $version, $e->getMessage(), $currentQuery));
         }