src/Console/Controllers/MigrateController.php
protected function truncateDatabase()
    {
        $db = $this->db;
        return $db->getSchema()->getTableSchemas()->then(
            function($schemas) use (&$db) {
                /** @var TableSchema[] $schemas */
                $promises = [];
                // First drop all foreign keys,
                foreach ($schemas as $schema) {
                    if ($schema->foreignKeys) {
                        foreach ($schema->foreignKeys as $name => $foreignKey) {
                            $promises[] = $db->createCommand()->dropForeignKey($name, $schema->name)->execute(true)
                                ->thenLazy(function() use ($name) {
                                    $this->stdout("Foreign key $name dropped.\n");
                                    return true;
                                });
                        }
                    }
                }
                // Then drop the tables:
                foreach ($schemas as $schema) {
                    $promises[] = $db->createCommand()->dropTable($schema->name)->execute(true)
                        ->thenLazy(function() use ($schema) {
                            $this->stdout("Table {$schema->name} dropped.\n");
                            return true;
                        });
                }
                return allInOrder($promises);
            }
        );
    }
protected function truncateDatabase()
    {
        $db = $this->db;
        return $db->getSchema()->getTableSchemas()->then(
            function($schemas) use (&$db) {
                /** @var TableSchema[] $schemas */
                $promises = [];
                // First drop all foreign keys,
                foreach ($schemas as $schema) {
                    if ($schema->foreignKeys) {
                        foreach ($schema->foreignKeys as $name => $foreignKey) {
                            $promises[] = $db->createCommand()->dropForeignKey($name, $schema->name)->execute(true)
                                ->thenLazy(function() use ($name) {
                                    $this->stdout("Foreign key $name dropped.\n");
                                    return true;
                                });
                        }
                    }
                }
                // Then drop the tables:
                foreach ($schemas as $schema) {
                    $promises[] = $db->createCommand()->dropTable($schema->name)->execute(true)
                        ->thenLazy(function() use ($schema) {
                            $this->stdout("Table {$schema->name} dropped.\n");
                            return true;
                        });
                }
                return allInOrder($promises);
            }
        );
    }
{@inheritdoc}