@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $this->processMigration(file_get_contents($file)); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $this->abondedTables()->each(function ($table) { |
|
| 62 | + $this->abondedTables()->each(function($table) { |
|
| 63 | 63 | $this->error("Schemas doesn't have table <fg=black;bg=white> {$table} </> seems you have delete it"); |
| 64 | 64 | |
| 65 | 65 | $this->confirm("Do you want to drop <fg=black;bg=white> {$table} </> ?", |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | protected function tables() |
| 77 | 77 | { |
| 78 | - return Collection::make(DB::select('SHOW TABLES'))->map(function ($table) { |
|
| 78 | + return Collection::make(DB::select('SHOW TABLES'))->map(function($table) { |
|
| 79 | 79 | return array_values((array)$table); |
| 80 | 80 | })->flatten(); |
| 81 | 81 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | protected function schemasTables() |
| 108 | 108 | { |
| 109 | - return $this->schemas->pluck('name')->push('migrations')->map(function ($name) { |
|
| 109 | + return $this->schemas->pluck('name')->push('migrations')->map(function($name) { |
|
| 110 | 110 | return DB::getTablePrefix() . $name; |
| 111 | 111 | }); |
| 112 | 112 | } |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | protected function create() |
| 48 | 48 | { |
| 49 | - if($this->columnsList()->isEmpty()) { |
|
| 49 | + if ($this->columnsList()->isEmpty()) { |
|
| 50 | 50 | return $this->output()->error("Table <fg=black;bg=white> {$this->table} </> does not have any columns"); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - LaravelSchema::create($this->name, function (Blueprint $table) { |
|
| 53 | + LaravelSchema::create($this->name, function(Blueprint $table) { |
|
| 54 | 54 | eval($this->schema->group(2)); |
| 55 | 55 | }); |
| 56 | 56 | |
@@ -59,18 +59,18 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | protected function sync() |
| 61 | 61 | { |
| 62 | - if($this->schemaEmpty()) { |
|
| 62 | + if ($this->schemaEmpty()) { |
|
| 63 | 63 | return $this->dropSchema(); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - $this->dbUnsyncedColumns()->each(function ($type, $column) { |
|
| 66 | + $this->dbUnsyncedColumns()->each(function($type, $column) { |
|
| 67 | 67 | $this->output()->info("Column <fg=black;bg=yellow> {$this->table}->{$column} </> is renamed or deleted !!"); |
| 68 | 68 | $action = $this->output()->choice('What we should do ?', $this->syncChoices(), 0); |
| 69 | 69 | |
| 70 | 70 | (new Column($this))->$action($column); |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | - $this->schemaUnsyncedColumns()->each(function ($column, $line) { |
|
| 73 | + $this->schemaUnsyncedColumns()->each(function($column, $line) { |
|
| 74 | 74 | (new Column($this))->create($line, $column); |
| 75 | 75 | }); |
| 76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | protected function getName($name) |
| 91 | 91 | { |
| 92 | 92 | //TODO: https://github.com/awssat/laravel-sync-migration/issues/2 |
| 93 | - if(preg_match('/[\'|"]\s?\.\s?\$/', $name) || preg_match('/\$[a-zA-z0-9-_]+\s?\.\s?[\'|"]/', $name)) { |
|
| 93 | + if (preg_match('/[\'|"]\s?\.\s?\$/', $name) || preg_match('/\$[a-zA-z0-9-_]+\s?\.\s?[\'|"]/', $name)) { |
|
| 94 | 94 | $this->output()->error("Using variables as table names (<fg=black;bg=white> {$name} </>) is not supported currentlly, see <href=https://github.com/awssat/laravel-sync-migration/issues/2> issue#2 </>"); |
| 95 | 95 | exit; |
| 96 | 96 | } |
@@ -105,38 +105,37 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | protected function dbUnsyncedColumns() |
| 107 | 107 | { |
| 108 | - return $this->dbColumns()->reject(function ($type, $column) { |
|
| 108 | + return $this->dbColumns()->reject(function($type, $column) { |
|
| 109 | 109 | return $this->columnsList()->values()->flatten()->contains($column); |
| 110 | 110 | }); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | protected function schemaUnsyncedColumns() |
| 114 | 114 | { |
| 115 | - return $this->columnsList()->reject(function ($column) { |
|
| 115 | + return $this->columnsList()->reject(function($column) { |
|
| 116 | 116 | return $this->dbColumns()->has($column); |
| 117 | 117 | }); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | protected function syncChoices() |
| 121 | 121 | { |
| 122 | - return $this->schemaUnsyncedColumns()->isEmpty() ? ['Delete', 'Ignore'] : |
|
| 123 | - ['Delete', 'Rename', 'Ignore']; |
|
| 122 | + return $this->schemaUnsyncedColumns()->isEmpty() ? ['Delete', 'Ignore'] : ['Delete', 'Rename', 'Ignore']; |
|
| 124 | 123 | } |
| 125 | 124 | |
| 126 | 125 | protected function dbColumns() |
| 127 | 126 | { |
| 128 | 127 | return Collection::make(DB::select('DESCRIBE ' . $this->table)) |
| 129 | - ->mapWithKeys(function ($column) { |
|
| 128 | + ->mapWithKeys(function($column) { |
|
| 130 | 129 | return [$column->Field => $column->Type]; |
| 131 | 130 | }); |
| 132 | 131 | } |
| 133 | 132 | |
| 134 | 133 | protected function columnsList() |
| 135 | 134 | { |
| 136 | - return Collection::make(explode(';', $this->schema->group(2)))->mapWithKeys(function ($line) { |
|
| 135 | + return Collection::make(explode(';', $this->schema->group(2)))->mapWithKeys(function($line) { |
|
| 137 | 136 | $line = trim($line); |
| 138 | 137 | |
| 139 | - if(Str::startsWith($line, ['//', '#', '/*'])) { |
|
| 138 | + if (Str::startsWith($line, ['//', '#', '/*'])) { |
|
| 140 | 139 | return []; |
| 141 | 140 | } |
| 142 | 141 | |