Commit 8cf85d8b authored by abkrim's avatar abkrim 😀
Browse files

Update some fixes

parent 3d510dff
Pipeline #262 failed with stages
in 52 seconds
<?php
namespace Abkrim\DbSchema\Classes;
class Schema
{
public static function reOrderSchema($schema)
{
usort($schema, function ( $a, $b) {
return $a['name'] <=> $b['name'];
});
return $schema;
}
}
......@@ -65,12 +65,14 @@ class DoctrineListSchema extends Command
private function getSchemaTable(string $table)
{
$table_schemas = array();
$schema_indexes = array();
$schema_columns = array();
$sm = Schema::connection($this->connection)->getConnection()->getDoctrineSchemaManager();
$indexes = $sm->listTableIndexes($table);
foreach ($indexes as $index) {
$table_schemas['indexes'][] = [
$schema_indexes[] = [
'name' => $index->getName(),
'unique' => $index->isUnique(),
'columns' => implode(',', $index->getColumns())
......@@ -80,7 +82,7 @@ class DoctrineListSchema extends Command
// Now get columns
$columns = $sm->listTableColumns($table);
foreach ($columns as $column) {
$table_schemas['columns'][] = [
$schema_columns[] = [
'name' => $column->getName(),
'type' => str_replace("Doctrine\DBAL\Types\\", "", $column->getType()),
'length' => $column->getLength(),
......@@ -93,11 +95,24 @@ class DoctrineListSchema extends Command
];
}
usort($schema_indexes, function ($a, $b) {
return $a['name'] <=> $b['name'];
});
usort($schema_columns, function ($a, $b) {
return $a['name'] <=> $b['name'];
});
$table_schemas = [
'indexes' => $schema_indexes,
'columns' => $schema_columns
];
if ($this->option('s') == true) {
if (! is_null($this->option('e'))) {
$this->saveSchema($table, $table_schemas);
} else {
$this->warn('If use otpion "s" you must use option "-e" with version for save');
$this->warn('If use option "s" you must use option "-e" with version for save');
}
} else {
$this->showSchema($table, $table_schemas);
......
<?php
namespace Abkrim\DbSchema\Tests;
use Abkrim\DbSchema\Classes\Schema;
use Faker\Factory as Faker;
use Orchestra\Testbench\TestCase;
class SchemaTest extends TestCase
{
/** @test */
function it_order_array_schema()
{
// Given
$array = [
[
'name' => 'b',
'other' => 1
],
[
'name' => 'a',
'other' => 2
],
[
'name' => 'c',
'other' => 3
],
];
// When
$array = Schema::reOrderSchema($array);
$this->assertEquals('a',$array[0]['name']);
// Then
// Should
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment