Neos\Flow\Persistence\Doctrine\Service::createSchema PHP Метод

createSchema() публичный Метод

Creates the needed DB schema using Doctrine's SchemaTool. If tables already exist, this will throw an exception.
public createSchema ( string $outputPathAndFilename = null ) : string
$outputPathAndFilename string A file to write SQL to, instead of executing it
Результат string
    public function createSchema($outputPathAndFilename = null)
    {
        $schemaTool = new SchemaTool($this->entityManager);
        $allMetaData = $this->entityManager->getMetadataFactory()->getAllMetadata();
        if ($outputPathAndFilename === null) {
            $schemaTool->createSchema($allMetaData);
        } else {
            $createSchemaSqlStatements = $schemaTool->getCreateSchemaSql($allMetaData);
            file_put_contents($outputPathAndFilename, implode(PHP_EOL, $createSchemaSqlStatements));
        }
    }

Usage Example

Пример #1
0
 /**
  * Create the database schema
  *
  * Creates a new database schema based on the current mapping information.
  *
  * It expects the database to be empty, if tables that are to be created already
  * exist, this will lead to errors.
  *
  * @param string $output A file to write SQL to, instead of executing it
  * @return void
  * @see neos.flow:doctrine:update
  * @see neos.flow:doctrine:migrate
  */
 public function createCommand($output = null)
 {
     if (!$this->isDatabaseConfigured()) {
         $this->outputLine('Database schema creation has been SKIPPED, the driver and host backend options are not set in /Configuration/Settings.yaml.');
         $this->quit(1);
     }
     $this->doctrineService->createSchema($output);
     if ($output === null) {
         $this->outputLine('Created database schema.');
     } else {
         $this->outputLine('Wrote schema creation SQL to file "' . $output . '".');
     }
 }