private function ensureSchema($name, array $columns = [])
 {
     $schema = $this->connection->getSchemaManager()->createSchema();
     if (!$schema->hasTable($name)) {
         $schema->createTable($name);
     }
     $table = $schema->getTable($name);
     foreach ($columns as $property => $value) {
         if (!$table->hasColumn($property)) {
             $table->addColumn($property, $this->getType($value), ['notnull' => false]);
         }
     }
     $sync = new \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer($this->connection);
     $sync->updateSchema($schema, true);
 }
Beispiel #2
0
 public function modify($columns = array(), $indexes = array(), $dryrun = false)
 {
     $synchronizer = new \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer($this->conn);
     $schema = new \Doctrine\DBAL\Schema\Schema();
     $table = $schema->createTable($this->table);
     $primaryKey = '';
     foreach ($columns as $name => $options) {
         $type = $options['type'];
         unset($options['type']);
         if (isset($options['primaryKey'])) {
             if ($options['primaryKey']) {
                 if (!empty($primaryKey)) {
                     throw new \Exception(_("Multiple Primary Keys defined"));
                 }
                 $primaryKey = $name;
             }
             unset($options['primaryKey']);
         }
         $table->addColumn($name, $type, $options);
     }
     if (!empty($primaryKey)) {
         $table->setPrimaryKey(array($primaryKey));
     }
     foreach ($indexes as $name => $data) {
         $type = $data['type'];
         $columns = $data['cols'];
         switch ($type) {
             case "unique":
                 $table->addUniqueIndex($columns, $name);
                 break;
             case "index":
                 $table->addIndex($columns, $name);
                 break;
             case "fulltext":
                 if ($this->driver == "pdo_mysql" && version_compare($this->version, "5.6", "le")) {
                     $table->addOption('engine', 'MyISAM');
                 }
                 $table->addIndex($columns, $name, array("fulltext"));
                 break;
         }
     }
     //with true to prevent drops
     if ($dryrun) {
         return $synchronizer->getUpdateSchema($schema, true);
     } else {
         return $synchronizer->updateSchema($schema, true);
     }
 }
 /**
  * Create a state table, and move the db version value from a file to it.
  */
 protected function update_7()
 {
     $schema = $this->app['db']->getSchemaManager()->createSchema();
     $schema = clone $schema;
     $state = $schema->createTable('state');
     $state->addColumn('key', 'string', array('length' => 255));
     $state->addColumn('value', 'blob');
     $state->setPrimaryKey(array('key'));
     $synchronizer = new \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer($this->app['db']);
     $synchronizer->updateSchema($schema);
     $this->app['db']->insert('state', array($this->app['db']->quoteIdentifier('key') => 'InstallationVersion', $this->app['db']->quoteIdentifier('value') => 7));
     unlink($this->app['config.dir'] . '/InstallationVersion');
 }