public function install()
 {
     $messageSchema = $this->messagesSchemaProvider->getSchemaFor($this->messagesTableName);
     $endpointSchema = $this->endpointSchemaProvider->getSchemaFor($this->endpointsTableName);
     // is there a better way to atomically create in order to not compete with other endpoints?
     try {
         $this->databaseSynchronizer->createSchema($messageSchema);
     } catch (TableExistsException $e) {
     }
     try {
         $this->databaseSynchronizer->createSchema($endpointSchema);
     } catch (TableExistsException $e) {
     }
 }
 /**
  * Execute setup tasks.
  */
 public function onSetup()
 {
     $connection = $this->getConnection();
     $synchronizer = new SingleDatabaseSynchronizer($connection);
     $schema = $this->getSchema();
     $synchronizer->dropSchema($schema);
     $synchronizer->createSchema($schema);
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     // make sure schemas exists
     $sm = $this->sc->getSchemaManager();
     $this->validateSchema($this->getConfig('source'));
     echo "Creating target schema\n";
     // create schema if it doesn't exist
     if (($db = $this->getOptionalConfig('target.dbname')) !== null && $this->validateSchema($this->getConfig('target'), false) == false) {
         // get schema-less connection
         $_config = $this->getConfig('target');
         unset($_config['dbname']);
         $conn = \Doctrine\DBAL\DriverManager::getConnection($_config);
         $tm = $conn->getSchemaManager();
         echo "Creating database\n";
         $tm->createDatabase($db);
     }
     try {
         $schema = $sm->createSchema();
         echo "Creating tables\n";
         // sync configured tables only
         if ($tables = $this->getOptionalConfig('tables')) {
             // extract target table names
             $tables = array_column($tables, 'name');
             foreach ($schema->getTables() as $table) {
                 if (!in_array($table->getName(), $tables)) {
                     $schema->dropTable($table->getName());
                 }
             }
         }
         // make sure schema is free of conflicts for target platform
         if (in_array($platform = $this->tc->getDatabasePlatform()->getName(), array('sqlite'))) {
             $this->updateSchemaForTargetPlatform($schema, $platform);
         }
         $synchronizer = new SingleDatabaseSynchronizer($this->tc);
         $synchronizer->createSchema($schema);
     } catch (\Exception $e) {
         $sql = $schema->toSql($this->tc->getDatabasePlatform());
         echo join($sql, "\n");
         throw $e;
     }
 }