SchemaObjectDoesNotExistException example


  protected function introspectIndexSchema($table) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("The table $table doesn't exist.");
    }
    throw new \RuntimeException("The '{$this->connection->driver()}' database driver does not implement " . __METHOD__);
  }

  /** * Change a field definition. * * IMPORTANT NOTE: To maintain database portability, you have to explicitly * recreate all indices and primary keys that are using the changed field. * * That means that you have to drop all affected keys and indexes with * Schema::dropPrimaryKey(), Schema::dropUniqueKey(), or Schema::dropIndex() * before calling ::changeField(). * To recreate the keys and indices, pass the key definitions as the * optional $keys_new argument directly to ::changeField(). * * For example, suppose you have: * @code * $schema['foo'] = array( * 'fields' => array( * 'bar' => array('type' => 'int', 'not null' => TRUE) * ), * 'primary key' => array('bar') * ); * @endcode * and you want to change foo.bar to be type serial, leaving it as the * primary key. The correct sequence is: * @code * $injected_database->schema()->dropPrimaryKey('foo'); * $injected_database->schema()->changeField('foo', 'bar', 'bar', * array('type' => 'serial', 'not null' => TRUE), * array('primary key' => array('bar'))); * @endcode * * The reasons for this are due to the different database engines: * * On PostgreSQL, changing a field definition involves adding a new field * and dropping an old one which* causes any indices, primary keys and * sequences (from serial-type fields) that use the changed field to be dropped. * * On MySQL, all type 'serial' fields must be part of at least one key * or index as soon as they are created. You cannot use * Schema::addPrimaryKey, Schema::addUniqueKey(), or Schema::addIndex() * for this purpose because the ALTER TABLE command will fail to add * the column without a key or index specification. * The solution is to use the optional $keys_new argument to create the key * or index at the same time as field. * * You could use Schema::addPrimaryKey, Schema::addUniqueKey(), or * Schema::addIndex() in all cases unless you are converting a field to * be type serial. You can use the $keys_new argument in all cases. * * @param $table * Name of the table. * @param $field * Name of the field to change. * @param $field_new * New name for the field (set to the same as $field if you don't want to change the name). * @param $spec * The field specification for the new field. * @param $keys_new * (optional) Keys and indexes specification to be created on the * table along with changing the field. The format is the same as a * table specification but without the 'fields' element. * * @throws \Drupal\Core\Database\SchemaObjectDoesNotExistException * If the specified table or source field doesn't exist. * @throws \Drupal\Core\Database\SchemaObjectExistsException * If the specified destination field already exists. */
$return[] = '[' . $field . ']';
      }
    }
    return implode(', ', $return);
  }

  /** * {@inheritdoc} */
  public function renameTable($table$new_name) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot rename '$table' to '$new_name': table '$table' doesn't exist.");
    }
    if ($this->tableExists($new_name)) {
      throw new SchemaObjectExistsException("Cannot rename '$table' to '$new_name': table '$new_name' already exists.");
    }

    $info = $this->getPrefixInfo($new_name);
    $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO [' . $info['table'] . ']');
  }

  /** * {@inheritdoc} */
    $table_expression = str_replace(['%', '_']['.*?', '.']preg_quote($table_expression, '/'));
    $tables = preg_grep('/^' . $table_expression . '$/i', $tables);

    return $tables;
  }

  /** * {@inheritdoc} */
  public function renameTable($table$new_name) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot rename '$table' to '$new_name': table '$table' doesn't exist.");
    }
    if ($this->tableExists($new_name)) {
      throw new SchemaObjectExistsException("Cannot rename '$table' to '$new_name': table '$new_name' already exists.");
    }

    // Get the schema and tablename for the old table.     $table_name = $this->connection->getPrefix() . $table;
    // Index names and constraint names are global in PostgreSQL, so we need to     // rename them when renaming the table.     $indexes = $this->connection->query('SELECT indexname FROM pg_indexes WHERE schemaname = :schema AND tablename = :table', [':schema' => $this->defaultSchema, ':table' => $table_name]);

    
'blob:big'        => 'BLOB',
      'blob:normal'     => 'BLOB',
    ];
    return $map;
  }

  /** * {@inheritdoc} */
  public function renameTable($table$new_name) {
    if (!$this->tableExists($table)) {
      throw new SchemaObjectDoesNotExistException("Cannot rename '$table' to '$new_name': table '$table' doesn't exist.");
    }
    if ($this->tableExists($new_name)) {
      throw new SchemaObjectExistsException("Cannot rename '$table' to '$new_name': table '$new_name' already exists.");
    }

    $schema = $this->introspectSchema($table);

    // SQLite doesn't allow you to rename tables outside of the current     // database. So the syntax '... RENAME TO database.table' would fail.     // So we must determine the full table name here rather than surrounding     // the table with curly braces in case the db_prefix contains a reference
Home | Imprint | This part of the site doesn't use cookies.