Skip to content

Commit 34e4e51

Browse files
update
1 parent 4dbae7d commit 34e4e51

File tree

7 files changed

+38
-58
lines changed

7 files changed

+38
-58
lines changed

src/Console/Commands/MigrationCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function fresh()
4040
$force = $this->option('force');
4141
$seed = $this->option('seed');
4242

43+
44+
4345
if($force){
4446
Artisan::call('db:wipe --force --drop-types --drop-views --response=0');
4547
}
@@ -69,10 +71,9 @@ public function refresh()
6971
*/
7072
public function reset()
7173
{
72-
// Require --force in production environments
7374
$this->forceChecker();
7475

75-
$force = (bool) $this->option('force');
76+
$force = $this->force();
7677

7778
$migration = new Migration();
7879
$response = $migration->drop($force);

src/Dummy/dummyJobsMigration.dum

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ return new class extends Migration
99
{
1010
/**
1111
* Run the migrations.
12-
*
13-
* @return mixed
1412
*/
15-
public function up()
13+
public function up(): void
1614
{
1715
Schema::create('{{TABLE}}', function (Blueprint $table) {
1816
$table->id();
@@ -27,16 +25,11 @@ return new class extends Migration
2725

2826
/**
2927
* Drop database table
30-
*
31-
* @param bool $force
32-
* [optional] Default is false
33-
* Force drop all tables or throw an error on Foreign keys
34-
*
35-
* @return mixed
28+
* @param bool $force
3629
*/
37-
public function drop($force = false)
30+
public function drop($force = false): void
3831
{
39-
return Schema::dropTable('{{TABLE}}', $force);
32+
Schema::dropTable('{{TABLE}}', $force);
4033
}
4134

4235
};

src/Dummy/dummyMigration.dum

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ return new class extends Migration
99
{
1010
/**
1111
* Run the migrations.
12-
*
13-
* @return mixed
1412
*/
15-
public function up()
13+
public function up(): void
1614
{
1715
Schema::create('{{TABLE}}', function (Blueprint $table) {
1816
$table->id();
@@ -22,16 +20,11 @@ return new class extends Migration
2220

2321
/**
2422
* Drop database table
25-
*
26-
* @param bool $force
27-
* [optional] Default is false
28-
* Force drop all tables or throw an error on Foreign keys
29-
*
30-
* @return mixed
23+
* @param bool $force
3124
*/
32-
public function drop($force = false)
25+
public function drop($force = false): void
3326
{
34-
return Schema::dropTable('{{TABLE}}', $force);
27+
Schema::dropTable('{{TABLE}}', $force);
3528
}
3629

3730
};

src/Dummy/dummyScheme.dum

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
11-
*
12-
* @return mixed
1311
*/
14-
public function up()
12+
public function up(): void
1513
{
1614
Schema::create('{{TABLE}}', function (Blueprint $table) {
1715
{{BODY}}
@@ -20,12 +18,10 @@ return new class extends Migration
2018

2119
/**
2220
* Drop database table
23-
*
24-
* @param bool $force [optional] Default is false
25-
* @return mixed
21+
* @param bool $force
2622
*/
27-
public function drop($force = false)
23+
public function drop($force = false): void
2824
{
29-
return Schema::dropTable('{{TABLE}}', $force);
25+
Schema::dropTable('{{TABLE}}', $force);
3026
}
3127
};

src/Dummy/dummySchemeLaravel.dum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
11-
*
12-
* @return void
1311
*/
14-
public function up()
12+
public function up(): void
1513
{
1614
Schema::create('{{TABLE}}', function (Blueprint $table) {
1715
{{BODY}}
@@ -20,10 +18,8 @@ return new class extends Migration
2018

2119
/**
2220
* Reverse the migrations.
23-
*
24-
* @return void
2521
*/
26-
public function drop($force = false)
22+
public function drop(): void
2723
{
2824
Schema::dropIfExists('{{TABLE}}');
2925
}

src/Dummy/dummySessionsMigration.dum

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ return new class extends Migration
99
{
1010
/**
1111
* Run the migrations.
12-
*
13-
* @return mixed
1412
*/
15-
public function up()
13+
public function up(): void
1614
{
1715
Schema::create('{{TABLE}}', function (Blueprint $table) {
1816
$table->id();
@@ -29,16 +27,11 @@ return new class extends Migration
2927

3028
/**
3129
* Drop database table
32-
*
33-
* @param bool $force
34-
* [optional] Default is false
35-
* Force drop all tables or throw an error on Foreign keys
36-
*
37-
* @return mixed
30+
* @param bool $force
3831
*/
39-
public function drop($force = false)
32+
public function drop($force = false): void
4033
{
41-
return Schema::dropTable('{{TABLE}}', $force);
34+
Schema::dropTable('{{TABLE}}', $force);
4235
}
4336

4437
};

src/Migrations/Schema.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ public static function create($tableName, callable $callback)
9292
{
9393
$blueprint = new Blueprint($tableName);
9494
$callback($blueprint);
95+
9596
$result = $blueprint->handleBlueprint();
9697
self::$lastResult = $result;
98+
9799
return $result;
98100
}
99101

@@ -191,11 +193,17 @@ public static function dropTable($tableName, $force = false)
191193

192194
// Handle query
193195
try{
194-
// DROP TABLE IF EXISTS
196+
195197
if($force){
196-
self::$pdo->exec("SET FOREIGN_KEY_CHECKS = 0; "); // Disable foreign key checks temporarily
197-
self::$pdo->exec("DROP TABLE {$tableName} CASCADE;"); // Drop the table with CASCADE option
198-
self::$pdo->exec("SET FOREIGN_KEY_CHECKS = 1;"); // Enable foreign key checks again
198+
// Disable foreign key checks temporarily
199+
self::$pdo->exec("SET FOREIGN_KEY_CHECKS = 0; ");
200+
201+
if(self::$db->tableExists($tableName)){
202+
// Drop the table with CASCADE option
203+
self::$pdo->exec("DROP TABLE {$tableName} CASCADE;");
204+
}
205+
// Enable foreign key checks again
206+
self::$pdo->exec("SET FOREIGN_KEY_CHECKS = 1;");
199207
} else{
200208
self::$pdo->query( "DROP TABLE {$tableName};" )->execute();
201209
}
@@ -227,11 +235,11 @@ public static function dropColumn($tableName, $columnName)
227235
{
228236
self::initSchemaDatabase();
229237

230-
// handle error
231-
$handle = self::checkDBConnect();
232-
if(is_array($handle)){
233-
return $handle;
234-
}
238+
$conn = self::checkDBConnect();
239+
if($conn['status'] != Constant::STATUS_200){
240+
self::$lastResult = $conn;
241+
return $conn;
242+
}
235243

236244
// if empty
237245
if(empty($columnName)){

0 commit comments

Comments
 (0)