mirror of https://github.com/pixelfed/pixelfed
Fix MariaDB driver detection and reblog caption null inserts
Laravel 11 exposes MariaDB as a dedicated 'mariadb' driver, so
config('database.default') === 'mysql' checks silently misclassified
MariaDB as the non-mysql (postgres) branch.
- Add App\Util\Database\DatabaseDriver with isMysqlLike()/isPgsql()
plus db_is_mysql_like()/db_is_pgsql() global helpers.
- Route all database.default driver checks through the helpers so
MySQL and MariaDB are treated as one group.
- Use '' (not null) for share/compose caption+rendered, valid whether
the column is nullable or NOT NULL (it is NOT NULL on MySQL/MariaDB).
- Guard pgsql strtolower() in registration against missing fields.
- Scope CustomEmoji::duplicateShortcodes to the grouped column for
Postgres GROUP BY validity.
- Remove stale Postgres guard in status:dedup; use havingRaw for
cross-driver HAVING.
pull/7271/head
parent
74e861b4c2
commit
e3b6cebf27
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Util\Database;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Helpers for branching on the active database driver.
|
||||
*
|
||||
* Laravel 11 ships a dedicated `mariadb` driver, so `config('database.default')`
|
||||
* returns `mariadb` (not `mysql`) when a MariaDB connection is active. MySQL and
|
||||
* MariaDB share the same SQL dialect for the branches used in this codebase, so
|
||||
* they must be treated as one group. Comparing directly against the string
|
||||
* `'mysql'` silently misclassifies MariaDB as "other" (i.e. the Postgres path).
|
||||
*
|
||||
* Use these helpers instead of comparing driver strings by hand.
|
||||
*/
|
||||
class DatabaseDriver
|
||||
{
|
||||
/**
|
||||
* Drivers that share MySQL's SQL dialect.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public const MYSQL_LIKE = ['mysql', 'mariadb'];
|
||||
|
||||
/**
|
||||
* The driver name for the given connection (defaults to the active one).
|
||||
*
|
||||
* Resolves the real driver rather than the connection name, so a connection
|
||||
* named `mysql` that is actually configured with the `mariadb` driver is
|
||||
* reported correctly.
|
||||
*/
|
||||
public static function name(?string $connection = null): ?string
|
||||
{
|
||||
return DB::connection($connection)->getDriverName();
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the driver is MySQL or MariaDB.
|
||||
*
|
||||
* Prefer this over `config('database.default') === 'mysql'`, which excludes
|
||||
* MariaDB.
|
||||
*/
|
||||
public static function isMysqlMaria(?string $connection = null): bool
|
||||
{
|
||||
return in_array(self::name($connection), self::MYSQL_LIKE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the driver is PostgreSQL.
|
||||
*/
|
||||
public static function isPgsql(?string $connection = null): bool
|
||||
{
|
||||
return self::name($connection) === 'pgsql';
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue