flarum / framework

Simple forum software for building great communities.
http://flarum.org/
6.23k stars 830 forks source link

feat: add support for PgSQL #3985

Closed SychO9 closed 2 weeks ago

SychO9 commented 2 months ago

Part of the roadmap

Changes proposed in this pull request: Postgres was trickier than SQLite, but that was mostly due to having some code that dates back years ago when eloquent/ the laravel schema builder was less flexible.

In most cases there should be no need to add any custum handling for the database driver when building queries. But that does become a necessity when writing more complex / larger queries. Example: fulltext search and statistics.

The easiest instance extension devs will run into when wanting to support PgSQL is the loose group by.

// Allowed in mysql
->select('col', 'col2', ..)
->groupBy('col')
->orderBy(..)

// must be done this way in pgsql
->select('col', 'col2', ..)
->distinct('col')
->orderBy('col')
->orderBy(..)

// can be simplified to
->select('col', 'col2', ..)
->whenMySql(fn (Builder $query) => $query->groupBy('col'))
->whenPgSql(fn (Builder $query) => $query->distinct('col')->orderBy('col'))
->orderBy(..)

Screenshot image image

Necessity

Confirmed

Required changes:

SychO9 commented 1 month ago

Added support for defining supported databases

image image

SychO9 commented 2 weeks ago

Awesome work! Should we show a warning in the extension UI and/or when enabling extensions if they don't specify compatibility with the current db driver?

image

SychO9 commented 2 weeks ago

@askvortsov1

https://github.com/flarum/framework/pull/3985/commits/ff96395941ea36e40672ff484bd79f8b8bf12a06

image