KTVCentral/app/Console/Commands/TransferSqliteToMysql.php
allen.yan 7c8c3fe69b DB 滙入
User 介面 只能看資料不能做修改
Role 介面移除
Branch介面 只能看資料不能做修改
Room 介面 可操控 包廂開關台
Sqgger API 可操控API
Room 有操控異動記錄
machine_statuses 需做資料留存需留7 天
20250528
2025-05-28 09:24:03 +08:00

50 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use App\Jobs\TransferSqliteTableJob;
class TransferSqliteToMysql extends Command
{
protected $signature = 'transfer:sqlite
{path : SQLite 相對路徑sqlite/song.sqlite}
{--sync : 同步執行}';
protected $description = '將 SQLite 中的資料表轉移到 MySQL 資料庫中';
public function handle(): int
{
$start = now();
$path = ltrim($this->argument('path'), '/');
$fullPath = Storage::disk('local')->path($path);
$this->info("[Transfer] 開始轉移 SQLite 資料:{$fullPath}");
if (!file_exists($fullPath)) {
$this->error("[Transfer] 找不到 SQLite 檔案:{$fullPath}");
return 1;
}
try {
if ($this->option('sync')) {
$this->warn('[Transfer] 使用同步模式執行...');
(new TransferSqliteTableJob($fullPath))->handle();
$this->info('[Transfer] 匯出完成(同步)');
} else {
TransferSqliteTableJob::dispatch($fullPath);
$this->info('[Transfer] 匯出任務已派送至 queue');
}
$duration = now()->diffInSeconds($start);
$this->info("[Transfer] 執行完成,用時 {$duration}");
} catch (\Throwable $e) {
$this->error('[Transfer] 發生錯誤:' . $e->getMessage());
return 1;
}
return 0;
}
}