Page MenuHomePhabricator

Feature Request to allow periods in database names for PostgreSQL
Closed, DeclinedPublic

Description

https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Relevant portions of documentation :

"SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_)."
It goes on to mention which characters can follow the initial letter, but it is important to distinguish this pertains only to unquoted identifiers.
"...The system uses no more than NAMEDATALEN-1 bytes of an identifier...By default, NAMEDATALEN is 64"
Further down, it reads "Quoted identifiers can contain any character, except the character with code zero."

I've changed regex in line 102 of mediawiki-1.30.0/includes/installer/PostgresInstaller.php to read
} elseif ( !preg_match( '/^[a-zA-Z0-9_\-\.]+$/', $newValues['wgDBname'] ) ) {
original - } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {

The modified regex code above just adds the ability to use a hypen or period. A more accurate regex check might be along the lines of /^[a-z_][a-z0-9_\-\.]{0,62}$/i to compensate for the first character having to be alpha or underscore, and a limit of 63 including the first character.

The above assumes that the underlying library and code that relies on the value encloses it in quotes when passing to the database functions.
My installation is on Ubuntu 16.04.3 LTS running PHP 7.0.25 connecting to PostrgeSQL version 9.5.11 database name = "mediawiki-1.30.0". In my (very admittedly isolated) case, everything works properly, so I assume code is handling passing values properly ( with quotes ).

The config-invalid-db-name string would need to be updated to provide a more accurate description of valid characters following the addition of allowing a period, but as the current description is not represented correctly in the code ( error reads that it allows hyphens, but regex does not allow hypens ).
My proposed English description for config-invalid-db-name would be "Invalid database name \"$1\".\nName must begin with ASCII letter (a-z,A-Z) or underscore (_), must be no longer than 63 characters, and must contain only letters (a-z, A-Z), numbers (0-9), periods (.), underscores (_), or hyphens (-).",

This step gets us a little closer to what PostgreSQL actually allows for database names.

Event Timeline

tstarling subscribed.

I don't think this is feasible. MediaWiki has an internal concept of a qualified table name with dot-separated components. SQLPlatform::qualifiedTableComponents() is complicated enough as it is without adding such special cases.