fix(migrations): use in-memory sqlite during tests and file sqlite for non-mysql
This commit is contained in:
parent
946e6c70e4
commit
ecd2da5688
|
|
@ -59,7 +59,7 @@ public function up()
|
|||
|
||||
private function createGesconImportConnection()
|
||||
{
|
||||
if (app()->environment('testing') || DB::connection()->getDriverName() === 'sqlite') {
|
||||
if (app()->environment('testing')) {
|
||||
config(['database.connections.gescon_import' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
|
|
@ -68,6 +68,28 @@ private function createGesconImportConnection()
|
|||
return;
|
||||
}
|
||||
|
||||
$existing = config('database.connections.gescon_import');
|
||||
if (is_array($existing) && ($existing['driver'] ?? '') === 'sqlite') {
|
||||
$dbFile = $existing['database'] ?? database_path('gescon_import.sqlite');
|
||||
if ($dbFile !== ':memory:' && ! file_exists($dbFile)) {
|
||||
@touch($dbFile);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (DB::connection()->getDriverName() === 'sqlite' || DB::connection()->getDriverName() === 'pgsql') {
|
||||
$sqlitePath = database_path('gescon_import.sqlite');
|
||||
if (! file_exists($sqlitePath)) {
|
||||
@touch($sqlitePath);
|
||||
}
|
||||
config(['database.connections.gescon_import' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => $sqlitePath,
|
||||
'prefix' => '',
|
||||
]]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Aggiungi connessione al database gescon_import in config
|
||||
config(['database.connections.gescon_import' => [
|
||||
'driver' => 'mysql',
|
||||
|
|
|
|||
|
|
@ -410,7 +410,7 @@ public function down(): void
|
|||
|
||||
private function configureGesconTempConnection(): void
|
||||
{
|
||||
if (app()->environment('testing') || DB::connection()->getDriverName() === 'sqlite') {
|
||||
if (app()->environment('testing')) {
|
||||
config(['database.connections.gescon_temp' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
|
|
@ -419,6 +419,28 @@ private function configureGesconTempConnection(): void
|
|||
return;
|
||||
}
|
||||
|
||||
$existing = config('database.connections.gescon_temp');
|
||||
if (is_array($existing) && ($existing['driver'] ?? '') === 'sqlite') {
|
||||
$dbFile = $existing['database'] ?? database_path('gescon_temp.sqlite');
|
||||
if ($dbFile !== ':memory:' && ! file_exists($dbFile)) {
|
||||
@touch($dbFile);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (DB::connection()->getDriverName() === 'sqlite' || DB::connection()->getDriverName() === 'pgsql') {
|
||||
$sqlitePath = database_path('gescon_temp.sqlite');
|
||||
if (! file_exists($sqlitePath)) {
|
||||
@touch($sqlitePath);
|
||||
}
|
||||
config(['database.connections.gescon_temp' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => $sqlitePath,
|
||||
'prefix' => '',
|
||||
]]);
|
||||
return;
|
||||
}
|
||||
|
||||
config(['database.connections.gescon_temp' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => '127.0.0.1',
|
||||
|
|
|
|||
|
|
@ -12,17 +12,43 @@
|
|||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Configurazione connessione gescon_import
|
||||
config(['database.connections.gescon_import' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '3306',
|
||||
'database' => 'gescon_import',
|
||||
'username' => 'netgescon_user',
|
||||
'password' => 'NetGescon2024!',
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
]]);
|
||||
if (app()->environment('testing')) {
|
||||
config(['database.connections.gescon_import' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
]]);
|
||||
} else {
|
||||
$existing = config('database.connections.gescon_import');
|
||||
if (is_array($existing) && ($existing['driver'] ?? '') === 'sqlite') {
|
||||
$dbFile = $existing['database'] ?? database_path('gescon_import.sqlite');
|
||||
if ($dbFile !== ':memory:' && ! file_exists($dbFile)) {
|
||||
@touch($dbFile);
|
||||
}
|
||||
} elseif (DB::connection()->getDriverName() === 'sqlite' || DB::connection()->getDriverName() === 'pgsql') {
|
||||
$sqlitePath = database_path('gescon_import.sqlite');
|
||||
if (! file_exists($sqlitePath)) {
|
||||
@touch($sqlitePath);
|
||||
}
|
||||
config(['database.connections.gescon_import' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => $sqlitePath,
|
||||
'prefix' => '',
|
||||
]]);
|
||||
} else {
|
||||
// Configurazione connessione gescon_import
|
||||
config(['database.connections.gescon_import' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '3306',
|
||||
'database' => 'gescon_import',
|
||||
'username' => 'netgescon_user',
|
||||
'password' => 'NetGescon2024!',
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
]]);
|
||||
}
|
||||
}
|
||||
|
||||
// === TABELLE CON DATI VERIFICATI ===
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user