Exemplo n.º 1
0
 /**
  * @param SqlFile $file
  * @throws MigrationException
  */
 private function log(SqlFile $file, $success)
 {
     $statement = $this->pdo->prepare("insert into installed_migrations(installation_time, migration_file_name, migration_file_checksum, success) values(now(), ?, ?, ?)");
     try {
         $success = $statement->execute([$file->getFile()->getFilename(), $file->getHash(), $success === true ? "true" : "false"]);
         if ($success === false) {
             throw new MigrationException("Could not write to installed_migrations table: " . var_export($statement->errorInfo(), true));
         }
     } finally {
         $statement->closeCursor();
     }
 }
Exemplo n.º 2
0
 public function run(SqlFile $file)
 {
     $statement = $this->pdo->prepare($file->getContents());
     try {
         $result = $statement->execute();
         if ($result === false) {
             throw new \Exception("Query Returned " . var_export($this->pdo->errorInfo(), true));
         }
     } catch (\Exception $e) {
         throw new MigrationException("Running SQL File " . $file->getFile()->getPathname() . " failed.", $e);
     } finally {
         $statement->closeCursor();
     }
 }
Exemplo n.º 3
0
 private function validateChecksum(SqlFile $file, Migration $migration)
 {
     if ($file->getHash() !== $migration->getChecksum()) {
         throw new MigrationException("Migration " . $file->getFile()->getFilename() . " is already installed, but it's contents were modified afterwards. Checksum at installation time: " . $migration->getChecksum() . "; current checksum: " . $file->getHash());
     }
 }