YOURLS now speaks PostgreSQL

YOURLS is my cherished project: I'm proud of it, and I'm also clear-eyed about its limitations. For instance, PostgreSQL support has been one of the frequently requested features for at least six years. There have been a few YOURLS PostgreSQL forks that tried to address this, but keeping a fork in sync is quite a task and they didn't keep up with YOURLS (albeit rather modest) development pace. Today I'm happy to say: the wait is over.

PostgreSQL support via plugin

PostgreSQL support comes as a drop-in plugin rather than a core feature: we like to keep YOURLS core light and let people add features only if they need it. This plugin intercepts database queries at runtime and translates MySQL to PostgreSQL syntax on the fly – backtick quoting, AUTO_INCREMENT ? SERIAL, RAND() ? RANDOM(), and so on. Obviously this is all transparent to the user and the application.

What will work, what won't

Everything core does, ie shortening URLs, tracking clicks, letting you add or edit short URLs, will work. The vast majority of existing YOURLS plugins will work. The drop-in plugin sits at the database layer and catches everything that flows through it.

To make sure everything core works perfectly, I've made sure YOURLS passes all its unit tests with the PostgreSQL plugin activated, under 3 latest versions of PostgreSQL and latest PHP. This will be easy to check with all future YOURLS releases.

The edge cases would be plugins that execute raw MySQL-flavored SQL directly, bypassing YOURLS' own database methods, won't be translated. I haven't encountered such plugin in the wild but if you have made custom query code, that would be something to fix.

Requirements

You'll need YOURLS 1.10.4, which is coming soon-ish or the current master branch (which is always stable and passing all unit tests). Drop in the plugin, configure your PostgreSQL DSN, and you're good to go. There is even a migration script to transfer everything from MySQL (or MariaDB) to PostgreSQL.

If you've been waiting for this – and I know some of you have been waiting for a long time – it's finally here :)

Leave a Reply

Your email address will not be published. Required fields are marked *