fix database
This commit is contained in:
+17
-8
@@ -10,15 +10,24 @@ return new class extends Migration
|
|||||||
$serverId = $this->resolveCanonicalServerId();
|
$serverId = $this->resolveCanonicalServerId();
|
||||||
|
|
||||||
if ($serverId === null) {
|
if ($serverId === null) {
|
||||||
throw new RuntimeException('Không tìm thấy dns_manager_servers để sync foreign key.');
|
$hasOrphaned = DB::table('dns_manager_domain as d')
|
||||||
}
|
->leftJoin('dns_manager_servers as s', 's.id', '=', 'd.dns_manager_server_id')
|
||||||
|
->where(function ($q) {
|
||||||
|
$q->where('d.dns_manager_server_id', 0)->orWhereNull('s.id');
|
||||||
|
})
|
||||||
|
->exists();
|
||||||
|
|
||||||
DB::statement("
|
if ($hasOrphaned) {
|
||||||
UPDATE dns_manager_domain d
|
throw new RuntimeException('Không tìm thấy dns_manager_servers để sync foreign key cho các bản ghi orphaned.');
|
||||||
LEFT JOIN dns_manager_servers s ON s.id = d.dns_manager_server_id
|
}
|
||||||
SET d.dns_manager_server_id = {$serverId}
|
} else {
|
||||||
WHERE d.dns_manager_server_id = 0 OR s.id IS NULL
|
DB::statement("
|
||||||
");
|
UPDATE dns_manager_domain d
|
||||||
|
LEFT JOIN dns_manager_servers s ON s.id = d.dns_manager_server_id
|
||||||
|
SET d.dns_manager_server_id = {$serverId}
|
||||||
|
WHERE d.dns_manager_server_id = 0 OR s.id IS NULL
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
DB::statement('ALTER TABLE dns_manager_domain MODIFY dns_manager_server_id BIGINT UNSIGNED NOT NULL');
|
DB::statement('ALTER TABLE dns_manager_domain MODIFY dns_manager_server_id BIGINT UNSIGNED NOT NULL');
|
||||||
DB::statement('ALTER TABLE dns_manager_ns MODIFY dns_manager_domain_id BIGINT UNSIGNED NOT NULL');
|
DB::statement('ALTER TABLE dns_manager_ns MODIFY dns_manager_domain_id BIGINT UNSIGNED NOT NULL');
|
||||||
|
|||||||
Reference in New Issue
Block a user