Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaryabakhtar authored Mar 15, 2024
2 parents 5eabf86 + 6a512e4 commit 20e532f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PHP Pipeline

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
max-parallel: 2
matrix:
php-versions: ['8.2']

name: PHP ${{ matrix.php-versions }}

steps:
- uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: ./vendor/bin/pest
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Community

There is a Discord community. https://discord.gg/VYau8hgwrm For quick help, ask questions in the appropriate channel.

# Laravel DB Sync

![DB Dync](https://repository-images.githubusercontent.com/506690782/a5b01352-4869-4e6d-8e46-d44e93c960df)
Expand Down Expand Up @@ -68,6 +72,12 @@ To specify a different local database connection:
LOCAL_TARGET_CONNECTION=different_mysql_connection
```

Set the mysql command path:

```
LOCAL_MYSQL_PATH=/usr/bin/mysql
```

For only mysqldump:
```
REMOTE_MYSQLDUMP_SKIP_TZ_UTC=true
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}
],
"require-dev": {
"orchestra/testbench": "^5.0|^6.23|^7.0|^8.0",
"pestphp/pest": "^1.21",
"orchestra/testbench": "^5.0|^6.23|^7.0|^8.0|^9.0",
"pestphp/pest": "^1.21|^2.0",
"pestphp/pest-plugin-laravel": "^1.1",
"friendsofphp/php-cs-fixer": "^3.9"
},
Expand Down
8 changes: 8 additions & 0 deletions config/dbsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*/
'username' => env('REMOTE_DATABASE_USERNAME', ''),

/*
* Database host (optional)
*/
'mysqlHostName' => env('REMOTE_DATABASE_MYSQL_HOSTNAME', 'localhost'),

/*
* Database port
*/
Expand Down Expand Up @@ -69,11 +74,14 @@

'mysqldumpSkipTzUtc' => env('REMOTE_MYSQLDUMP_SKIP_TZ_UTC', false),


/*
* List all the environment variables that need to be set for the command to work
*/
'environments' => [
'local',
'staging'
],

'localMysqlPath' => env('LOCAL_MYSQL_PATH', '/usr/local/bin/mysql'),
];
18 changes: 15 additions & 3 deletions src/Console/DbSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public function handle(): bool
return true;
}

$host = config('dbsync.host');
$useSsh = config('dbsync.useSsh');
$sshUsername = config('dbsync.sshUsername');
$sshPort = config('dbsync.sshPort');
$host = config('dbsync.host');

$mysqlHostName = config('dbsync.mysqlHostName');
$username = config('dbsync.username');
$database = config('dbsync.database');
$port = config('dbsync.port');
Expand All @@ -37,6 +38,13 @@ public function handle(): bool
$mysqldumpSkipTzUtc = config('dbsync.mysqldumpSkipTzUtc') ? '--skip-tz-utc' : '';

$targetConnection = config('dbsync.targetConnection');

$localUsername = config('database.connections.mysql.username');
$localPassword = config('database.connections.mysql.password');
$localHostname = config('database.connections.mysql.host');
$localPort = config('database.connections.mysql.port');
$localDatabase = config('database.connections.mysql.database');
$localMysqlPath = config('dbsync.localMysqlPath');

if (empty($host) || empty($username) || empty($database)) {
$this->error('DB credentials not set, have you published the config and set ENV variables?');
Expand All @@ -52,15 +60,19 @@ public function handle(): bool
}

if ($useSsh === true) {
exec("ssh $sshUsername@$host -p$sshPort mysqldump -P$port -u$username -p$password $database $ignoreString > $fileName", $output);
echo($mysqlHostName . PHP_EOL);
exec("ssh $sshUsername@$host -p$sshPort mysqldump -P$port -h$mysqlHostName -u$username -p$password $database $ignoreString > $fileName", $output);
} else {
exec("mysqldump -h$host -P$port -u$username -p$password $database $ignoreString $mysqldumpSkipTzUtc --column-statistics=0 > $fileName", $output);
}

$this->comment(implode(PHP_EOL, $output));

if ($importSqlFile === true) {
DB::connection($targetConnection)->unprepared(file_get_contents(base_path($fileName)));
$command = $localPassword
? "$localMysqlPath -u$localUsername -h$localHostname -p$localPassword -P$localPort $localDatabase < $fileName"
: "$localMysqlPath -u$localUsername -h$localHostname -P$localPort $localDatabase < $fileName";
exec($command, $output);
}

if ($removeFileAfterImport === true) {
Expand Down

0 comments on commit 20e532f

Please sign in to comment.