dropTable() public method

Builds and executes a SQL statement for dropping a DB table.
public dropTable ( string $table )
$table string the table to be dropped. The name will be properly quoted by the method.
 public function dropTable()
 {
     if ($this->dropOriginTable) {
         if (in_array($this->tableNameRaw, $this->_connection->schema->tableNames)) {
             $schema = $this->_connection->schema->getTableSchema($this->tableNameRaw);
             if ($schema) {
                 $keys = $schema->foreignKeys;
                 if (is_array($keys)) {
                     foreach ($keys as $name => $_next) {
                         $t = [];
                         foreach ($_next as $k => $v) {
                             if (!$k) {
                                 $t['related_table'] = $v;
                             } else {
                                 $t['related_field'] = $v;
                                 $t['field'] = $k;
                             }
                         }
                         try {
                             $keyName = $this->getNameForeignKey($this->tableNameRaw, $t['related_table'], $_next[$t['field']], $t['related_field'], 255);
                             if ($this->hideMigrationOutput) {
                                 ob_start();
                             }
                             $this->migrationClass->dropForeignKey($keyName, $this->tableNameRaw);
                             if ($this->hideMigrationOutput) {
                                 ob_clean();
                                 ob_flush();
                             }
                         } catch (\yii\db\Exception $exp) {
                         }
                     }
                 }
                 if ($this->hideMigrationOutput) {
                     ob_start();
                 }
                 try {
                     $this->migrationClass->dropTable($this->tableNameRaw);
                 } catch (\yii\db\Exception $exp) {
                 } catch (IntegrityException $exp) {
                 }
                 if ($this->hideMigrationOutput) {
                     ob_clean();
                     ob_flush();
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function afterDelete()
 {
     parent::afterDelete();
     $migrate = new Migration();
     $table = self::getTable($this->tab_index, $this->tab);
     $migrate->dropTable($table);
     //return true;
 }
Example #3
0
 /**
  * @inheritdoc
  * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
  */
 public function dropTable($table)
 {
     $table = $this->autoWrappedTableName($table);
     return parent::dropTable($table);
 }
Example #4
0
 /**
  * @param Migration $migration
  * @param string $tableName
  */
 public static function migrateDown($migration, $tableName = '{{%files}}')
 {
     $migration->dropTable($tableName);
 }