From 5d5ce25d374a89e496aea0ef75be172269a043e2 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Thu, 21 Jul 2022 00:07:42 +0200 Subject: [PATCH] schema: Move postgres special about TEXT/BYTEA to MWPlatform override Global replaces on strings without boundaries or other checks could be problematic, when the word is used as column name or table name. This is not the case for mediawiki, because these names are provided in lower case, but doing the override instead is clearer way to get this. This also allows to define some special to get back the bytea if binary support is needed in postgres. Change-Id: I0a674408580d4e15222dc2556d597c2b523ce2b9 --- .../libs/rdbms/dbal/MWPostgreSqlPlatform.php | 20 +++++++++++++++++++ maintenance/generateSchemaChangeSql.php | 5 ----- maintenance/generateSchemaSql.php | 5 ----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/includes/libs/rdbms/dbal/MWPostgreSqlPlatform.php b/includes/libs/rdbms/dbal/MWPostgreSqlPlatform.php index aa4f5edc550..c3ec2554a75 100644 --- a/includes/libs/rdbms/dbal/MWPostgreSqlPlatform.php +++ b/includes/libs/rdbms/dbal/MWPostgreSqlPlatform.php @@ -59,6 +59,26 @@ class MWPostgreSqlPlatform extends MWPostgreSqlPlatformCompat { return $tableSql; } + /** + * @inheritDoc + */ + public function getBlobTypeDeclarationSQL( array $column ) { + // MySQL goes with varbinary for collation reasons, but postgres can't + // properly understand BYTEA type and works just fine with TEXT type + // FIXME: This should be fixed at some point (T257755) + return 'TEXT'; + } + + /** + * @inheritDoc + */ + public function getBinaryTypeDeclarationSQL( array $column ) { + // MySQL goes with varbinary for collation reasons, but postgres can't + // properly understand BYTEA type and works just fine with TEXT type + // FIXME: This should be fixed at some point (T257755) + return 'TEXT'; + } + /** * @inheritDoc */ diff --git a/maintenance/generateSchemaChangeSql.php b/maintenance/generateSchemaChangeSql.php index 20aa4177ded..6f72143af4d 100644 --- a/maintenance/generateSchemaChangeSql.php +++ b/maintenance/generateSchemaChangeSql.php @@ -60,11 +60,6 @@ class GenerateSchemaChangeSql extends SchemaMaintenance { // Remove table prefixes from Postgres schema, people should not set it // but better safe than sorry. $sql = str_replace( "\n/*_*/\n", ' ', $sql ); - - // MySQL goes with varbinary for collation reasons, but postgres can't - // properly understand BYTEA type and works just fine with TEXT type - // FIXME: This should be fixed at some point (T257755) - $sql = str_replace( "BYTEA", 'TEXT', $sql ); } // Until the linting issue is resolved diff --git a/maintenance/generateSchemaSql.php b/maintenance/generateSchemaSql.php index cadbbfae9fc..594ccba0b9c 100644 --- a/maintenance/generateSchemaSql.php +++ b/maintenance/generateSchemaSql.php @@ -65,11 +65,6 @@ class GenerateSchemaSql extends SchemaMaintenance { [ "WHERE", ' ', " ", ');', "KEY(\n " ], $sql ); - - // MySQL goes with varbinary for collation reasons, but postgres can't - // properly understand BYTEA type and works just fine with TEXT type - // FIXME: This should be fixed at some point (T257755) - $sql = str_replace( "BYTEA", 'TEXT', $sql ); } // Until the linting issue is resolved