Skip to content

Commit 58154b9

Browse files
fix: fix test_generate_2_single_table_backup_all_table_data test when creating second table
1 parent 5e69cdc commit 58154b9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/BackupTablesService.php

-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ protected function processBackup(array $tablesToBackup = [])
8484
throw new \Exception('NOT SUPPORTED DATABASE DRIVER');
8585
}
8686
Schema::enableForeignKeyConstraints();
87-
8887
}
8988

9089
return [
@@ -147,9 +146,7 @@ protected function backupTablesForForPostgres($newTableName, $table)
147146

148147
protected function backupTablesForForSqlServer($newTableName, $table)
149148
{
150-
Schema::disableForeignKeyConstraints();
151149
DB::statement(/**@lang TSQL*/"SELECT * INTO $newTableName FROM $table");
152-
Schema::enableForeignKeyConstraints();
153150

154151
$newCreatedTables[] = $newTableName;
155152
$response[] = " Table '$table' cloned successfully.";

tests/BackupTablesTest.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ public function test_generate_2_single_table_backup_all_table_data()
9595
BackupTables::backupTables($tableName);
9696

9797
$newTableName = $tableName.'_backup_'.now()->format('Y_m_d_H_i_s');
98+
$newTableName2 = $tableName2 . '_backup_' . now()->format('Y_m_d_H_i_s');
9899

99100
$this->assertTrue(Schema::hasTable($newTableName));
100101

101-
if (DB::getDriverName() == 'mysql') { // todo debugging
102-
dump(Father::first()->first_name);
103-
}
102+
103+
//if (DB::getDriverName() == 'mysql') { // todo debugging
104+
// dump(Father::first()->first_name);
105+
//}
104106

105107
$this->assertEquals(DB::table($tableName)->value('first_name'), DB::table($newTableName)->value('first_name'));
106108
$this->assertEquals(DB::table($tableName)->value('email'), DB::table($newTableName)->value('email'));
@@ -110,7 +112,10 @@ public function test_generate_2_single_table_backup_all_table_data()
110112
//$this->assertEquals(DB::table($tableName)->value('status'), DB::table($newTableName)->value('status')); // virtualAs tables
111113
}
112114

113-
$this->assertEquals(DB::table($tableName2)->value('father_id'), DB::table($tableName2)->value('father_id')); // foreign key
115+
BackupTables::backupTables($tableName2);
116+
$this->assertTrue(Schema::hasTable($newTableName2));
117+
118+
$this->assertEquals(DB::table($tableName2)->value('father_id'), DB::table($newTableName2)->value('father_id')); // foreign key
114119

115120
}
116121

0 commit comments

Comments
 (0)