← ClaudeAtlas

laravel-mysql-to-postgreslisted

Migrate a Laravel application's database from MySQL/MariaDB to PostgreSQL safely. Use when moving a Laravel app to Postgres, when Eloquent/queries behave differently after switching drivers, or when planning a MySQL->Postgres cutover. Covers the migration strategy (pgloader vs query-builder), the Laravel-specific behavior differences that silently break (case sensitivity, booleans, the id-sequence trap, raw SQL, GROUP BY strictness), and a verification checklist.
majdghithan/agent-skills · ★ 7 · API & Backend · score 73
Install: claude install-skill majdghithan/agent-skills
# Laravel: MySQL -> PostgreSQL migration The data moves fine. What breaks is the assumptions your app baked in over the years, because **MySQL is forgiving and Postgres is strict**. Every place you leaned on MySQL being lenient is a bug waiting on the other side. Treat a migration as an *audit of your app's lazy assumptions*, not a data transfer. ## Step 0 - The one test that surfaces half the problems Before touching real data, point `php artisan migrate` at a **fresh empty Postgres database** and watch what throws. If every migration runs clean, your schema is genuinely database-agnostic. If it throws, you just found your MySQL-only assumptions for free. ```bash # .env pointed at an empty pgsql db php artisan migrate:fresh # does the schema even build on Postgres? ``` Do not delete MySQL the day you switch. Keep it running for days/weeks until you're sure - cutovers get reverted. ## Step 1 - Move the data (pick one) - **`pgloader`** - a single tool built for exactly this. Reads MySQL, writes Postgres, converting types as it goes (`TINYINT(1)` -> `boolean`, `AUTO_INCREMENT` -> sequence). One command, most of the job. **Usually resets sequences for you** (see the trap below). - **Laravel's query builder** - read from the old connection, write to the new one in PHP, transforming rows. More control, more code; good when the schema has corners pgloader trips on. **Does NOT reset sequences** - you must do it manually. ## The behavior differences that silently break Lara