Start a Project

Bagisto Database Compatibility: One Codebase for MySQL, MariaDB, and PostgreSQL

bagisto-database-support-featured-light

Run your Bagisto store on MySQL, MariaDB, or PostgreSQL. Bagisto Database Compatibility is built into the core, with one codebase for all three.

What Bagisto Database Compatibility Offers

The Bagisto 2.5 release in October 2026 added PostgreSQL beside MySQL and MariaDB. CI tests all three on every change.

Supporting three databases does not mean writing every query three times. Bagisto moves each difference into one known place.

The hard part was never the syntax. It was behavior that passes on one engine and fails quietly on another.

Why Portable SQL Breaks Quietly

Laravel hides most differences between engines. These questions still decide whether a query works everywhere:

  1. Does a text search match “Shirt” when the shopper types “shirt”?
  2. What does a blank form field turn into?
  3. Does a boolean come back as 1 or as true?
  4. Can a transaction continue after a duplicate-key error?

Take the first one. Here is the search most developers write.

MySQL compares text without case under its default collations. PostgreSQL LIKE is case-sensitive.

So the same store finds the product on MySQL and returns nothing on PostgreSQL. No test fails until someone runs it there.

The Bagisto Agent Skills teach AI assistants to avoid exactly this mistake.

How Bagisto Database Compatibility Works

Bagisto answers each question with one rule, and each rule lives in one layer of the code.

One Grammar for Every Engine

The db_grammar() helper returns the SQL fragment that suits the active connection.

The helper resolves the DatabaseGrammar contract. Bagisto binds a PostgreSQL grammar for pgsql connections and a MySQL grammar for the rest.

The contract holds 16 methods, one for each construct the engines spell differently:

The admin reports group sales by month, week, and day through the same grammar. One report query serves all three engines.

Typed Models for Every Value

A blank form field arrives as an empty string. PostgreSQL rejects an empty string in an integer, date, or boolean column.

MySQL stores a boolean as TINYINT(1) and returns 1 or 0. PostgreSQL has a native boolean type and returns true or false.

Bagisto fixes both sides in the model. A setter cleans the value on write, and a cast fixes the type on read.

These lines come from the catalog rule model. More than 40 Bagisto models now declare boolean casts.

The rule lives in the model, not in a controller. An admin form, an import, and an API call all save the same clean value.

Upserts Instead of Caught Errors

Bagisto records every storefront search in the search_terms table. Two shoppers can search the same new term at the same moment.

The old code tried the insert and caught the duplicate-key error.

MySQL rolls back only the failed statement. PostgreSQL marks the whole transaction as failed instead.

Every later statement then fails with SQLSTATE 25P02, “current transaction is aborted”. The catch block cannot recover.

Bagisto now records the search in one statement, and the database settles the conflict itself.

Laravel compiles it to ON DUPLICATE KEY UPDATE on MySQL and MariaDB, and to ON CONFLICT DO UPDATE on PostgreSQL.

The helper incrementedUses() writes the column as search_terms.uses, because PostgreSQL reads a bare column there as ambiguous.

Proven on Nine Database Versions

Each of these bugs passes every test on the database the developer runs. So CI checks Bagisto Database Compatibility on every change, on every engine.

The Pest workflow runs on each push and each pull request:

PHP 8.4 and PHP 8.5 each run against all nine images, so every change goes through 18 jobs.

The workflow does not stop at the first failure. A break on one engine leaves the others running, so one run shows every break.

Writing an extension? Follow the same rules in your own queries:

  1. Use the grammar helper for LIKE, string aggregation, dates, and JSON.
  2. Add a boolean cast and a setter for each field a form can send empty.
  3. List every non-aggregated column of a SELECT in its GROUP BY.
  4. Settle a duplicate with an upsert rather than catching a constraint error.
  5. Run your tests on MySQL and PostgreSQL before each release.

Works with Bagisto extensions:

  1. Multi Vendor Marketplace: transform your store into a marketplace.
  2. Multi Tenant Commerce: a SaaS solution to launch and scale online.
  3. Headless eCommerce: API-first, flexible headless commerce.
  4. B2B Commerce: build B2B with bulk orders and catalogs.
  5. B2B Marketplace: launch a B2B marketplace for scalable trade.
  6. Mobile App: a customizable open-source eCommerce app.
  7. Bagisto Themes: pre-built stores for every business type.
  8. POS: sell in your offline store and online.
    ….. all other Extensions.

Bagisto Database Compatibility FAQ

Does PostgreSQL support cost anything?

No. Bagisto Database Compatibility is part of Bagisto core, which is open source under the MIT license.

Which database should I choose?

All three pass the same test suite in CI. Pick the engine your team and your host already run well.

How do I choose the database for a new store?

Run php artisan bagisto:install and select mysql, mariadb, or pgsql when it asks for the database connection.

The installer fills the default port for each, 3306 or 5432, and writes your choice to the .env file.

Is there a Docker image for PostgreSQL?

Yes. The production images come in one version per web server and database, such as 2.5.0-nginx-postgres.

Will my extensions work on PostgreSQL?

They work when their own queries follow the same rules. An extension with MySQL-only SQL needs the grammar helper first.

Go Ahead with Bagisto

Bagisto Database Compatibility comes built into Bagisto core: one codebase, typed models, and a CI matrix that proves it on three engines.

Get started today: Follow the Bagisto installation guide.

Exit mobile version