64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\TargetDatabaseFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class TargetDatabase extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'host',
|
|
'port',
|
|
'database',
|
|
'username',
|
|
'password',
|
|
'driver',
|
|
'description',
|
|
'is_active',
|
|
];
|
|
|
|
protected $casts = [
|
|
'port' => 'integer',
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
protected static function newFactory(): TargetDatabaseFactory
|
|
{
|
|
return TargetDatabaseFactory::new();
|
|
}
|
|
|
|
public function migrationSchedules(): HasMany
|
|
{
|
|
return $this->hasMany(MigrationSchedule::class, 'target_database_id');
|
|
}
|
|
|
|
public function getConnectionConfig(): array
|
|
{
|
|
$config = [
|
|
'driver' => $this->driver,
|
|
'host' => $this->host,
|
|
'port' => $this->port,
|
|
'database' => $this->database,
|
|
'username' => $this->username,
|
|
'password' => $this->password,
|
|
'charset' => 'utf8',
|
|
'prefix' => '',
|
|
'prefix_indexes' => true,
|
|
];
|
|
|
|
// Add PostgreSQL-specific options
|
|
if ($this->driver === 'pgsql') {
|
|
$config['search_path'] = 'public';
|
|
$config['sslmode'] = 'prefer';
|
|
}
|
|
|
|
return $config;
|
|
}
|
|
}
|