Skip to content

Commit f209742

Browse files
committed
Prefix fix #1
1 parent 7e4e29b commit f209742

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/Schema.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Schema
1111
{
1212
public $schema;
1313
public $name;
14+
public $table;
1415
public $writeIn;
1516
public $synced = false;
1617

@@ -23,12 +24,13 @@ public function __construct($schema, SyncMigrateCommand $writeIn)
2324
{
2425
$this->schema = $schema;
2526
$this->name = $this->getName($schema->group(1));
27+
$this->table = DB::getTablePrefix() . $this->name;
2628
$this->writeIn = $writeIn;
2729
}
2830

2931
public function process()
3032
{
31-
$action = DB::getSchemaBuilder()->hasTable($this->name) ? 'sync' : 'create';
33+
$action = $this->tabeExist() ? 'sync' : 'create';
3234

3335
$this->$action();
3436
}
@@ -42,14 +44,14 @@ public function output()
4244
protected function create()
4345
{
4446
if($this->columnsList()->isEmpty()) {
45-
return $this->output()->error("Table <fg=black;bg=white> {$this->name} </> does not have any columns");
47+
return $this->output()->error("Table <fg=black;bg=white> {$this->table} </> does not have any columns");
4648
}
4749

4850
LaravelSchema::create($this->name, function (Blueprint $table) {
4951
eval($this->schema->group(2));
5052
});
5153

52-
$this->output()->warn("New table <fg=white;bg=red> {$this->name} </> was created");
54+
$this->output()->warn("New table <fg=white;bg=red> {$this->table} </> was created");
5355
}
5456

5557
protected function sync()
@@ -59,7 +61,7 @@ protected function sync()
5961
}
6062

6163
$this->dbUnsyncedColumns()->each(function ($type, $column) {
62-
$this->output()->info("Column <fg=black;bg=yellow> {$this->name}->{$column} </> is renamed or deleted !!");
64+
$this->output()->info("Column <fg=black;bg=yellow> {$this->table}->{$column} </> is renamed or deleted !!");
6365
$action = $this->output()->choice('What we should do ?', $this->syncChoices(), 0);
6466

6567
(new Column($this))->$action($column);
@@ -72,8 +74,8 @@ protected function sync()
7274

7375
protected function dropSchema()
7476
{
75-
$this->output()->error("Table <fg=black;bg=yellow> {$this->name} </> does not have any columns");
76-
$this->output()->confirm("Do you want to drop <fg=white;bg=red> {$this->name} </> ?",
77+
$this->output()->error("Table <fg=black;bg=yellow> {$this->table} </> does not have any columns");
78+
$this->output()->confirm("Do you want to drop <fg=white;bg=red> {$this->table} </> ?",
7779
true) && LaravelSchema::dropIfExists($this->name);
7880
}
7981

@@ -114,7 +116,8 @@ protected function syncChoices()
114116

115117
protected function dbColumns()
116118
{
117-
return collect(DB::select('DESCRIBE ' . $this->name))->mapWithKeys(function ($column) {
119+
return collect(DB::select('DESCRIBE ' . $this->table))
120+
->mapWithKeys(function ($column) {
118121
return [$column->Field => $column->Type];
119122
});
120123
}
@@ -152,4 +155,9 @@ protected function columnsTypes($column)
152155
'morphs' => ["{$column}_id", "{$column}_type"],
153156
];
154157
}
158+
159+
protected function tabeExist()
160+
{
161+
return DB::getSchemaBuilder()->hasTable($this->name);
162+
}
155163
}

src/SyncMigrateCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ protected function getAllSchemas($content)
100100
*/
101101
protected function abondedTables()
102102
{
103-
return $this->tables()->diff($this->schemas->pluck('name')->push('migrations'));
103+
return $this->tables()->diff($this->schemasTables());
104+
}
105+
106+
protected function schemasTables()
107+
{
108+
return $this->schemas->pluck('name')->push('migrations')->map(function ($name) {
109+
return DB::getTablePrefix() . $name;
110+
});
104111
}
105112
}

0 commit comments

Comments
 (0)