Skip to content

Commit 20e532f

Browse files
authored
Merge branch 'main' into main
2 parents 5eabf86 + 6a512e4 commit 20e532f

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

.github/workflows/php.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: PHP Pipeline
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
max-parallel: 2
12+
matrix:
13+
php-versions: ['8.2']
14+
15+
name: PHP ${{ matrix.php-versions }}
16+
17+
steps:
18+
- uses: actions/checkout@v1
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@master
22+
with:
23+
php-version: ${{ matrix.php-versions }}
24+
coverage: xdebug
25+
26+
- name: Validate composer.json and composer.lock
27+
run: composer validate
28+
29+
- name: Install dependencies
30+
run: composer install --prefer-dist --no-progress --no-suggest
31+
32+
- name: Run test suite
33+
run: ./vendor/bin/pest

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Community
2+
3+
There is a Discord community. https://discord.gg/VYau8hgwrm For quick help, ask questions in the appropriate channel.
4+
15
# Laravel DB Sync
26

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

75+
Set the mysql command path:
76+
77+
```
78+
LOCAL_MYSQL_PATH=/usr/bin/mysql
79+
```
80+
7181
For only mysqldump:
7282
```
7383
REMOTE_MYSQLDUMP_SKIP_TZ_UTC=true

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
}
1010
],
1111
"require-dev": {
12-
"orchestra/testbench": "^5.0|^6.23|^7.0|^8.0",
13-
"pestphp/pest": "^1.21",
12+
"orchestra/testbench": "^5.0|^6.23|^7.0|^8.0|^9.0",
13+
"pestphp/pest": "^1.21|^2.0",
1414
"pestphp/pest-plugin-laravel": "^1.1",
1515
"friendsofphp/php-cs-fixer": "^3.9"
1616
},

config/dbsync.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
*/
2828
'username' => env('REMOTE_DATABASE_USERNAME', ''),
2929

30+
/*
31+
* Database host (optional)
32+
*/
33+
'mysqlHostName' => env('REMOTE_DATABASE_MYSQL_HOSTNAME', 'localhost'),
34+
3035
/*
3136
* Database port
3237
*/
@@ -69,11 +74,14 @@
6974

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

77+
7278
/*
7379
* List all the environment variables that need to be set for the command to work
7480
*/
7581
'environments' => [
7682
'local',
7783
'staging'
7884
],
85+
86+
'localMysqlPath' => env('LOCAL_MYSQL_PATH', '/usr/local/bin/mysql'),
7987
];

src/Console/DbSyncCommand.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ public function handle(): bool
2020
return true;
2121
}
2222

23-
$host = config('dbsync.host');
2423
$useSsh = config('dbsync.useSsh');
2524
$sshUsername = config('dbsync.sshUsername');
2625
$sshPort = config('dbsync.sshPort');
26+
$host = config('dbsync.host');
2727

28+
$mysqlHostName = config('dbsync.mysqlHostName');
2829
$username = config('dbsync.username');
2930
$database = config('dbsync.database');
3031
$port = config('dbsync.port');
@@ -37,6 +38,13 @@ public function handle(): bool
3738
$mysqldumpSkipTzUtc = config('dbsync.mysqldumpSkipTzUtc') ? '--skip-tz-utc' : '';
3839

3940
$targetConnection = config('dbsync.targetConnection');
41+
42+
$localUsername = config('database.connections.mysql.username');
43+
$localPassword = config('database.connections.mysql.password');
44+
$localHostname = config('database.connections.mysql.host');
45+
$localPort = config('database.connections.mysql.port');
46+
$localDatabase = config('database.connections.mysql.database');
47+
$localMysqlPath = config('dbsync.localMysqlPath');
4048

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

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

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

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

6678
if ($removeFileAfterImport === true) {

0 commit comments

Comments
 (0)