PHP code example of nodir / db-sync
1. Go to this page and download the library: Download nodir/db-sync library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nodir / db-sync example snippets
DB::table('users')->update([
'email' => DB::raw("CONCAT('user', id, '@test.local')"),
'phone' => DB::raw("CONCAT('+99890', LPAD(id::text, 7, '0'))"),
]);
bash
php artisan vendor:publish --tag=db-sync-config
dockerfile
# PostgreSQL client (pg_dump, pg_restore) va SSH
RUN apt-get update && apt-get install -y \
postgresql-client \
openssh-client \
&& rm -rf /var/lib/apt/lists/*
bash
docker compose exec app bash
# Hammasi bormi?
pg_dump --version # ✅ PostgreSQL client
pg_restore --version # ✅ PostgreSQL restore
ssh user@server "echo OK" # ✅ SSH ulanish
# Sync!
php artisan db:sync-prod
bash
ssh [email protected] "echo OK"
bash
php artisan db:sync-prod --fresh --keep-dump
bash
php artisan db:sync-prod --fresh
┌──────────────┐ SSH ┌──────────────┐
│ Local │──────────────▶│ Prod │
│ │ pg_dump │ │
│ │◀──────────────│ │
│ │ .dump file │ │
└──────┬───────┘ └──────────────┘
│
▼ pg_restore
┌──────────────┐
│ Local DB │
│ (yangilanadi)│
└──────────────┘