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()
|
private function createGesconImportConnection()
|
||||||
{
|
{
|
||||||
if (app()->environment('testing') || DB::connection()->getDriverName() === 'sqlite') {
|
if (app()->environment('testing')) {
|
||||||
config(['database.connections.gescon_import' => [
|
config(['database.connections.gescon_import' => [
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => ':memory:',
|
'database' => ':memory:',
|
||||||
|
|
@ -68,6 +68,28 @@ private function createGesconImportConnection()
|
||||||
return;
|
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
|
// Aggiungi connessione al database gescon_import in config
|
||||||
config(['database.connections.gescon_import' => [
|
config(['database.connections.gescon_import' => [
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,7 @@ public function down(): void
|
||||||
|
|
||||||
private function configureGesconTempConnection(): void
|
private function configureGesconTempConnection(): void
|
||||||
{
|
{
|
||||||
if (app()->environment('testing') || DB::connection()->getDriverName() === 'sqlite') {
|
if (app()->environment('testing')) {
|
||||||
config(['database.connections.gescon_temp' => [
|
config(['database.connections.gescon_temp' => [
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => ':memory:',
|
'database' => ':memory:',
|
||||||
|
|
@ -419,6 +419,28 @@ private function configureGesconTempConnection(): void
|
||||||
return;
|
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' => [
|
config(['database.connections.gescon_temp' => [
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'host' => '127.0.0.1',
|
'host' => '127.0.0.1',
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,43 @@
|
||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
// Configurazione connessione gescon_import
|
if (app()->environment('testing')) {
|
||||||
config(['database.connections.gescon_import' => [
|
config(['database.connections.gescon_import' => [
|
||||||
'driver' => 'mysql',
|
'driver' => 'sqlite',
|
||||||
'host' => '127.0.0.1',
|
'database' => ':memory:',
|
||||||
'port' => '3306',
|
'prefix' => '',
|
||||||
'database' => 'gescon_import',
|
]]);
|
||||||
'username' => 'netgescon_user',
|
} else {
|
||||||
'password' => 'NetGescon2024!',
|
$existing = config('database.connections.gescon_import');
|
||||||
'charset' => 'utf8mb4',
|
if (is_array($existing) && ($existing['driver'] ?? '') === 'sqlite') {
|
||||||
'collation' => 'utf8mb4_unicode_ci',
|
$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 ===
|
// === TABELLE CON DATI VERIFICATI ===
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user