Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ across such a case, please let us know by [opening an issue][issues], or by addi
* The `db_timeout` configuration option was added (default: `60`, same as the default shell command timeout).
Set the option to `null` to disable the timeout.

* The `db_ssh_tunnel_timeout` configuration was added (default: `30` seconds). This sets the timeout for establishing
* The `db_ssh_tunnel_timeout` configuration option was added (default: `30` seconds). This sets the timeout for establishing
an SSH tunnel to the remote database server. Set the option to `null` to disable the timeout.

* The `db_type` configuration option was added to `environments.*`. This allows specifying the database type of the remote
environment (`mysql` (default), `mariadb`, `mongodb`, `pgsql` or `sqlite`).

## v0.6.0

* The configuration for the `AnonymizeUsers` processor was changed. Make sure to update your config file accordingly, so
Expand Down
22 changes: 20 additions & 2 deletions config/environment-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,33 @@
|
| Environments that should be available for import.
|
| Each environment supports the following settings:
| - ssh_host: The SSH host to connect to.
| - ssh_username: The SSH username to use.
| - ssh_key: The SSH private key to use (optional if ssh_password is used).
| - ssh_password: The SSH password to use (overrules ssh_key if present).
| - ssh_base_path: The base path of the project on the remote server.
|
| - db_type: The database connection type. Supported types: `mysql` (default), `mariadb`, `mongodb`, `pgsql` and `sqlite`.
| - db_host: The database host.
| - db_name: The database name.
| - db_username: The database username.
| - db_password: The database password.
| - db_port: The database port.
| - db_use_ssh: Whether to use an SSH tunnel to connect to the database.
| - db_ssh_tunnel_port: The local port to use for the SSH tunnel.
|
*/

'environments' => [
'staging' => [
'ssh_host' => env('LEI_STAGING_SSH_HOST'),
'ssh_username' => env('LEI_STAGING_SSH_USERNAME'),
'ssh_key' => env('LEI_STAGING_SSH_KEY', '~/.ssh/id_rsa'),
'ssh_password' => env('LEI_STAGING_SSH_PASSWORD'), // Overrules ssh_key if present
'ssh_password' => env('LEI_STAGING_SSH_PASSWORD'),
'ssh_base_path' => env('LEI_STAGING_SSH_BASE_PATH'),

'db_type' => env('LEI_STAGING_DB_TYPE', 'mysql'),
'db_host' => env('LEI_STAGING_DB_HOST'),
'db_name' => env('LEI_STAGING_DB_NAME'),
'db_username' => env('LEI_STAGING_DB_USERNAME'),
Expand All @@ -32,9 +49,10 @@
'ssh_host' => env('LEI_PRODUCTION_SSH_HOST'),
'ssh_username' => env('LEI_PRODUCTION_SSH_USERNAME'),
'ssh_key' => env('LEI_PRODUCTION_SSH_KEY', '~/.ssh/id_rsa'),
'ssh_password' => env('LEI_PRODUCTION_SSH_PASSWORD'), // Overrules ssh_key if present
'ssh_password' => env('LEI_PRODUCTION_SSH_PASSWORD'),
'ssh_base_path' => env('LEI_PRODUCTION_SSH_BASE_PATH'),

'db_type' => env('LEI_PRODUCTION_DB_TYPE', 'mysql'),
'db_host' => env('LEI_PRODUCTION_DB_HOST'),
'db_name' => env('LEI_PRODUCTION_DB_NAME'),
'db_username' => env('LEI_PRODUCTION_DB_USERNAME'),
Expand Down
25 changes: 21 additions & 4 deletions src/Commands/ImportEnvironmentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Schema;
use Spatie\DbDumper\Databases\MariaDb;
use Spatie\DbDumper\Databases\MongoDb;
use Spatie\DbDumper\Databases\MySql;
use Spatie\DbDumper\Databases\PostgreSql;
use Spatie\DbDumper\Databases\Sqlite;
use Spatie\DbDumper\Exceptions\CannotSetParameter;
use Symfony\Component\Process\Process;
use VanOns\LaravelEnvironmentImporter\Exceptions\ImportEnvironmentException;
Expand Down Expand Up @@ -157,6 +161,7 @@ protected function getEnvironments(): array
'ssh_host',
'ssh_username',
'ssh_base_path',
'db_type',
'db_host',
'db_name',
'db_username',
Expand Down Expand Up @@ -321,16 +326,28 @@ protected function getDatabaseDumpClient(bool $local = false): MySql
default => $this->dbPort(),
};

$dbType = match ($local) {
true => DB::getDriverName(),
false => $this->getEnvironmentConfigValue('db_type', 'mysql'),
};

/** @var class-string<MariaDb|MongoDb|MySql|PostgreSql|Sqlite> $db */
$db = match ($dbType) {
'mariadb' => MariaDb::class,
'mongodb' => MongoDb::class,
'pgsql' => PostgreSql::class,
'sqlite' => Sqlite::class,
default => MySql::class,
};

/** @phpstan-ignore-next-line */
return MySql::create()
return $db::create()
->setHost($local ? DB::getConfig('host') : $this->getEnvironmentConfigValue('db_host'))
->setDbName($local ? DB::getConfig('database') : $this->getEnvironmentConfigValue('db_name'))
->setUserName($local ? DB::getConfig('username') : $this->getEnvironmentConfigValue('db_username'))
->setPassword($local ? DB::getConfig('password') : $this->getEnvironmentConfigValue('db_password'))
->setPort($port)
->setDumpBinaryPath($this->getConfigValue('db_dump_binary_path', '/usr/bin'))
// Disable column statistics to prevent issues with older MySQL or MariaDB versions.
->addExtraOption('--column-statistics=0');
->setDumpBinaryPath($this->getConfigValue('db_dump_binary_path', '/usr/bin'));
}

/**
Expand Down