Free: a 2-minute MySQL to Postgres readiness check for Laravel apps (single PHP file)
TuskShiftNew, free, in your browser: paste your SHOW CREATE TABLE and see what breaks on Postgres (int unsigned overflow, TIMESTAMP shift, _ci collations, sequences, tinyint(1), ENUM/SET, zero dates, FULLTEXT). Nothing is uploaded.
Update 26 Oct: checker v2 is out (adds TIMESTAMP time-zone shift, increments() headroom and bigint unsigned checks): free checker v2 + full migration checklist.
A free, single-file PHP script that tells you in about two minutes how much of your Laravel app will break when you switch DB_CONNECTION=mysql to pgsql. No Composer, no dependencies, PHP 8.1+, MIT licence. The database part only runs SELECTs.
What it checks
Code (14 patterns, the ones that break most often): where(..., 'like', ...) turning case-sensitive, backtick identifiers in raw SQL, IFNULL, GROUP_CONCAT, DATE_FORMAT, DATE_ADD/DATEDIFF, ON DUPLICATE KEY / INSERT IGNORE / REPLACE INTO, ORDER BY FIELD(), FOREIGN_KEY_CHECKS, zero-date literals, REGEXP, IF() in raw expressions, unsigned integers in migrations, and groupBy() calls to review.
Live data (optional, read-only): zero or partial dates, NUL bytes in text, tinyint(1) columns holding values other than 0/1, unsigned ints above the Postgres integer limit, unique columns on a _ci collation (your email logins become case-sensitive), and triggers that no loader ports.
Run it
Save the script below as tuskshift-quickcheck.php, then:
php tuskshift-quickcheck.php /path/to/laravel-app # add the data checks (password from env, never on the command line): TUSK_MYSQL_PASSWORD=secret php tuskshift-quickcheck.php /path/to/laravel-app \ --dsn="mysql:host=127.0.0.1;dbname=app" --user=readonly_user
Exit code is 1 if anything high-severity or a data blocker turns up, so you can drop it into CI as a gate.
Sample output (our demo app + a seeded MariaDB 11)
TuskShift quickcheck — 4 PHP files scanned
Code: 10 high, 1 medium, 1 low
Data/schema: 6 issue(s)
HIGH LIKE_CASE app/Http/Controllers/CustomerController.php:14
where(col, 'like', ...) turns case-SENSITIVE on Postgres. Use ->whereLike() ...
HIGH UPSERT app/Http/Controllers/CustomerController.php:29
MySQL-only upsert. Use ->upsert() / ->insertOrIgnore() (compile to ON CONFLICT).
DATA CI_UNIQUE users.email
Unique on utf8mb4_unicode_ci: lookups become case-sensitive on Postgres ...
DATA BOOL_NOT_01 users.is_admin
1 row(s) hold values other than 0/1. A boolean cast fails or loses data.
DATA NUL_BYTE invoices.notes
1 row(s) contain a 0x00 byte. Postgres text cannot store it.
DATA ZERO_DATE invoices.due_at
2 row(s) with zero/partial dates. Postgres rejects them.The script
#!/usr/bin/env php
<?php
/**
* tuskshift-quickcheck (free) — a 2-minute MySQL→PostgreSQL readiness check for a Laravel app.
*
* php tuskshift-quickcheck.php /path/to/laravel-app
* php tuskshift-quickcheck.php /path/to/laravel-app --dsn="mysql:host=127.0.0.1;dbname=app" --user=app
* (password via TUSK_MYSQL_PASSWORD env var; the DB part only runs SELECTs)
*
* Part 1 greps app/, routes/, database/ and config/ for the 14 MySQL-only patterns that break most often.
* Part 2 (optional) checks live data for the 5 things that make a Postgres load fail or silently change.
* No dependencies. PHP 8.1+. MIT licence. Exit code 1 if anything "high" or a data blocker is found.
*
* Free sampler from TuskShift. The full kit (52 code rules, full preflight, resumable copy,
* per-row checksum verify, FK snapshot/restore, 10-chapter playbook): https://tuskshift.gumroad.com/l/tuskshift
*/
declare(strict_types=1);
$path = null; $o = ['dsn' => null, 'user' => 'root'];
foreach (array_slice($argv, 1) as $a) {
if (preg_match('/^--(dsn|user)=(.*)$/s', $a, $m)) { $o[$m[1]] = $m[2]; } elseif ($a[0] !== '-') { $path = rtrim($a, '/'); }
}
if (!$path || !is_dir($path)) { fwrite(STDERR, "Usage: php tuskshift-quickcheck.php <laravel-app> [--dsn=mysql:...] [--user=...]\n"); exit(2); }
// [id, severity, regex, why/fix]
$rules = [
['LIKE_CASE', 'high', "/['\"](not\\s+)?like['\"]\\s*,/i", "where(col, 'like', ...) turns case-SENSITIVE on Postgres. Use ->whereLike() (Laravel 11+) or ilike behind a driver check."],
['BACKTICK', 'high', '/(DB::|Raw\(|select\(|statement\().*`[A-Za-z_]+`/', 'Backtick identifiers in raw SQL. Postgres uses "double quotes"; usually just drop them.'],
['IFNULL', 'high', '/\bIFNULL\s*\(/i', 'IFNULL() does not exist. COALESCE() works on both engines.'],
['GROUP_CONCAT','high', '/\bGROUP_CONCAT\s*\(/i', "GROUP_CONCAT() does not exist. string_agg(col::text, ',') on pgsql."],
['DATE_FORMAT', 'high', '/\bDATE_FORMAT\s*\(/i', "DATE_FORMAT() does not exist. to_char(col, 'YYYY-MM-DD')."],
['DATE_MATH', 'high', '/\b(DATE_ADD|DATE_SUB|DATEDIFF|TIMESTAMPDIFF)\s*\(/i', 'MySQL date math. Bind a Carbon value or use col + INTERVAL \'7 days\'.'],
['UPSERT', 'high', '/ON\s+DUPLICATE\s+KEY|INSERT\s+IGNORE|REPLACE\s+INTO/i', 'MySQL-only upsert. Use ->upsert() / ->insertOrIgnore() (compile to ON CONFLICT).'],
['FIELD_ORDER', 'high', '/ORDER\s+BY\s+FIELD\s*\(/i', 'ORDER BY FIELD() is MySQL-only. Use a CASE expression or array_position().'],
['FK_CHECKS', 'high', '/FOREIGN_KEY_CHECKS/i', 'Use Schema::disableForeignKeyConstraints() instead.'],
['ZERO_DATE', 'high', "/'0000-00-00/", "Zero dates are rejected by Postgres. Use NULL."],
['REGEXP', 'high', '/\s(NOT\s+)?(REGEXP|RLIKE)\s/i', 'REGEXP/RLIKE: use ~ or ~* on Postgres.'],
['IF_FUNC', 'medium', '/(selectRaw|DB::raw|orderByRaw|havingRaw)\(.*(?<![A-Za-z_])IF\s*\(/i', 'IF(cond,a,b) is MySQL-only. CASE WHEN ... END works on both.'],
['UNSIGNED', 'medium', '/->(unsignedInteger|unsignedMediumInteger)\(/', 'No unsigned ints on Postgres: unsignedInteger max drops from 4.29B to 2.14B.'],
['GROUP_BY', 'low', '/->groupBy\(/', 'Postgres rejects selected columns that are neither grouped nor aggregated. Check each one.'],
];
$findings = []; $files = 0;
foreach (['app', 'routes', 'database', 'config'] as $dir) {
if (!is_dir("$path/$dir")) { continue; }
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("$path/$dir", FilesystemIterator::SKIP_DOTS));
foreach ($it as $f) {
if (!str_ends_with($f->getFilename(), '.php')) { continue; }
$files++;
foreach (file($f->getPathname()) as $n => $line) {
foreach ($rules as [$id, $sev, $re, $fix]) {
if (preg_match($re, $line)) { $findings[] = [$sev, $id, substr($f->getPathname(), strlen($path) + 1) . ':' . ($n + 1), $fix]; }
}
}
}
}
$blockers = [];
if ($o['dsn']) {
try {
$pdo = new PDO($o['dsn'], $o['user'], getenv('TUSK_MYSQL_PASSWORD') ?: '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
} catch (Throwable $e) { fwrite(STDERR, "DB connection failed: {$e->getMessage()}\n"); exit(2); }
$qi = fn(string $s) => '`' . str_replace('`', '``', $s) . '`';
$cols = $pdo->query("SELECT c.TABLE_NAME t, c.COLUMN_NAME c, c.DATA_TYPE d, c.COLUMN_TYPE ct, c.COLUMN_KEY k, c.COLLATION_NAME co
FROM information_schema.COLUMNS c JOIN information_schema.TABLES tb ON tb.TABLE_SCHEMA=c.TABLE_SCHEMA AND tb.TABLE_NAME=c.TABLE_NAME
WHERE c.TABLE_SCHEMA = DATABASE() AND tb.TABLE_TYPE='BASE TABLE'")->fetchAll(PDO::FETCH_ASSOC);
foreach ($cols as $r) {
[$t, $c, $d] = [$r['t'], $r['c'], $r['d']]; $col = $qi($c); $tab = $qi($t); $obj = "$t.$c";
$count = fn(string $where) => (int) $pdo->query("SELECT COUNT(*) FROM $tab WHERE $where")->fetchColumn();
if (in_array($d, ['date', 'datetime', 'timestamp'], true) && ($n = $count("CAST($col AS CHAR) LIKE '0000-%' OR CAST($col AS CHAR) LIKE '%-00-%' OR CAST($col AS CHAR) LIKE '%-00%'")))
{ $blockers[] = ['ZERO_DATE', $obj, "$n row(s) with zero/partial dates. Postgres rejects them."]; }
if (in_array($d, ['char', 'varchar', 'text', 'mediumtext', 'longtext'], true) && ($n = $count("LOCATE(CHAR(0), $col) > 0")))
{ $blockers[] = ['NUL_BYTE', $obj, "$n row(s) contain a 0x00 byte. Postgres text cannot store it."]; }
if ($r['ct'] === 'tinyint(1)' && ($n = $count("$col NOT IN (0,1)")))
{ $blockers[] = ['BOOL_NOT_01', $obj, "$n row(s) hold values other than 0/1. A boolean cast fails or loses data."]; }
if ($d === 'int' && str_contains($r['ct'], 'unsigned') && ($n = $count("$col > 2147483647")))
{ $blockers[] = ['UNSIGNED_OVERFLOW', $obj, "$n row(s) exceed Postgres integer. Use bigint."]; }
if (in_array($r['k'], ['PRI', 'UNI'], true) && $r['co'] && str_ends_with($r['co'], '_ci'))
{ $blockers[] = ['CI_UNIQUE', $obj, "Unique on {$r['co']}: lookups become case-sensitive on Postgres (logins by email!). Use citext or a lower() index."]; }
}
if ($n = (int) $pdo->query("SELECT COUNT(*) FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA = DATABASE()")->fetchColumn())
{ $blockers[] = ['TRIGGERS', 'schema', "$n trigger(s): no loader ports these; rewrite in PL/pgSQL."]; }
}
$rank = ['high' => 0, 'medium' => 1, 'low' => 2];
usort($findings, fn($a, $b) => [$rank[$a[0]], $a[1]] <=> [$rank[$b[0]], $b[1]]);
$tally = array_count_values(array_column($findings, 0)) + ['high' => 0, 'medium' => 0, 'low' => 0];
echo "TuskShift quickcheck — $files PHP files scanned\n";
echo "Code: {$tally['high']} high, {$tally['medium']} medium, {$tally['low']} low\n";
if ($o['dsn']) { echo 'Data/schema: ' . count($blockers) . " issue(s)\n"; }
echo str_repeat('-', 72), "\n";
foreach ($findings as [$sev, $id, $where, $fix]) { printf("%-6s %-13s %s\n %s\n", strtoupper($sev), $id, $where, $fix); }
foreach ($blockers as [$id, $obj, $why]) { printf("DATA %-17s %s\n %s\n", $id, $obj, $why); }
echo str_repeat('-', 72), "\n";
echo "Not checked here: SQL built across variables, TIMESTAMP time-zone shifts, sequences after a data load,\n";
echo "FKs dropped by pgloader, row-level verification. Full kit: https://tuskshift.gumroad.com/l/tuskshift\n";
exit(($tally['high'] > 0 || $blockers) ? 1 : 0);What it does not catch
It is a grep plus six queries. It cannot see SQL assembled across several variables, and it does not touch the problems that only show up during or after the copy: MySQL TIMESTAMP values shifting by the server's offset, sequences left behind MAX(id) after a bulk load (first insert after go-live hits a duplicate key), foreign keys that pgloader's data-only mode silently drops, and rows that copied but changed. Row counts will match in all of those cases.
Those are what the paid TuskShift Migration Kit ($49) covers: a 52-rule scanner, full read-only preflight, resumable chunked copy, per-row checksum verification, FK snapshot/restore and sequence-reset SQL, and a 10-chapter cutover playbook. For a production cutover that needs a signed go/no-go, there is the Cutover Assurance Pack.
Found a trap this misses? Tell us and we will add it.
Not affiliated with Laravel, PostgreSQL, MySQL or MariaDB.
Doing this migration for real? The TuskShift Migration Kit has the full runbook, data-validation SQL and cutover checklist. Launch price: 30% off with code LAUNCH30 until Nov 5 → https://tuskshift.gumroad.com/l/tuskshift/LAUNCH30 . Also want metrics on Timescale? Kit + Timescale Metrics Kit bundle: https://tuskshift.gumroad.com/l/fmfnj