swap hardcoded public values for DB_SCHEMA constant

This commit is contained in:
Matthew Bucci
2024-10-18 23:07:05 -07:00
parent 129aa7f171
commit 36726124a4
7 changed files with 33 additions and 9 deletions
+5
View File
@@ -49,6 +49,11 @@ if(!defined('PG4WP_ROOT')) {
mkdir(PG4WP_LOG);
}
// Default to public schema
if (!defined('DB_SCHEMA')) {
define('DB_SCHEMA', 'public');
}
// Here happens all the magic
require_once(PG4WP_ROOT . '/core.php');
} // Protection against multiple loading
+2 -2
View File
@@ -6,7 +6,7 @@ class DescribeSQLRewriter extends AbstractSQLRewriter
{
$sql = $this->original();
$table = $this->extractTableName($sql);
return $this->generatePostgresDescribeTable($table);
return $this->generatePostgresDescribeTable($table, DB_SCHEMA);
}
/**
@@ -31,7 +31,7 @@ class DescribeSQLRewriter extends AbstractSQLRewriter
* @param string $schema The schema name
* @return string The generated SQL query
*/
public function generatePostgresDescribeTable($tableName, $schema = "public")
public function generatePostgresDescribeTable($tableName, $schema)
{
$sql = <<<SQL
SELECT
+2 -2
View File
@@ -37,7 +37,7 @@ class SelectSQLRewriter extends AbstractSQLRewriter
if(false !== strpos($sql, 'information_schema')) {
// WP Site Health rewrites
if (false !== strpos($sql, "SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length)")) {
$sql = $this->postgresTableSizeRewrite();
$sql = $this->postgresTableSizeRewrite(DB_SCHEMA);
return $sql;
}
@@ -373,7 +373,7 @@ class SelectSQLRewriter extends AbstractSQLRewriter
}
// This method is specifically to handle should_suggest_persistent_object_cache in wp site health
protected function postgresTableSizeRewrite($schema = 'public')
protected function postgresTableSizeRewrite($schema)
{
$sql = <<<SQL
@@ -6,7 +6,7 @@ class ShowFullColumnsSQLRewriter extends AbstractSQLRewriter
{
$sql = $this->original();
$table = $this->extractTableNameFromShowColumns($sql);
return $this->generatePostgresShowColumns($table);
return $this->generatePostgresShowColumns($table, DB_SCHEMA);
}
/**
@@ -31,7 +31,7 @@ class ShowFullColumnsSQLRewriter extends AbstractSQLRewriter
* @param string $schema The schema name
* @return string The generated SQL query
*/
public function generatePostgresShowColumns($tableName, $schema = "public")
public function generatePostgresShowColumns($tableName, $schema)
{
$sql = <<<SQL
SELECT
@@ -5,7 +5,7 @@ class ShowTableStatusSQLRewriter extends AbstractSQLRewriter
public function rewrite(): string
{
$sql = $this->original();
return $this->generatePostgresShowTableStatus();
return $this->generatePostgresShowTableStatus(DB_SCHEMA);
}
@@ -14,7 +14,7 @@ class ShowTableStatusSQLRewriter extends AbstractSQLRewriter
*
* @return string The generated SQL query
*/
public function generatePostgresShowTableStatus($schema = "public")
public function generatePostgresShowTableStatus($schema)
{
$sql = <<<SQL
SELECT
+1 -1
View File
@@ -4,7 +4,7 @@ class ShowTablesSQLRewriter extends AbstractSQLRewriter
{
public function rewrite(): string
{
$schema = "public";
$schema = DB_SCHEMA;
return 'SELECT tablename FROM pg_tables WHERE schemaname = \'$schema\';';
}
}