'integer', 'table_size_mb' => 'float', 'index_size_mb' => 'float', 'data_free_mb' => 'float', 'avg_row_length' => 'integer', 'auto_increment' => 'integer', 'has_time_field' => 'boolean', 'time_fields' => 'array', 'has_user_field' => 'boolean', 'user_fields' => 'array', 'has_status_field' => 'boolean', 'status_fields' => 'array', 'last_scanned_at' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * 按表名筛选 */ public function scopeByTable($query, string $tableName) { return $query->where('table_name', $tableName); } /** * 获取大表(记录数超过指定数量) */ public function scopeLargeTables($query, int $minRecords = 10000) { return $query->where('record_count', '>', $minRecords); } /** * 获取有时间字段的表 */ public function scopeWithTimeFields($query) { return $query->where('has_time_field', true); } /** * 获取有用户字段的表 */ public function scopeWithUserFields($query) { return $query->where('has_user_field', true); } /** * 获取有状态字段的表 */ public function scopeWithStatusFields($query) { return $query->where('has_status_field', true); } /** * 获取表大小的可读格式 */ public function getTableSizeHumanAttribute(): string { $mb = $this->table_size_mb; if ($mb < 1) { return round($mb * 1024, 2) . ' KB'; } elseif ($mb < 1024) { return round($mb, 2) . ' MB'; } else { return round($mb / 1024, 2) . ' GB'; } } /** * 获取总大小(表+索引) */ public function getTotalSizeMbAttribute(): float { return $this->table_size_mb + $this->index_size_mb; } /** * 获取总大小的可读格式 */ public function getTotalSizeHumanAttribute(): string { $mb = $this->total_size_mb; if ($mb < 1) { return round($mb * 1024, 2) . ' KB'; } elseif ($mb < 1024) { return round($mb, 2) . ' MB'; } else { return round($mb / 1024, 2) . ' GB'; } } }